# Crazy RUT

July 24, 2011
By

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

I have noticed that the Russell 2000 (RUT) acts very differently from most of the other indexes that I have studied.  If we apply the system shown in Shorting Mebane Faber to RUT and then extend it with a simple slope, we notice something very different about RUT behavior.  No clear dominant strategy really emerges.

 From TimelyPortfolio
 From TimelyPortfolio

require(quantmod)
require(PerformanceAnalytics)   getSymbols("^RUT",from="1919-01-01",to=Sys.Date())   RUT <- to.monthly(RUT)[,4]
index(RUT) <- as.Date(index(RUT))   #get 10 month rolling average
avg10 <- runMean(RUT,n=10)   #know I can do this better in R but here is my ugly code
#to calculate 6 month slope of 10 month average
width=6
for (i in 1:(NROW(avg10)-width)) {
#get sp500/crb slope
model <- lm(RUT[i:(i+width),1]~index(RUT[i:(i+width)]))
ifelse(i==1,avg10slope <- model\$coefficients[2],
avg10slope <- rbind(avg10slope,model\$coefficients[2]))
}
#get xts so we can use
avg10slope <- xts(cbind(avg10slope),order.by=index(avg10)[(width+1):NROW(avg10)])   priceSignals <- na.omit(merge(RUT,avg10,avg10slope))   signalUpUp <- ifelse(priceSignals[,1] > priceSignals[,2] & priceSignals[,3] > 0, 1, 0)
signalUpDown <- ifelse(priceSignals[,1] > priceSignals[,2] & priceSignals[,3] < 0, 1, 0)
signalDownUp <- ifelse(priceSignals[,1] < priceSignals[,2] & priceSignals[,3] > 0, 1, 0)
signalDownDown <- ifelse(priceSignals[,1] < priceSignals[,2] & priceSignals[,3] < 0, 1, 0)   retUpUp <- lag(signalUpUp,k=1)* ROC(RUT,type="discrete",n=1)
retUpDown <- lag(signalUpDown,k=1)* ROC(RUT,type="discrete",n=1)
retDownUp <- lag(signalDownUp, k=1) * ROC(RUT,type="discrete",n=1)
retDownDown <- lag(signalDownDown, k=1) * ROC(RUT,type="discrete",n=1)   ret <- merge(retUpUp,retUpDown,retDownUp,retDownDown,ROC(RUT,type="discrete",n=1))
colnames(ret) <- c("UpUp","UpDown","DownUp","DownDown","RUT")   jpeg(filename="performance summary.jpg",quality=100,
width=6.25, height = 6.25, units="in",res=96)
charts.PerformanceSummary(ret,ylog=TRUE,
main="RUT 10 Month Moving Average Strategy Comparisons
May 1987-Jun 2011"
)
dev.off()   jpeg(filename="rolling returns.jpg",quality=100,
width=6.25, height = 6.25, units="in",res=96)
chart.RollingPerformance(ret,width=36,
main="RUT 10 Month Moving Average Strategy Comparisons
36 Month Rolling Return May 1987-Jun 2011"
)
dev.off()

Created by Pretty R at inside-R.org

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

Tags: ,