I’m encountering an issue when combining tsCV with nnetar (with h = 2 and additional input variables). The forecast errors for both horizons (h = 1 and h = 2) terminate two observations before the end of the sample.
In contrast, when using ARMA with tsCV, the horizon alignment behaves as expected:
For 1-step-ahead forecasts, errors end 1 observation before the final data point.
For 2-step-ahead forecasts, errors end 2 observations before the final data point.
This raises the question of whether the behavior I’m seeing with nnetar + tsCV is a known issue or a specification problem on my end.
Could you please advise on how to address this? Is shifting the nnetar forecast errors down by two steps a reasonable solution, or is there a more appropriate way to handle this alignment issue when using tsCV with nnetar?
Here is my code:
rfit <- function(x, h, xreg, newxreg) {
forecast(nnetar(x, xreg=xreg, p=1, size=5, repeats=5), xreg=newxreg, h=h)
}
xreg_data <- data.frame(cons)
error <- data.frame(
forecast::tsCV(price, fit, h=2, window = 365, initial =1, xreg=xreg_data)
)