More Exploration of Crazy RUT

[This article was first published on Timely Portfolio, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Unintentionally while playing with the lawstat package in R, I started trying to build systems (STANDARD DISCLAIMER: NOT INVESTMENT ADVICE AND WILL LOSE LOTS OF MONEY SO PROCEED WITH CAUTION) based on the Jarque Bera test of normality (entry in Wikipedia or the research paper http://scholar.google.com/scholar?cluster=18293285759900281575&hl=en&as_sdt=0,1).  Since I was only playing around, I sort of deliberately curve fitted a system to work on the Russell 2000.  After a lot of experimentation, I came up with something very interesting, which led me to test on multiple other indexes.  It seemed to only really work well on the Russell 2000 and mainly over the last 5 years, which of course led me right back to the question posed in Crazy RUT and explored again in Crazy RUT in Academic Context Why Trend is Not Your Friend, which is “Why don’t most momentum systems work over the last decade on the Russell 2000 when they work on almost all other indexes?”  Please let me know if you have a good explanation, or if you want to test for regimes. Here is the result. I apologize that I spent little time on making these pretty.

From TimelyPortfolio

Even more strange is that the system applied to Kenneth French’s small classification shows different results.

From TimelyPortfolio

Here is how the system looks on the S&P 500, and again certainly nothing special.

From TimelyPortfolio

R code from GIST (do raw for copy/paste):

require(lawstat)
require(quantmod)
require(PerformanceAnalytics)
#set up function to use to obtain rolling p-value from bera jarque normality test
rjb.p <- function(x) {
rjb.test(x,option="RJB")$p.value
# rjb.test(x,option="RJB")$statistic
}
#set up function to do same routine on Russell 2000 and French small
#to test for robustness of result
testmultiple <- function(x,data.source="") {
if (data.source=="") data.source=colnames(x)[1]
x.roc <- ROC(to.weekly(x)[,4],type="discrete",n=1)
x.roc[1,]<-0
signal.rjb <- apply.rolling(x.roc,FUN=rjb.p,width=25)
roc.long <- ROC(to.weekly(x)[,4],type="discrete",n=8)
#plot.zoo(signal.rjb*roc.long)#,ylim=c(0,20))
perf <- merge(lag(ifelse((signal.rjb>0.05 & roc.long > 0.015) | (signal.rjb < 0.75 & signal.rjb > 0.4) ,1,0)) * x.roc,x.roc)
colnames(perf) <- c("system","buyhold")
charts.PerformanceSummary(perf,ylog=TRUE,main=paste("Performance of Systems",data.source,sep=" "))
return("done")
}
#do this to get from Yahoo! Finance but history only goes back to 1987
#getSymbols("^RUT",from="1900-01-01")
#I have local file from Bloomberg that goes back to 1980
RUT <- read.csv("rut.csv",stringsAsFactors=FALSE)
RUT <- as.xts(RUT[,2],order.by=as.Date(RUT[,1]))
testmultiple(RUT,data.source="Russell 2000 Index")
#do again but this time using French data
my.url="http://mba.tuck.dartmouth.edu/pages/faculty/ken.french/ftp/6_Portfolios_ME_Prior_12_2_Daily.zip"
my.tempfile<-paste(tempdir(),"\\frenchmomentum.zip",sep="")
my.usefile<-paste(tempdir(),"\\6_Portfolios_ME_Prior_12_2_Daily.txt",sep="")
download.file(my.url, my.tempfile, method="auto",
quiet = FALSE, mode = "wb",cacheOK = TRUE)
unzip(my.tempfile,exdir=tempdir(),junkpath=TRUE)
#read space delimited text file extracted from zip
french_momentum <- read.table(file=my.usefile,
header = TRUE, sep = "",
as.is = TRUE,
skip = 12, nrows=12316)
colnames(french_momentum) <- c(paste("Small",
colnames(french_momentum)[1:3],sep="."),
paste("Large",colnames(french_momentum)[1:3],sep="."))
#get dates ready for xts index
datestoformat <- rownames(french_momentum)
datestoformat <- paste(substr(datestoformat,1,4),
substr(datestoformat,5,6),substr(datestoformat,7,8),sep="-")
#get xts for analysis
french_momentum_xts <- as.xts(french_momentum[,1:6],
order.by=as.Date(datestoformat))
french_momentum_xts <- french_momentum_xts/100
#get average of small to test all
french_momentum_small <- as.xts(apply(french_momentum_xts[,1:3],MARGIN=1,FUN=mean),
order.by=index(french_momentum_xts))
french_momentum_price <- as.xts(apply(french_momentum_small+1,MARGIN=2,FUN=cumprod),
order.by=index(french_momentum_xts))
#to get cumulative return(price) for each by size x momentum
#french_momentum_price <- as.xts(apply(french_momentum_xts+1,MARGIN=2,FUN=cumprod),
# order.by=index(french_momentum_xts))
#to test each by momentum
#apply(french_momentum_price[,1:3],MARGIN=2,FUN=testmultiple)
testmultiple(french_momentum_price,data.source="French Small")
#now let's do on the S&P 500
getSymbols("^GSPC",from="1900-01-01")
testmultiple(GSPC,data.source="S&P 500")

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

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)