I have analysed my GDP time series in order to make a forcast. I found that the most appropriate models would be:
- GARCH(1,1) with ARMA (1,1) :
garch1b<garchFit(~arma(1,1)+garch(1,1),data=dlogGDP,cond.dist="QMLE") - GARCH(1,1) with ARMA (1,0):
garch6b<garchFit(~arma(1,0)+garch(1,1),data=dlogGDP,cond.dist="QMLE")
GDP time schema

Both models are valid. I would like to perform an out-of-sample forecasting performance comparison. I used this code:
# 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)
However, I do not get any results. The error1.h and error2.h are NaN.
QUESTION:
- What is wrong with my code?
- Is there another way how to do a out-of-sample forcasting performance using the
fGARCHpackage?
I believe it's just one line that is missing and careful specification of the predict output: