Automatic ARMA/GARCH selection in parallel

by ivannp on March 24, 2013

In the original ARMA/GARCH post I outlined the implementation of the garchSearch function. There have been a few requests for the code so … here it is. Quite easy to use too:

library(quantmod)
source("garchAuto.R")

spy = getSymbols("SPY", auto.assign=FALSE)
rets = ROC(Cl(spy), na.pad=FALSE)
fit = garchAuto(rets, cores=8, trace=TRUE)

After the last code line above, fit contains the best (according to the AIC statistic) model, which is the return value of garchFit. The function has reasonable defaults, but also provides controls over various aspects of the model selection – check the code.

The function is called garchAuto, following the naming convention of the fGarch package. In fact, I am trying to get it into the fGarch package, but haven’t heard back yet. There are reasons why I don’t feel too optimistic about this happening, hence, my decision to publish it here.

Last, if you wonder why I abandoned the original garchSearch name, the reason is that a similar function from the forecast package is called auto.arima (“auto”, not “search”).

{ 4 comments… read them below or add one }

Alex April 3, 2013 at 07:48

Hello, thanks for your code. I have actually already coded ArmaGarchSearch() myself but without distribution choice and without parallel (did not know before – thanks for that). My concern is and it was about the length of the estimation data set. I ve tried from 300 to 1500 and then use this for 1 step forecast. But it does not give same forecasts! Right now I calculate ( without parallel – crazy) indicator for windows 300 and then try to compare performance with respect to length of the windows.
And another question, my forecast values are of order 10^(-4) ( I guess you have the same) while sd~10^(-3). From statistical point of view there is no use of such prediction. What do you use as a signal for long or short? forecast greater or smaller than zero correspondently?
And I read some papers, such models’ first use is indeed the simulation and pricing derivatives.
Thanks in advance,
Alex

Reply

ivannp April 8, 2013 at 17:42

At the end, it’s up to you to decide whether this method is worth using or not, so if you think it’s statistically insignificant – I have no issues. The mean return on GSPC since 1950 is 0.0002849584, in other words, right off the bat we are talking very small numbers. Would it be better if we used percentages instead, i.e. multiplying everything by 100? I don’t think so. You are touching here on a very important issue – how to determine whether a system is useful or not. I have been pondering this for a while, so there might be some posts coming on the topic.

Reply

DanSan566 May 21, 2013 at 19:40

Hi! Thanks for your great code! I’m trying to fit 28 Stocks with an ARMA+GARCH Model from the Dow Jones. It works perfectly for 25. For three stocks I get as result NULL. I’ve tried to fix and failed… I would like to use your code in my bachelor thesis if its okay for you (I will mention your blog and so forth) Here is my code and maybe you have an idea whats going wrong:
library(quantmod, quietly = TRUE)
library(PerformanceAnalytics, quietly = TRUE)
library(fGarch)

symbols_dj <- c("MRK" ,"HD", "PG")
getSymbols(symbols_dj, from = "2000-01-01", to = "2006-12-31")
data <- xts()
for(i in seq_along(symbols_dj)) {
symbol_dj <- symbols_dj[i]
data <- merge(data, Ad(get(symbol_dj)))
}
returns <- Return.calculate(data, method = "log")
returns[1,] <- 0

garch_models <- sapply(returns, garchAuto, cores=8, trace=TRUE)

Reply

ankc November 28, 2013 at 06:54

Hi,
I’m trying to understand how to use the code, do you just load up quantmod and use the code?
I’m having trouble understanding what source(“garchAuto.R”) does.

Can you clear that up for me?

Thanks

Reply

Leave a Comment