Exercise

Plotting financial data

Trading strategies developed using quantstrat contain several characteristics, including indicators developed from market data, signals triggered by certain combinations of indicators, and rules acted on by certain signals. The first step in developing any trading system is to obtain market data, and maybe even examine how it looks.

As you saw in the video, the quantmod package has a function to obtain data from various sources. This is the getSymbols() command, which returns an object with the same name as the symbol.

In this exercise, you will obtain data for SPY, an exchange traded fund (ETF) that tracks the top 500 companies in the United States by market cap. This data is from Yahoo! Finance, which is a sufficient source of data for strategies that do not require instantaneous "see the close, buy the close" execution. You will then plot it and add a trendline to it.

For example, to obtain adjusted data for SPY in 2013 from Yahoo! Finance and then plot the maximum values traded each day, you would run the following code. Notice how only the first reference to the SPY data is enclosed in quotation marks.