MulaiMulai sekarang secara gratis

Understanding initialization settings - II

Like in the previous chapter, you will use getSymbols() to obtain the SPY data from Yahoo! Finance.

After importing the data, use stock() to tell quantstrat what instruments will be present for the simulation, and to treat them just as they are, as opposed to creating a minimum buy size, as with futures. Furthermore, this command specifies which currency to use with the given instruments. Note that whenever you use a function to initialize a dataset such as GDX or SPY, you must enclose it in quotation marks:

stock("GDX", currency = "USD")

The quantstrat package has been loaded into your workspace, as well as the from and to date strings that you created in the previous exercise.

Latihan ini adalah bagian dari kursus

Financial Trading in R

Lihat Kursus

Petunjuk latihan

  • Use the library() command to load the quantmod package.
  • Use getSymbols() to get adjusted data from SPY from Yahoo! Finance between the from and to dates.
  • Use the stock() command to let quantstrat know you will be using the SPY data in your strategy and set its currency to "USD".

Latihan interaktif praktis

Cobalah latihan ini dengan menyelesaikan kode contoh berikut.

# Load the quantmod package
___

# Retrieve SPY from yahoo
getSymbols(___)

# Use stock() to initialize SPY and set currency to USD
stock(___)
Edit dan Jalankan Kode