rtime-seriesforecastingmulti-step

Multi-Step Ahead Time Series Forecasting (Using Direct Approach)


I was wondering what's wrong with my loop forecasting multi-step time series.

I first have this loop to mimic the information set at time τ and estimate the models based on a rolling window of 1000 observation and make a one-step-ahead out-of-sample forecast with 726 out-of-sample observations.

require(highfrequency)
require(quantmod)
require(xts)

getSymbols("^VIX")

VIX_fcst <- VIX[, "VIX.Close"]
VIX_fcst$pred <- NA

for (i in 2000:2726) {
  HAREstimated <- HARmodel(data = VIX_fcst[i: (i+ 999), "VIX.Close"], periods = c(1, 5 , 22), type = "HAR", inputType = "RM")
  VIX_fcst$pred[i + 1000] <- predict(HAREstimated)
}

Basically, I make a regression on 1000 observations and store the prediction t+1 in a separate column and it works greatly.

Now I would like to take it further with a 5 ahead multi-step forecast by integrating an inner loop to find the t+5 prediction using prediction value instead of price for t+1, t+2...t+5. Here's a example for the first T+5 prediction of the 726 obs :

for (i in 2000:2004) {
  HAREstimated2 <- HARmodel(data = VIX_fcst[i: (i+ 999), "VIX.Close"], periods = c(1, 5 , 22), type = "HAR", inputType = "RM")
  VIX_fcst$VIX.Close[i + 1000] <- predict(HAREstimated2)
}

I thought storing the value in the VIX.Close column did the trick but the loop doesn't seem to consider the predictions which brings me back to one step ahead loop results.

Any ideas?


Solution

  • I finally found the solution by myself, here it is for those who will encounter this problem :

    for (i in 2000:2722) {
    
      for (j in i:(i+4)) {
        if (j < (i+4)) {
          HAREstimated <- HARmodel(data = VIX_fcst[j: (j + 999), "VIX.Close"], periods = c(1, 5 , 22), type = "HAR", inputType = "RM")
          VIX_fcst$VIX.Close[j + 1000] <- predict(HAREstimated)
        }
        else {
          HAREstimated <- HARmodel(data = VIX_fcst[j: (j + 999), "VIX.Close"], periods = c(1, 5 , 22), type = "HAR", inputType = "RM")
          VIX_fcst$pred[j + 1000] <- predict(HAREstimated3)
          VIX_fcst <- VIX[, "VIX.Close"]
        }
      }
    }
    

    Note that you need to remove 4 observations in the sample you want to forecast.