Time series cross-validation 4: forecasting the S&P 500
[This article was first published on Modern Toolmaking, 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.
I finally got around to publishing my time series cross-validation package to github, and I plan to push it out to CRAN shortly.Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
You can clone the repo using github for mac, for windows, or linux, and then run the following script to check it out:
This script downloads monthly data for S&P 500 (adjusted for splits and dividends), and, for each month form 1995 to the present, fits a naive model, an auto.arima() model, and an ets() model to the past 5 year’s worth of data and uses those models to predict S&P 500 prices for the next 12 months (note that the progress bar doesn’t update if you register a parallel backend. I can’t figure out how to fix this bug):
This script downloads monthly data for S&P 500 (adjusted for splits and dividends), and, for each month form 1995 to the present, fits a naive model, an auto.arima() model, and an ets() model to the past 5 year’s worth of data and uses those models to predict S&P 500 prices for the next 12 months (note that the progress bar doesn’t update if you register a parallel backend. I can’t figure out how to fix this bug):
The naive model outperforms the arima and exponential smoothing models, both of which take into account seasonal patterns, trends, and mean-reversion! Furthermore, we’re not just using any arima/exponential smoothing model: at each step we’re selecting the best model, based on the last 5 years worth of data. (The ets model slightly outperforms the naive model at the 3 month horizon, but not the 2 month or 4 month horizons).
Forecasting equities prices is hard!
To leave a comment for the author, please follow the link and comment on their blog: Modern Toolmaking.
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.