predict_rolling: Rolling forecasts

predict_rollingR Documentation

Rolling forecasts

Description

Forecasts a VAR or VECM by discarding a part of the sample, and recursively generating a series of updated forecasts.

Usage

predict_rolling(object, ...)

## S3 method for class 'nlVar'
predict_rolling(object, nroll = 10, n.ahead = 1, refit.every, newdata, ...)

Arguments

object

A linear object of class ‘nlVar’; generated by lineVar or VECM.

...

Currently not used.

nroll

The number of rolling forecasts

n.ahead

An integer specifying the number of forecast steps.

refit.every

Determines every how many periods the model is re-estimated.

newdata

In case the given model is already estimated on the sub-sample, the out-of-sample data can be provided with this argument. Note it should contain observations to predict the first values, that are also contained in the in-sample.

Details

This function allows to check the out-of sample forecasting accuracy by estimating the model on a sub-sample of the original, then making nroll forecasts of horizon n.ahead, each time by updating the sample. In other words, with a given model estimated on 100 observations, the function will estimate it on say 90 first obs (nroll=10), generate a say 1 step-ahead (n.ahead=1) from obs 90, then using true value 91 for to predict value at 92, etc, till the full sample is used.

Unlike with usual predict() methods, specifiying n.ahead=2 will not generate a 1 step-ahead and a 2 step-ahead forecasts, but only nroll 2 step-ahead forecasts.

Note that while the forecasts are updated with new values, the model estimation is (by default) not updated. This can however be done with the argument fit.every, specifiying at which frequency the model should be re-estimated. By setting it to 1 for example, each time a new observation is taken, the model is reestimated. This is similar to the ugarchroll in package rugarch.

Value

A matrix containing the forecasts.

Author(s)

Matthieu Stigler

See Also

predict.nlar for the standard predict function.

Examples



data(barry)

## model estimated on full sample:
mod_vec <- VECM(barry, lag=2)

## generate 10 1-step-ahead forecasts:
preds_roll <- predict_rolling(mod_vec, nroll=10)

## plot the results:
plot(window(barry[,"dolcan"],start=1998), type="l", ylab="barry: dolcan")
preds_roll_ts <- ts(preds_roll$pred, start=time(barry)[nrow(barry)-10], freq=12)
lines(preds_roll_ts[,"dolcan"], col=2, lty=2)
legend("bottomright", lty=c(1,2), col=1:2, leg=c("True", "Fitted"))
title("Comparison of true and rolling 1-ahead forecasts\n")



tsDyn documentation built on Oct. 31, 2024, 5:08 p.m.