Testing Hurst with Multiple Indexes

June 20, 2011
By

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

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)

Created by Pretty R at inside-R.org

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



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.

Sponsors

Mango solutions



plotly webpage

dominolab webpage



Zero Inflated Models and Generalized Linear Mixed Models with R

Quantide: statistical consulting and training

datasociety

http://www.eoda.de





ODSC

ODSC

CRC R books series





Six Sigma Online Training









Contact us if you wish to help support R-bloggers, and place your banner here.

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)