user1607
user1607

Reputation: 551

Out of sample forcasting performance - fGARCH in R

I have analysed my GDP time series in order to make a forcast. I found that the most appropriate models would be:

GDP time schema

img

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:

  1. What is wrong with my code?
  2. Is there another way how to do a out-of-sample forcasting performance using the fGARCH package?

Upvotes: 1

Views: 478

Answers (1)

Alisa
Alisa

Reputation: 1

I believe it's just one line that is missing and careful specification of the predict output:

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)
}

Upvotes: 0

Related Questions