Bruno Hanzen
Dec. 11th, 2016
The “getSymbol” function creates an XTS object named as the loaded symbol
library(quantmod)
tick<-"AAPL"
name<-getSymbols(tick,src="yahoo")
name
[1] "AAPL"
symbol<-get(name)
head(symbol)
AAPL.Open AAPL.High AAPL.Low AAPL.Close AAPL.Volume
2007-01-03 86.29 86.58 81.90 83.80 309579900
2007-01-04 84.05 85.95 83.82 85.66 211815100
2007-01-05 85.77 86.20 84.40 85.05 208685400
2007-01-08 85.96 86.53 85.28 85.47 199276700
2007-01-09 86.45 92.98 85.15 92.57 837324600
2007-01-10 94.75 97.80 93.45 97.00 738220000
AAPL.Adjusted
2007-01-03 10.90416
2007-01-04 11.14619
2007-01-05 11.06681
2007-01-08 11.12147
2007-01-09 12.04533
2007-01-10 12.62176
In order to avoid unnecessary call to YAHOO, the “getSymbol” call is placed within a “reactive” statement. The data are not reloaded from YAHOO when the user selects another indicator for the same stock.
Quantmod comes with a rich set of built-in indicators and graph. For example, we first plot a standard chart, then add Bollinger Bands.
chartSeries(symbol, name=tick, theme=chartTheme('white'), TA = "addBBands()")