時序
在 R 中回測 GARCH 時出現錯誤消息
我正在嘗試使用R 中
ugarchroll
的rugarch
包來回測我的 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 的第一個元素
rets
(NA
這是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