## The following is a small illustrative example using the quotes of the
## SP500 index. This example estimates the performance of a random
## forest on a illustrative example of trying to forecast the future
## variations of the adijusted close prices of the SP500 using a few
## predictors. The random forest is evaluated on 4 repetitions of a
## monte carlo experiment where 30% of the data is used for training
## the model that is then used to make predictions for the next 20%,
## using a sliding window approach with a relearn step of 10 periods
## (check the help page of the timeseriesWF() function to understand
## these and other settings)
## Not run:
# library(quantmod)
# library(randomForest)
#
# getSymbols('^GSPC',from='2008-01-01',to='2012-12-31')
# data.model <- specifyModel(Next(100*Delt(Ad(GSPC))) ~ Delt(Ad(GSPC),k=1:10)+Delt(Vo(GSPC),k=1:3))
# data <- as.data.frame(modelData(data.model))
# colnames(data)[1] <- 'PercVarClose'
#
# spExp <- mcEstimates(Workflow("timeseriesWF",wfID="rfTrial",
# type="slide",relearn.step=10,
# learner='randomForest'),
# PredTask(PercVarClose ~ .,data,"sp500"),
# EstimationTask(metrics=c("mse","theil"),
# method=MonteCarlo(nReps=4,szTrain=.3,szTest=.2)))
#
# summary(spExp)
# ## End(Not run)
Run the code above in your browser using DataLab