0

Im doing a VAR forecast, and then trying to forecast with a rolling window, however it doesn't seem to work for me. I have done a loop for my ARIMA model, which works (it does give me a warning: i window.default(x, ...) : 'end' value not changed <- which im not sure what means)

this is my code for the rolling window for arima

h <- 1 # h-step ahead
train <- window(Y, start=2002, end=c(2017,12),frequency = 12) #in-sample
test <- window(Y, start=2018, end=c(2021,12),frequency = 12) #out-of-sample
n <- length(test) - h+1
fit <- arima(Y, order=c(1,1,1), seasonal = list(order = c(1, 0, 1), period = 12))
fc <- ts(numeric(n), start=2018+(h-1)/12, freq=12)



for(i in 1:n)

x <- window(Y, end=c(2017,12) + (i-1)/12)
refit <- Arima(x, model=fit) # apply the estimated model to the extended data
fc[i] <- forecast(refit, h=h)$mean[h]

however when forecasting with VAR I have to use predict, and this doesn't seem to work for me with the rolling window, do any of you have any suggestions?

my training-set contains 192 values, and my test set 48

0 Answers0