When I find a chart that looks like this, I always like to explore a little further.
via StockCharts.com
I pull it into R and try to find anything worthwhile. I do not find anything, except that I do not want to be trading both in the same direction and expect any diversification. But we all know the whole world is correlated.
From TimelyPortfolio |
From TimelyPortfolio |
R code:
require(quantmod)
require(TTR)
require(PerformanceAnalytics)
tckr<-c("GLD","SLV","IWM")
start<-"2006-06-30"
end<- format(Sys.Date(),"%Y-%m-%d") # yyyy-mm-dd
# Pull tckr index data from Yahoo! Finance
getSymbols(tckr, from=start, to=end)
#adjust for splits and dividends
GLD<-adjustOHLC(GLD,use.Adjusted=T)
SLV<-adjustOHLC(SLV,use.Adjusted=T)
IWM<-adjustOHLC(IWM,use.Adjusted=T)
#get daily return from prices to use PerformanceAnalytics
GLD<-dailyReturn(GLD)
SLV<-dailyReturn(SLV)
IWM<-dailyReturn(IWM)
RetToAnalyze<-merge(GLD,SLV,IWM)
colnames(RetToAnalyze)<-tckr
charts.RollingRegression(last(RetToAnalyze,"3 years")[,c(1,2),drop=F],last(RetToAnalyze,"5 years")[,3],legend.loc="topleft",width=20,main="Rolling 20-day Regression")
chart.RollingPerformance(RetToAnalyze,width=150,legend.loc="topleft",main="Rolling 150-day Performance")
I see you fixed the problem with SLV trading at over $100 until 7/23/2008 by using the adjustOHLC(use.Adjusted=T) function. Very nice. I presume you used require(TTR) for clarity sake as you likely know that require(quantmod) will include TTR package.
ReplyDeleteYour posts are extremely helpful for R beginners like me. I am redoing every example you were doing here in the blog and explore all the different functions used in your code. Awesome work!
ReplyDelete