I am trying to evaluate the out-of-sample forecasting performance of different OLS models. The easiest time-series regression looks like this: Y_t = b0 + b1 * Y_t-30 + e_t
The fitting period for the model is, let's say 50, then I let the model run using the dynlm package
dynlm(as.zoo(Y) ~ L(as.zoo(Y), 30), start = "1996-01-01", end = timelist[i])
In my current code I just let the index i run until the end and then I save the RMSE of the corresponding model. But this RMSE is not the out-of-sample one step ahead forecast and since my current code is already pretty slow and it doesn't even do exactly what I want it to do, I wanted to ask you if you have a suggestion which package I should use to achieve my goal.
To sum it up, I want to do the following:
1) run a recursive regression after a certain fitting period (expanding window, NOT rolling window)
2) create one-step ahead out-of-sample forecasts
3) calculate the root mean squared error of these forecasts vs. actual observations to evaluate the model performance
I tried doing this so far with a huge for-loop and the dynlm package, but the results are not really satisfying. Any input is greatly appreciated, since I have been looking for solutions for quite a while now. I will update my example code as soon as I made some progress.
# minimal working example
require(xts)
require(zoo)
require(dynlm)
timelist <- seq.Date(from = as.Date("1996-01-01"), to = as.Date("1998-01-01"), by = "days")
set.seed(123)
Y <- xts(rnorm(n = length(timelist)), order.by = timelist)
X <- xts(rnorm(n = length(timelist), mean = 10), order.by = timelist)
# rmse container
rmse.container.full <- data.frame(matrix(NA, ncol = 3, nrow = length(index(timelist))))
colnames(rmse.container.full) <- c("Date", "i", "rmse.m1")
rmse.container.full$Date <- timelist
# fitting period
for(i in 50:length(timelist)) {
# m1
model1 <- dynlm(as.zoo(Y) ~ L(as.zoo(X), 30), start = "1996-01-01", end = timelist[i])
rmse.container.full[i, 2] <- i
rmse.container.full[i, 3] <- summary(model1)$sigma # RSME mod1 etc
print(i)
}