Main Content

forecast

Forecast responses from Bayesian vector autoregression (VAR) model

Description

forecast is well suited for computing out-of-sample unconditional forecasts of a Bayesian VAR(p) model that does not contain an exogenous regression component. For advanced applications, such as out-of-sample conditional forecasting, VARX(p) model forecasting, missing value imputation, and Gibbs sampler specification for posterior predictive distribution estimation, see simsmooth.

YF = forecast(PriorMdl,numperiods,Y) returns a path of forecasted responses YF over the length numperiods forecast horizon. Each period in YF is the mean of the posterior predictive distribution, which is derived from the posterior distribution of the prior Bayesian VAR(p) model PriorMdl given the response data Y. The output YF represents the continuation of Y.

NaNs in the data indicate missing values, which forecast removes using list-wise deletion.

example

[YF,YFStd] = forecast(PriorMdl,numperiods,Y) also returns the corresponding standard deviations of the posterior predictive distribution YFStd.

example

Examples

collapse all

Consider the 3-D VAR(4) model for the US inflation (INFL), unemployment (UNRATE), and federal funds (FEDFUNDS) rates.

[INFLtUNRATEtFEDFUNDSt]=c+j=14Φj[INFLt-jUNRATEt-jFEDFUNDSt-j]+[ε1,tε2,tε3,t].

For all t, εt is a series of independent 3-D normal innovations with a mean of 0 and covariance Σ. Assume a diffuse prior distribution for the parameters ([Φ1,...,Φ4,c],Σ).

Load and Preprocess Data

Load the US macroeconomic data set. Compute the inflation rate, stabilize the unemployment and federal funds rates, and remove missing values.

load Data_USEconModel
seriesnames = ["INFL" "UNRATE" "FEDFUNDS"];
DataTimeTable.INFL = 100*[NaN; price2ret(DataTimeTable.CPIAUCSL)];
DataTimeTable.DUNRATE = [NaN; diff(DataTimeTable.UNRATE)];
DataTimeTable.DFEDFUNDS = [NaN; diff(DataTimeTable.FEDFUNDS)];
seriesnames(2:3) = "D" + seriesnames(2:3);
rmDataTimeTable = rmmissing(DataTimeTable);

Create Prior Model

Create a diffuse prior model. Specify the response series names.

numseries = numel(seriesnames);
numlags = 4;

PriorMdl = bayesvarm(numseries,numlags,'SeriesNames',seriesnames);

Forecast Responses

Directly forecast two years (eight quarters) of observations from the posterior predictive distribution. forecast estimates the posterior distribution of the parameters, and then forms the posterior predictive distribution.

numperiods = 8;
YF = forecast(PriorMdl,numperiods,rmDataTimeTable{:,seriesnames});

YF is an 8-by-3 matrix of forecasted responses.

Plot the forecasted responses.

fh = rmDataTimeTable.Time(end) + calquarters(0:8);
tiledlayout(3,1)
for j = 1:PriorMdl.NumSeries
    nexttile
    plot(rmDataTimeTable.Time(end - 20:end),rmDataTimeTable{end - 20:end,seriesnames(j)},'r',...
        fh,[rmDataTimeTable{end,seriesnames(j)}; YF(:,j)],'b');
    legend("Observed","Forecasted",'Location','NorthWest')
    title(seriesnames(j))
end

Figure contains 3 axes objects. Axes object 1 with title INFL contains 2 objects of type line. These objects represent Observed, Forecasted. Axes object 2 with title DUNRATE contains 2 objects of type line. These objects represent Observed, Forecasted. Axes object 3 with title DFEDFUNDS contains 2 objects of type line. These objects represent Observed, Forecasted.

Consider the 3-D VAR(4) model of Forecast Responses from Posterior Predictive Distribution.

Load the US macroeconomic data set. Compute the inflation rate, stabilize the unemployment and federal funds rates, and remove missing values.

load Data_USEconModel
seriesnames = ["INFL" "UNRATE" "FEDFUNDS"];
DataTimeTable.INFL = 100*[NaN; price2ret(DataTimeTable.CPIAUCSL)];
DataTimeTable.DUNRATE = [NaN; diff(DataTimeTable.UNRATE)];
DataTimeTable.DFEDFUNDS = [NaN; diff(DataTimeTable.FEDFUNDS)];
seriesnames(2:3) = "D" + seriesnames(2:3);
rmDataTimeTable = rmmissing(DataTimeTable);

Create a diffuse prior model. Specify the response series names.

numseries = numel(seriesnames);
numlags = 4;

PriorMdl = bayesvarm(numseries,numlags,'SeriesNames',seriesnames);

Directly forecast two years (eight quarters) of response observations from the posterior predictive distribution. Return the posterior standard deviations.

