Speed ​​forecasts one step further (instead of using rollapply)

i use rollapply to create 1 step forecasts for the GARCH (1,1) model ( garchFit ). An example is given 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 way to speed this up?

+1
source share
1 answer
  • In recent versions of rollapply (for example, zoo 1.7-6), an error occurred that did not lead to incorrect answers, but led to its launch much more slowly than necessary. Try the development version (to become a zoo 1.7-7) and see if this is enough for your needs:

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

  • You can also try to measure the percentage of time spent by your function (see ?Rprof ), and if its large, i.e. total.pct for FUN big, then its pointless to look for rollapply alternatives.

+4
source

Source: https://habr.com/ru/post/1386948/


All Articles