加快一步预测(而不是使用 rollapply) [英] speed up one step ahead predictions (instead of using rollapply)

查看:20
本文介绍了加快一步预测(而不是使用 rollapply)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 rollapply 来创建 GARCH(1,1) 模型 (garchFit) 的 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?

推荐答案

  1. rollapply 的最新版本(例如 zoo 1.7-6)中存在一个错误,该错误不会导致错误答案,但确实导致其运行速度比需要的要慢得多.尝试开发版本(成为 zoo 1.7-7),看看它是否足以满足您的需求:

  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")

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

您也可以尝试测量您的函数占用的时间百分比(参见 ?Rprof),如果它很大,即 total.pct 用于 FUN 很大,那么寻找 rollapply 替代方案毫无意义.

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.

这篇关于加快一步预测(而不是使用 rollapply)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