我已经分析了我的GDP时间序列,以便进行预测。我发现最合适的模型是:
garch1b<garchFit(~arma(1,1)+garch(1,1),data=dlogGDP,cond.dist="QMLE")
garch6b<garchFit(~arma(1,0)+garch(1,1),data=dlogGDP,cond.dist="QMLE")
GDP时间架构
两种型号都有效。我想进行样本外预测性能比较。我用了这段代码:
# Out-of-sample forcasting performance
y<-dlogGDP
S=round(0.75*length(y))
h=1
error1.h<-c()
for (i in S:(length(y)-h))
{
mymodel.sub<-garchFit(y[1:i], formula = ~arma(1,1)+garch(1,1))
predict.h<-predict(mymodel.sub,n.ahead=h)$pred[h]
error1.h<-c(error1.h,y[i+h]-predict.h)
}
error2.h<-c()
for (i in S:(length(y)-h))
{
mymodel.sub<-garchFit(y[1:i], formula = ~arma(1,0)+garch(1,1))
predict.h<-predict(mymodel.sub,n.ahead=h)$pred[h]
error2.h<-c(error2.h,y[i+h]-predict.h)
}
cbind(error1.h,error2.h)
# Mean Absolute Error
MAE1<-mean(abs(error1.h))
MAE2<-mean(abs(error2.h))
# Mean Squared Forcast Error
MAE1<-mean(abs(error1.h^2))
MAE2<-mean(abs(error2.h^2))
# Forcasting Performance Comparison
library(forecast)
dm.test(error1.h,error2.h,h=h,power=1)
dm.test(error1.h,error2.h,h=h,power=2)
但是,我没有得到任何结果。 error1.h
和error2.h
为NaN
。
问题:
fGARCH
包进行样本外广播效果?答案 0 :(得分:0)
我相信只是缺少一行,并仔细指定了预测输出:
for (i in S:(length(y)-h))
{
mymodel.sub<-garchFit(y[1:i], formula = ~arma(1,0)+garch(1,1))
f <- fGarch::predict(mymodel.sub,n.ahead=h)
predict.h<-f$meanForecast
error1.h<-c(error1.h,y[i+h]-predict.h)
}