時序

在 R 中回測 GARCH 時出現錯誤消息

  • October 21, 2019

我正在嘗試使用R 中ugarchrollrugarch包來回測我的 ARCH 模型,但我收到了此警告消息

"Warning message: In .rollfdensity(spec = spec, data = data, n.ahead = n.ahead, forecast.length = forecast.length, :

non-converged estimation windows present...resubsmit object with different solver parameters."

這是我的程式碼

library(quantmod)
library(rugarch)

getSymbols("SPY")
rets=ROC(SPY$SPY.Close)
tgarch = ugarchspec(mean.model = list(armaOrder = c(1, 1)), 
                   variance.model = list(model = "sGARCH"),
                   distribution.model = "std")
garchroll<-ugarchroll(tgarch, data = rets,n.start =500, 
                     refit.window="window", refit.every =200)

出現錯誤是因為 is 的第一個元素retsNA這是ROC計算系列變化率的預期行為,但在第一個元素之前的先前值自然不可用)。


為避免這種情況,請添加可選參數na.pad = FALSE,即rets = ROC(SPY$SPY.Close, na.pad = FALSE)

> rets=ROC(SPY$SPY.Close)
> head(rets)
              SPY.Close
2007-01-03            NA
2007-01-04  0.0021198638
2007-01-05 -0.0080082993
2007-01-08  0.0046144192
2007-01-09 -0.0008502445
2007-01-10  0.0033260425
> rets = ROC(SPY$SPY.Close, na.pad = FALSE)
> head(rets)
              SPY.Close
2007-01-04  0.0021198638
2007-01-05 -0.0080082993
2007-01-08  0.0046144192
2007-01-09 -0.0008502445
2007-01-10  0.0033260425
2007-01-11  0.0043708988

引用自:https://quant.stackexchange.com/questions/49097