1

i use rollapplyin order to create 1-step ahead forecasts of a GARCH(1,1) model (garchFit). An example is provided below:

require(fGarch)
require(zoo)
data(EuStockMarkets)  
dax <- diff(log(EuStockMarkets))[,"DAX"]


gfit <- function(df)
   { 
  series <- df
    capture.output(gf <- garchFit(formula=~arma(0,0) + garch(1,1), data=series),     file='NUL')
    g <- predict(gf, n.ahead=1)[,2]
    attributes(g) <- NULL
return(g)
   }

 rolling <- rollapply(dax, width=250, FUN=gfit)

However, this takes a relatively long time. So my question is: Is there a method of speeding this up?

Seb
  • 5,417
  • 7
  • 31
  • 50
  • thanks a lot! it cut the whole thing by roughly a half. before: `user system elapsed 206.36 2.46 226.04`; after: `user system elapsed 122.30 0.31 123.04`. so this helps a lot. but probably there are further possibilities :) – Seb Dec 13 '11 at 20:37
  • now i have lot's of [output](https://docs.google.com/document/pub?id=19Fdy_iD-gfJYailOM_qGXOi3g5iXpCrQIqsYkzkqWpc) am i seeing this right that converting the whole thing into a `ts`object takes a huge fraction? is there a resource on interpreting the `Rprof` output. Thanks a **lot**! – Seb Dec 14 '11 at 07:58
  • Since it seems that we have converged on an answer I have deleted my comments and transferred them to an answer. – G. Grothendieck Dec 14 '11 at 15:06

1 Answers1

4
  1. There was a bug in recent versions of rollapply (such as zoo 1.7-6) that did not result in incorrect answers but did cause it to run much more slowly than need be. Try the development version (to become zoo 1.7-7) and see if that is sufficient for your needs:

    install.packages("zoo", repo = "http://r-forge.r-project.org")

  2. You can also try measuring the percentage of time taken up by your function (see ?Rprof) and if its large, i.e. total.pct for FUN is large, then its pointless to look for rollapply alternatives.

G. Grothendieck
  • 254,981
  • 17
  • 203
  • 341