numperiods = 8;
[YF,YStd] = forecast(PriorMdl,numperiods,rmDataTimeTable{:,seriesnames});

YF and YStd are 8-by-3 matrices of forecasted responses and corresponding standard deviations, respectively.

Plot the forecasted responses and approximate 95% credible intervals.

fh = rmDataTimeTable.Time(end) + calquarters(0:8);
for j = 1:PriorMdl.NumSeries
subplot(3,1,j)
plot(rmDataTimeTable.Time(end - 20:end),rmDataTimeTable{end - 20:end,seriesnames(j)},'r',...
    fh,[rmDataTimeTable{end,seriesnames(j)}; YF(:,j)],'b',...
    fh,[rmDataTimeTable{end,seriesnames(j)}; YF(:,j) + 1.96*YStd(:,j)],'b--',...
    fh,[rmDataTimeTable{end,seriesnames(j)}; YF(:,j) - 1.96*YStd(:,j)],'b--');
legend("Observed","Forecasted","Approximate 95% Credible Interval",'Location','NorthWest')
title(seriesnames(j))
end

Figure contains 3 axes objects. Axes object 1 with title INFL contains 4 objects of type line. These objects represent Observed, Forecasted, Approximate 95% Credible Interval. Axes object 2 with title DUNRATE contains 4 objects of type line. These objects represent Observed, Forecasted, Approximate 95% Credible Interval. Axes object 3 with title DFEDFUNDS contains 4 objects of type line. These objects represent Observed, Forecasted, Approximate 95% Credible Interval.

Input Arguments

collapse all

Prior Bayesian VAR model, specified as a model object in this table.

Model ObjectDescription
conjugatebvarmDependent, matrix-normal-inverse-Wishart conjugate model returned by bayesvarm, conjugatebvarm, or estimate
semiconjugatebvarmIndependent, normal-inverse-Wishart semiconjugate prior model returned by bayesvarm or semiconjugatebvarm
diffusebvarmDiffuse prior model returned by bayesvarm or diffusebvarm
normalbvarmNormal conjugate model with a fixed innovations covariance matrix, returned by bayesvarm, normalbvarm, or estimate

Forecast horizon, or the number of time points in the forecast period, specified as a positive integer.

Data Types: double

Presample and estimation sample multivariate response series, specified as a (numlags + numobs)-by-numseries numeric matrix.

Rows correspond to observations, and the last row contains the latest observation. forecast uses the first numlags = PriorMdl.P observations as a presample to initialize the prior model PriorMdl for posterior estimation. forecast estimates the posterior using the remaining numobs observations and PriorMdl.

numseries is the number of response variables PriorMdl.NumSeries. Columns correspond to individual response variables PriorMdl.SeriesNames.

For more details, see Algorithms.

Data Types: double

Output Arguments

collapse all

Path of multivariate response series forecasts, returned as a numperiods-by-numseries numeric matrix. YF is the mean of the posterior predictive distribution of each period in the forecast horizon.

YF represents the continuation of the response series Y. Rows correspond to observations; row j is the j-period-ahead forecast. Columns correspond to the columns in Y.

Forecast standard deviations, returned as a numperiods-by-numseries numeric matrix. YFStd is the standard deviation of the posterior predictive distribution of each period in the forecast horizon. Dimensions correspond to the dimensions of YF.

More About

collapse all

Tips

  • Monte Carlo simulation is subject to variation. If forecast uses Monte Carlo simulation, then estimates and inferences might vary when you call forecast multiple times under seemingly equivalent conditions. To reproduce estimation results, set a random number seed by using rng before calling forecast.

Algorithms

  • If the posterior predictive distribution is analytically intractable (true for most cases), forecast implements Markov Chain Monte Carlo (MCMC) sampling with Bayesian data augmentation to compute the mean and standard deviation of the posterior predictive distribution. To do so, forecast calls simsmooth, which uses a computationally intensive procedure.

  • Most Econometrics Toolbox™ forecast functions accept an estimated or posterior model object from which to generate forecasts. Such a model encompasses the parametric structure and data. However, the forecast function of Bayesian VAR models requires presample and estimation sample data to do the following:

    • Perform Bayesian parameter updating to estimate posterior distributions. forecast implements MCMC sampling with Bayesian data augmentation, which includes a Kalman filter smoothing step that requires the entire observed series.

    • Predict future responses in the presence of two sources of uncertainty:

      • Estimation noise ε1,…,εT, which induces parameter uncertainty

      • Forecast period noise εT+1,…,εT+numperiods

References

[1] Litterman, Robert B. "Forecasting with Bayesian Vector Autoregressions: Five Years of Experience." Journal of Business and Economic Statistics 4, no. 1 (January 1986): 25–38. https://doi.org/10.2307/1391384.

Version History

Introduced in R2020a