Silver and Russell 2000

February 16, 2011
By

(This article was first published on Timely Portfolio, and kindly contributed to R-bloggers)

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")

To leave a comment for the author, please follow the link and comment on his blog: Timely Portfolio.

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...



If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Tags:

Comments are closed.