I am using forecast::tsCV
function in R to perform a rolling origin forecast of 1 day to 1 year ahead horizons using daily frequency data.
Suppose my outcome variable is y, and I have x1, x2 and x3 as exogenous variables.
If I want to use the actual values of x1, x2 and x3 for training and testing sample to perform a seven day ahead out of sample forecast, then it would be as:
xreg <- data.frame(x1, x2, x3)
fit <- function(x, h, xreg, newxreg) {
forecast(Arima(x, order=c(1,0,1), xreg=xreg), xreg=newxreg)
}
e <- forecast::tsCV(y, fit, h=7, window=1000, xreg=xreg)
However, the problem is that I want to use the actual values of x1 and x2 for the training sample and their forecasted values for the rest of the period.
So I have forecasted values of x1 and x2, lets call them f_x1 and f_x2. If the first forecast point 1007, x1, x2 and x3 have to be used for 1 to 1000, then switch to f_x1 and f_x2 from 1001 to 1007, and this have to roll over as the windows roll.
I have tried this one:
xreg1=contains x1, x2 and x3
xreg2= contains f_x1, f_x2, x3
then:
e <tsCV(price, fit, h=7,
window =1000,
if (length(xreg) < 1001) {
xreg=xreg1
} else if (length(xreg) > 1000) {
xreg=xreg2
})
But the output shows that it doesn't convert using data from xtreg 1 to xtreg2.
Can someone help me how can I develop the forecast::tsCV
function to perform this?
Thanks for the answer, Its from PackageName::forecast
tsCV
? Please edit, for example by giving the function in the formPackageName::tsCV
. $\endgroup$