Kyle Balkissoon
KKB Research and Development
2016-10-26
At the end of this presentation you will know how to the following
Before we can do anything we need data, some good R libraries for getting data are:
library(Quandl) # see Quandl.com for more info
library(quantmod) #Has preconfigured api with yahoo info
##Quandl - Note requires assignment, type xts is xtensible time series
SPTSXComp=Quandl("YAHOO/INDEX_GSPTSE",type='xts')
##quantmod - assigns to object named GSPTSE - automatically in xts/zoo
getSymbols("^GSPTSE")
symbol_list = c('XLF','XLE','XLU','XLK','XLB','XLP','XLY','XLI','XLV')
getSymbols(symbol_list, from = '1990-01-01')
getSymbols("SPY",from='1990-01-01')
library(PerformanceAnalytics)
securities_matrix = NULL
for( sym in symbol_list){
securities_matrix = merge.xts(securities_matrix,
Return.calculate(Ad(get(paste(sym))),
method='discrete'))}
securities_matrix=securities_matrix[complete.cases(securities_matrix)]
SPYReturn=Return.calculate(Ad(SPY),method='discrete')
chart.CumReturns(securities_matrix)