Site icon R-bloggers

Testing Hurst with Multiple Indexes

[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.

DO NOT TRADE THIS SYSTEM.  YOU VERY EASILY COULD LOSE LARGE AMOUNTS OF MONEY.

I am not necessarily recommending the system that I presented in Exploring the Market with Hurst, but I thought it would provide a nice platform to illustrate some backtesting with multiple indexes.  Do not pass on the incredible opportunity presented by almost unlimited indexes from Yahoo! Finance and the Fed.

From TimelyPortfolio
From TimelyPortfolio
From TimelyPortfolio
From TimelyPortfolio
From TimelyPortfolio
From TimelyPortfolio

R code (click to download):

require(quantmod)
require(PerformanceAnalytics)
require(FGN)   #sort of random mix for additional testing
indexes<-c("STI","KS11","GDAXI","DJUSAU","DJUSFI","RUT","DJUBS")
#iterate through index symbols
for (i in 1:length(indexes))  {
	#get symbol
	getSymbols(paste("^",indexes[i],sep=""),
		from="1900-01-01",to=format(Sys.Date(),"%Y-%m-%d"))
	#set monthly index to first day of the month
	assign(indexes[i],to.monthly(get(indexes[i]))[,4])
	#has to be a cleaner way than this to set the index
	assign(indexes[i],as.xts(coredata(get(indexes[i])),
		order.by=as.Date(index(get(indexes[i])))))
	#get monthly changes
	ret<-ROC(get(indexes[i]),n=1,type="discrete")
	index(ret) <- as.Date(index(ret))
	hurstKmonthly <- apply.rolling(ret, FUN="HurstK", width = 12)
	colnames(hurstKmonthly) <- "HurstK.monthly"
	index(hurstKmonthly) <- as.Date(index(hurstKmonthly))
	serialcorr <- runCor(cbind(coredata(ret)),cbind(index(ret)),n=12)
	serialcorr <- as.xts(serialcorr,order.by=index(ret))
	autoreg <- runCor(ret,lag(ret,k=1),n=12)
	colnames(serialcorr) <- "SerialCorrelation.monthly"
	colnames(autoreg) <- "AutoRegression.monthly"
	signalUpTrend <- runMean(hurstKmonthly+serialcorr+autoreg,n=6) +
		(get(indexes[i])/runMean(get(indexes[i]),n=12)-1)*10
	signalUpTrend < - lag(signalUpTrend,k=1)

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.