简体   繁体   English

预测ARMA GARCH模型时出错

[英]Error in Predict for ARMA GARCH model

I have data of an one year interest rate for a period over roughly five years. 我有大约五年的一年利率的数据。 I would like to create a model for this interest rate and I have come to the conclusion that an ARMA(3,2) with a GARCH(1,1) is appropriate. 我想为这个利率创建一个模型,我得出的结论是ARMA(3,2)与GARCH(1,1)是合适的。 I therefore use the following code below to get my estimates. 因此,我使用下面的代码来估算。

> stibor1ydarmagarch=garchFit(formula=~arma(3,2)+garch(1,1),
                          data=stibor1yd, 
                          cond.dist="std", 
                          trace=FALSE)

This works fine and I get nice estimates. 这很好,我得到了很好的估计。 However when it comes to predicting, I get an error. 但是,当涉及预测时,我收到一个错误。 Does someone have a clue why I get the error and how to solve it? 有人知道为什么我得到错误以及如何解决它?

> predict(stibor1ydarmagarch, n.ahead=10)
Error in a_vec[(i - 1):(i - u2)] : only 0's may be mixed with negative subscripts

This issue seems to be duplicate with an older post which does not contain answer: R error when using predict() function with class = fGarch 这个问题似乎与一个不包含答案的旧帖子重复: 当使用带有class = fGarch的predict()函数时出现R错误

The error stems from the case where either (i - 1) or (i - u2) becomes negative, so the index is something like -1:2 which is not allowed. 该错误源于(i - 1)(i - u2)变为负数的情况,因此索引类似于-1:2,这是不允许的。

After checking the predict method for the fitted object via getMethod("predict","fGARCH") , it looks like the error happens here (irrelevant parts omitted): 通过getMethod("predict","fGARCH")检查拟合对象的预测方法后,看起来这里发生了错误(省略了相关部分):

    a_vec <- rep(0, (n.ahead))      
    u2 <- length(ar)      
    a_vec[1] = ar[1] + ma[1]       
    if ((n.ahead - 1) > 1) {
        for (i in 2:(n.ahead - 1)) {
          a_vec[i] <- ar[1:min(u2, i - 1)] * a_vec[(i - 1):(i - u2)]             
        }
    }

So as i is always larger than 1, the error happens because 因为i总是大于1,所以错误发生是因为

(i - u2) < 0 <==> i < u2 <==> i < length(ar)

Does this make any sense? 这有意义吗? For me it doesn't, as it looks like if your model's ar part is larger than 2, this always produces an error. 对我来说它没有,因为看起来如果你的模型的ar部分大于2,这总是会产生错误。

The code is bit weird also because a_vec[i] is scalar and 代码a_vec[i]因为a_vec[i]是标量和

ar[1:min(u2, i - 1)] * a_vec[(i - 1):(i - u2)] + ... can be a vector which length is greater than 1. ar[1:min(u2, i - 1)] * a_vec[(i - 1):(i - u2)] + ...可以是长度大于1的向量。

EDIT: 编辑:

There is either a bug in the prediction function or there's undocumented restrictions which kind of models can be predicted, as even the example from the fGarch 's manual gives error if it is slightly modified: 预测函数中存在一个错误,或者存在未记录的限制,可以预测哪种模型,即使fGarch手册中的示例在稍微修改时也会出错:

   set.seed(123)
   fit = garchFit(~arma(2,0)+garch(1,1), data = garchSim(), trace = FALSE)
   predict(fit, n.ahead = 4)
   meanForecast   meanError standardDeviation
1 -7.512452e-04 0.004161189       0.004161189
2 -1.107497e-03 0.003958535       0.003878321
3  2.617933e-04 0.003782362       0.003665391
4  6.264252e-05 0.003616971       0.003507209
Warning message:
In a_vec[i] <- ar[1:min(u2, i - 1)] * a_vec[(i - 1):(i - u2)] +  :
  number of items to replace is not a multiple of replacement length

Based on the Changelog of fGarch package it seems that this issue was corrected several years ago, but apparently it has resurfaced, or was never properly fixed: 基于fGarch软件包Changelog,似乎几年前这个问题已得到纠正,但显然已经重新出现,或者从未正确修复过:

2009-11-05  chalabi

    * R/methods-predict.R: small changes in predict,fGARCH-method to
      correct its output when n.ahead=1 since addition of conditional
      errors.

I would suggest you to contact the maintainer of the package. 我建议你联系包的维护者。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM