2. Reduced-form VAR Modeling

2.1. Description

\[y_{t} = C(r_{t}) x_{t} + B_{1}(r_{t}) y_{t-1} + \cdots + B_{p}(r_{t}) y_{t-p} + u_{t}\]

with \(r_{t} = 1, 2, \dots, h\) and transition probabilities \(p_{r_{t}, r_{t+1}}(I_{t})\).

The modern toolbox builds the reduced-form VAR via the rfvar_model factory; the option surface uses named arguments matching the modern arguments blocks.

A VAR is its own solution. solve builds the state space of every VAR class (rfvar_model, svar_model, prfvar_model, proxy_svar_model), constant or switching, straight from the parameters: no numerical steady state, no derivatives, no first-order solve. The steady state of regime \(r\) is \((I - \sum_k B_k(r))^{-1} c(r)\), the deterministic regressors at zero; with a unit root and no drift it is the minimum-norm solution, and with a drift the solve fails (code 21). solver_used reports 'var_closed_form'. Options that ask for another solution are refused with the reason (rise:var:ownSolution): solve_order above 1, solve_derivatives_only, sstate_unique, solve_perturbation_type='frwz', solve_bgp, an imposed or user-supplied steady state, nonzero sstate_exogenous. The perturbation types 'm', 'mw' and 'bm' all give this solution, and the solver option is not used.

2.2. Quick-start example

A constant-parameter five-variable VAR on Norwegian quarterly data.

2.2.1. Collecting and transforming data

% CLVMNACSCAB1GQNO : GDP Norway
% IR3TIB01NOQ156N  : 3-month interbank rate
% NORCPGRLE01IXOBQ : CPI excluding food and energy
% CCUSSP01NOQ650N  : NOK / USD spot
% POILWTIUSDQ      : Global price of WTI crude
xrange = '1990Q1:2022Q3';
rawdb  = fetch_fred({'NORCPGRLE01IXOBQ','IR3TIB01NOQ156N','CLVMNACSCAB1GQNO', ...
                     'CCUSSP01NOQ650N','POILWTIUSDQ'});

raw.P       = rawdb(1).series(xrange);
raw.INTRATE = rawdb(2).series(xrange);
raw.Y       = rawdb(3).series(xrange);
raw.EXRATE  = rawdb(4).series(xrange);
raw.POIL    = rawdb(5).series(xrange);

db          = struct();
db.PAI      = raw.P / lag(raw.P, 1);
db.R        = 1 + raw.INTRATE/100;
db.GROWTH   = raw.Y / lag(raw.Y, 1);
db.EXRATE   = 1 / raw.EXRATE;        % USD per NOK: rising => NOK appreciation
db.PAIOIL   = raw.POIL / lag(raw.POIL, 1);

2.2.2. Setting up the reduced-form VAR

endog = {'PAIOIL','GROWTH','PAI','R','EXRATE'};
exog  = {};
nlags = 4;
const = true;

mdl = rfvar_model(endog, ...
    lag_length        = nlags, ...
    constant_term     = const, ...
    deterministic_vars = exog);

(The legacy constructor was rfvar(endog, exog, nlags, const) positionally; the modern factory uses named arguments and a slightly different name order.)

2.2.3. Estimating the VAR (classical / OLS)

mdlest = estimate(mdl, ...
    data             = db, ...
    estim_start_date = date2serial(db.GROWTH.start), ...
    estim_end_date   = date2serial(db.GROWTH.finish));

Estimation dates are passed through date2serial – the modern date validator does not accept char strings.

With solve_check_stability true, the default, an estimate is mean-square stable. Least squares has no search that could keep to stable points, so an estimate with a root above one is refused (estimate:olsNotStable): set solve_check_stability to false to keep the least-squares estimate of a nonstationary VAR, or estimate with a prior, whose search rejects the points that are not stable.

2.2.4. Restrictions on the VAR

“Domestic variables do not affect oil prices” via linear restrictions on the VAR coefficients:

linres = {
    'b1(PAIOIL,PAI)=0'
    'b1(PAIOIL,GROWTH)=0'
    'b1(PAIOIL,R)=0'
    'b1(PAIOIL,EXRATE)=0'
    'b2(PAIOIL,PAI)=0'
    'b2(PAIOIL,GROWTH)=0'
    'b2(PAIOIL,R)=0'
    'b2(PAIOIL,EXRATE)=0'
    };

Or programmatically:

linres = cell(0, 1);
for ilag = 1:nlags
    for iv = 2:numel(endog)
        y = endog{iv};
        linres{end+1, 1} = sprintf('b%0.0f(PAIOIL,%s)=0', ilag, y);
    end
end

Estimate the restricted VAR:

mdlest_restr = estimate(mdl, ...
    data                      = db, ...
    estim_start_date          = date2serial(db.GROWTH.start), ...
    estim_end_date            = date2serial(db.GROWTH.finish), ...
    estim_linear_restrictions = linres);

2.3. Identification

A mixture of sign restrictions, contemporaneous zeros, and arbitrary restrictions on the impact matrix:

shock_names = {'oilp','demand','costpush','mp','forex'};

ident_restr1 = {
    % normalization with sign restrictions
    'PAIOIL{0}@oilp','+'
    'GROWTH{0}@demand','+'
    'PAI{0}@costpush','+'
    'R{0}@mp','+'
    'EXRATE{0}@forex','+'
    % block: oil-price domestic neutrality
    'PAIOIL{0}@demand',0
    'PAIOIL{0}@costpush',0
    'PAIOIL{0}@mp',0
    'PAIOIL{0}@forex',0
    % block: domestic-domestic
    'GROWTH{0}@costpush',0
    'GROWTH{0}@mp',0
    'GROWTH{0}@forex',0
    'PAI{0}@mp',0
    'PAI{0}@forex',0
    'R{0}@forex',0
    };

agnostic   = true;
max_trials = 6000;

Rfunc = struct();   ident = struct();

[Rfunc.unrestr, ident.unrestr] = ...
    identification(mdlest,       ident_restr1, shock_names, agnostic, max_trials);

[Rfunc.restr,   ident.restr]   = ...
    identification(mdlest_restr, ident_restr1, shock_names, agnostic, max_trials);

With restrictions given as a cell array, each shock name is matched to the restrictions that mention it, not to its position in the list: the names can be listed in any order ({'demand','supply','mp'} as well as {'demand','mp','supply'}), and each name labels the shock its restrictions define, in irf, variance_decomposition, historical_decomposition and structural_shocks alike, with or without regime switching. Outputs that list several shocks list them in the order the names were given; with fewer names than variables, the remaining shocks keep their own names.

There is one identification per parameterization. solve searches the rotation of each parameterization once and stores it with the solution, and every consumer reads that rotation: irf, variance_decomposition, historical_decomposition, forecast, simulate, filter, structural_shocks and the function identification returns (which, on a model identified with the same specification, reads that model’s rotation). An estimation stores the rotation of its estimate, and the shocks of the filtration it returns are those of the identified solution. When no rotation meets the restrictions within max_trials, every consumer returns the same code, 801, and an estimation returns no filtration.

The search of a regime draws its candidates from a stream of its own, seeded by a seed identify takes from the global random generator and by the bits of the parameter values that regime sees (rise.engine.var.vartools.rotation_key). The identity is that of the bits: bit-identical values in the same order give the same rotation, or the same 801, wherever and whenever the model is solved (a model handed unsolved to several consumers, a posterior or bootstrap draw, a parallel worker). A value one unit in the last place away, a signed zero, or the values in another order give another stream; two different inputs share one with probability about 2^-62. A change in the switching parameters of another regime leaves a regime’s stream as it is. Set the seed (rng) before identify to pick another admissible rotation. This holds for every VAR class (rfvar_model, prfvar_model, svar_model, proxy_svar_model), constant or switching.

Constructing a sign/zero-restriction identification engine consumes one global randi call to choose its seed; subsequent rotation searches use private streams and do not advance the global generator. LP identified_set uses its own supplied/default seed and leaves the global generator unchanged.

Serial execution and process-based parallel pools are validated for reproducible rotation searches. Thread-based pools have not been validated and are outside this guarantee.

A candidate whose column fails the sign restrictions of its shock is negated when its negative meets them all, when those restrictions cannot hold for both signs (a sign restriction, or a magnitude interval away from zero), and when the proposal is symmetric under the negation of a column (agnostic, or no zero restrictions). The law of the accepted rotations is then the law of the proposal conditional on the restrictions, as without the negation, and far fewer candidates are thrown away: with one sign restriction on each of twelve shocks, a candidate met them once in about 3600 trials and now always does. With agnostic false and zero restrictions, nothing is negated.

A proxy SVAR identifies the shock each proxy instruments. Restrictions given as a cell identify the other shocks, keep the impact of the instrumented ones (up to their sign), and turn the whole shock-impact block, the rows of the proxies included, by the same orthogonal matrix: the likelihood and the responses of the proxies do not change, and each proxy loads on its shock only. A 'choleski' identification would replace the instrumented shocks, and is refused.

Under sign restrictions the model is set identified: one rotation is one member of the set of admissible rotations, and two seeds can give very different answers. Report what holds across the set, such as the median and a band of an impulse response or of a variance share over many rotations (one identify per seed) or over the draws of a bootstrap or of a posterior, not the numbers of one rotation. These are summaries under the sampling law of the search, not a uniquely identified answer.

2.4. Recursive (Choleski) identification

identify(m, 'choleski', shock_names) (and identification(m, 'choleski', shock_names)) imposes a recursive structure: the impact matrix is the lower Cholesky factor of the residual covariance. The recursion follows the order in which you declared the variables, the list given to rfvar_model (or the units and variables given to prfvar_model), even though RISE stores the variables alphabetically. The first declared variable responds on impact to its own shock only, the second to the first two shocks, and so on. Shock k belongs to the k-th declared variable and takes the k-th name:

m  = rfvar_model({'ygap','pigap','Rgap'}, 'lag_length', 2);
me = estimate(m, 'data', db);
mi = identify(me, 'choleski', {'demand','supply','mp'});
r  = irf(mi, 'irf_periods', 20);   % r.mp: the shock of Rgap, which
                                   % moves neither ygap nor pigap on impact

Without names, the shocks are called <variable>_SHOCK (ygap_SHOCK, pigap_SHOCK, Rgap_SHOCK); with fewer names than variables, the first names label the shocks of the first declared variables and the others keep their default <variable>_SHOCK names. A reduced-form VAR that is not identified at all uses the same recursive factor: its shock e<k> is the shock of the k-th declared variable.

To use another recursion order, pass 'ordering': the names of all the variables in the order you want, or a permutation of 1:nvars that indexes the declared variables. The shock names then follow that order:

mi = identify(me, 'choleski', {'mp','demand','supply'}, ...
    'ordering', {'Rgap','ygap','pigap'});
% same as declaring rfvar_model({'Rgap','ygap','pigap'}, ...)
% and identifying with identify(me, 'choleski', {'mp','demand','supply'})

The declaration order is read from the model’s own equations (the equation of the k-th declared variable is the k-th one, <var>{t} = ... + e<k>{t}), so it is kept when the model is saved and loaded, re-estimated, bootstrapped, or rebuilt by set.

This is the reduced-form counterpart of a recursive structural VAR: an svar_model whose \(A_{0}\) is lower triangular in the declaration order (the zero restrictions a0(<earlier>,<later>)=0) has the same impulse responses, its shock epsilon<k> matching the k-th Choleski shock.

Note

Change of behavior. Earlier versions ran the recursion in RISE’s alphabetical order of the variables, so custom names given in the order of the declared variables labeled the wrong shocks (with the variables {'ygap','pigap','Rgap'}, the first name labeled the shock of Rgap), and the default <variable>_SHOCK responses followed the alphabetical recursion. Results of 'choleski' (and of an unidentified reduced-form VAR) change unless the variables were declared in alphabetical order. To reproduce the old results, pass 'ordering', sort(variables) and give the names in that order.

2.5. Structural shocks, IRFs and decompositions

Structural shocks:

params       = [];
sshocks      = struct();
sshocks.unrestr = structural_shocks(mdlest,       params, Rfunc.unrestr, shock_names);
sshocks.restr   = structural_shocks(mdlest_restr, params, Rfunc.restr,   shock_names);

Cholesky IRFs (no identification scheme):

cholShocks = [];
myirfs     = irf([mdlest, mdlest_restr], cholShocks, 40);

IRFs under the identification scheme:

params  = [];
myirfs  = irf([mdlest, mdlest_restr], shock_names, 40, params, Rfunc.unrestr);

Variance decomposition:

vd = variance_decomposition(mdlest_restr, params, Rfunc.restr);

Historical decomposition:

hd = historical_decomposition(mdlest_restr, params, Rfunc.restr);

The decomposition of a VAR is exact (the states are observed). Each variable gets a ts with one column per contributor, in this order:

  • init: the initial conditions, i.e. the first lag_length observations propagated through the autoregressive coefficients;

  • const: the constant term, accumulated from a zero start (when the VAR has 'constant_term', true);

  • one column per deterministic variable, under its name (the deterministic_vars), accumulated from a zero start;

  • one column per structural shock, under its name, accumulated from a zero start: the shock columns contain the contributions of the structural shocks only.

The columns add up to the data at every date: sum(double(d), 2), with d = hd.(endog{1}), is the data of endog{1} from the first date after the initial lags.

The constant and the initial conditions together make the deterministic path of the VAR (what the data would be without any shock); plot the shock columns alone (d(:, shock_names)) to see the story the shocks tell. The same columns come out for svar_model, proxy_svar_model and prfvar_model. With regime switching, the contributions of the regimes are weighted in each period by the smoothed regime probabilities of the filter, as for a switching DSGE model, and the output has one page (not one page per regime). Grouping shocks (the groups argument) or data with missing values send the computation to the filter-based route of DSGE models, whose columns are the shocks (or groups) and init.

2.6. Bootstrap and distributions

n      = 1000;
params = bootstrap(mdlest_restr, n);

Variance-decomposition distribution:

ci = [30, 50, 68, 90];
vd = variance_decomposition(mdlest_restr, params, Rfunc.restr);
% fanchart over the draws via fanchart() + plot_fanchart()

Historical-decomposition distribution:

hd = historical_decomposition(mdlest_restr, params, Rfunc.restr);

IRF distribution:

myirfs = irf(mdlest_restr, shock_names, 40, params, Rfunc.restr);

In each case the output is multi-page (one page per bootstrap draw); pass it to fanchart for central-tendency-plus-bands plots (see Forecasting and simulation).

2.7. Bayesian estimation

VAR-coefficient priors are built with the functions of the package rise.engine.var.var_priors (minnesota, niw, inw, user_defined, generate_sims_zha_prior, …). The canonical informative prior is the Minnesota family:

nlags  = 4;
const  = true;
exog   = {};

var_prior=rise.engine.var.var_priors.minnesota(endog,const,exog,nlags,db,...
    tightness=0.1,...
    lag_decay=1,...
    ar_first_lag=0.9);

minnesota, inw, niw and generate_sims_zha_prior take the data: they are scaled by the residual standard deviations \(s_{i}\) of univariate AR(nlags) fits of each variable, so they do not depend on the units of the data (multiply a variable by 100 and the posterior of the coefficients, in the original units, does not move). Their hyperparameters have the same names in every VAR prior:

Name

Meaning

tightness

overall tightness

cross_tightness

the other variables’ lags, relative to the own lags (minnesota, inw)

lag_decay

decay over the lags

constant_looseness

the constant and the deterministic terms; larger is looser

covariance_dummy_weight

Sims-Zha: replicates of the covariance dummies

co_persistence

Sims-Zha: weight of the dummy initial observation

own_persistence

Sims-Zha: weight of the sum-of-coefficients dummies

In equation \(i\) of minnesota, the own lag \(l\) has prior standard deviation tightness/\(l^{mathit{lag_decay}}\) and mean ar_first_lag at lag 1, lag \(l\) of variable \(j\) has tightness*cross_tightness\(s_{i}/(s_{j}l^{mathit{lag_decay}})\), and the constant and deterministic coefficients have \(s_{i}\) constant_looseness (defaults tightness 0.1, cross_tightness 0.5, lag_decay 1, constant_looseness 100: a large constant_looseness is loose, in every VAR prior, Sims-Zha included). The names were L1 to L7 until 30 October 2026; the old names are refused. inw adds an inverse-Wishart prior on the residual covariance, centered at \(\mathrm{diag}(s^{2})\) with df = n + 2 by default; niw is the normal-inverse-Wishart, \(\mathrm{vec}(B) \mid \Sigma \sim N(\mathrm{vec}(B_{0}), \Sigma \otimes \Omega)\), \(\Sigma \sim IW(S, \nu)\), with the same scaling in its default \(\Omega\) (an own/cross distinction is not possible there: no cross_tightness, and none in generate_sims_zha_prior either, for the same reason). Explicit moments replace the defaults (coeff_mean, coeff_var, scale_matrix, df for inw; mean, Omega, scale_matrix, df for niw); with all of them given, data may be [].

The VAR prior is passed through estim_var_prior; structural / non-VAR priors (if any) are passed through estim_priors. Each parameter’s prior density is counted once:

  • every VAR parameter without a prior in estim_priors gets RISE’s default flat prior, which carries its start value and its bounds and has no density;

  • the VAR prior covers the coefficients, and the residual covariance when it has a prior on it (use_sigma_prior: true for inw, niw and generate_sims_zha_prior, false for minnesota); the density of a covered parameter is the VAR prior’s, and a prior in estim_priors on it is combined with it (see Combined priors below);

  • a parameter the VAR prior does not cover has the prior you give it in estim_priors, or none. Without a proper prior on every free parameter the prior is improper, and there is no marginal data density: estimate reports NaN and says why, listing the parameters (posterior_maximization.improper_prior). Linear restrictions count: a parameter they fix does not need a prior. A Minnesota prior alone therefore has no marginal data density; use inw (the Minnesota prior on the coefficients and an inverse-Wishart on the covariance) to compare models.

2.7.1. Combined priors

A prior in estim_priors on a parameter the VAR prior covers is combined with the VAR prior: the prior is the product of the two densities. The same holds for the priors on the structural parameters of an svar_model whose reduced-form VAR prior weighs them (see Structural VAR Modeling). The product is a valid prior, but it is not normalized: the posterior mode and the posterior draws do not depend on its normalizing constant \(Z\), and every marginal data density is off by \(\log Z\). RISE estimates \(Z\) by Monte Carlo before the estimation and takes \(\log Z\) out of the log prior, so that every marginal data density (Laplace, the integrated routes, MHM, bridge and the other estimators of rise.engine.mdd.mdd) is that of the normalized prior:

  • \(Z\) is the mean, over draws of your priors in estim_priors, of the VAR prior’s density at the values the draws imply. The parameters only the VAR prior covers are integrated out by its marginal density (log_marginal), with any number of regimes: under switching, by the density of its regime plan (each value counted once, see Priors under regime switching), in closed form;

  • the draws come in batches of 1000 until the Monte Carlo standard error of \(\log Z\) is at most 0.01, with at least 2000 and at most 1,000,000 draws; the seed is fixed, so the constant is the same at every call;

  • posterior_maximization.prior_normalizer holds \(\log Z\) (log_Z), its standard error (mcse) and the number of draws, and the results table prints them beside the marginal data density;

  • when the constant cannot be computed (your priors do not determine what the VAR prior depends on and the VAR prior has no marginal density of what they determine; priors on the values of two or more regimes whose VAR-prior densities depend on values without a prior of yours, such as the variances of both regimes under niw, which depend on the coefficients; restrictions that tie a parameter with a prior to others) there is no marginal data density, and estimate says why (prior_normalizer.reason). In the switching case the regimes are dependent through the values no prior of yours covers, and their joint marginal is not a marginal of the VAR prior: it would take draws of the VAR prior’s conditionals, which no factory provides.

Before 30 October 2026 such a prior was an error (setup_priors:VarPriorOverlap).

A prior of your own is built with user_defined: you write the log density, as a function of the coefficients, the innovation covariance and a structure of your own parameters:

var_prior=rise.engine.var.var_priors.user_defined(endog,const,exog,nlags,...
    log_prior_func=@(params,Sigma,up) -0.5*sum(((params(up.pos)-up.target)/up.sd).^2),...
    user_params=struct('pos',[1 4],'target',[0.5;-0.5],'sd',0.1));

params is the coefficient matrix \(B\) (a row for the constant, one for each deterministic variable, then one for each variable at lag 1, lag 2, …, a column for each equation) stacked column by column; its names, in that order, are var_prior.params_order. The function returns a real scalar. The template is evaluated like the others: for a switching VAR the density of each value is counted once (see “Priors under regime switching”), and a model whose parameters switch in part needs the density of some elements, log_marginal_func(B,Sigma,maskB,maskSigma,up) (the log marginal density of B(maskB) and Sigma(maskSigma), the other elements integrated out); without it such a model is an error. ar_first_lag sets only the start value of the coefficients (var_prior.mean), not the density. Set use_sigma_prior=true when your density includes a proper prior on the covariance; otherwise the covariance has no proper prior and there is no marginal data density.

For a structural VAR these reduced-form priors reweight the prior of \(A_{0}\); structural lag priors (generate_structural_prior, Baumeister-Hamilton and Sims-Zha) do not: see Structural VAR Modeling.

Then the unrestricted Bayesian estimate:

ve = estimate(mdl, ...
    data             = db, ...
    estim_start_date = date2serial(db.GROWTH.start), ...
    estim_end_date   = date2serial(db.GROWTH.finish), ...
    estim_var_prior = var_prior);

and the restricted Bayesian estimate:

ve_lr = estimate(mdl, ...
    data                      = db, ...
    estim_start_date          = date2serial(db.GROWTH.start), ...
    estim_end_date            = date2serial(db.GROWTH.finish), ...
    estim_var_prior          = var_prior, ...
    estim_linear_restrictions = linres);

How the mode is found. With constant parameters and one of the conjugate templates (minnesota, inw, niw, generate_sims_zha_prior), estimate does not search: the posterior mode of the likelihood (conditional on the first lag_length observations, or the first kf_presample when that is larger) times the prior comes in closed form, or by alternating two closed forms, the coefficients given the residual covariance and the covariance given the coefficients:

  • priors whose coefficient covariance is \(\Sigma \otimes \Omega\) (niw, Sims-Zha) give the mode in one step; with Sims-Zha it is least squares on the data with the dummy observations appended;

  • priors with a fixed coefficient covariance (minnesota, inw) alternate the two steps until a pass no longer changes the estimates more than the one before, the precision of the arithmetic (on a 20-variable VAR in levels, about 1e-11, reached in 27 passes);

  • under minnesota and inw, linear restrictions (estim_linear_restrictions, and the panel estimators of a panel VAR) are imposed on the coefficients in the coefficient step.

estimate prints Posterior mode in closed form, and the mode is the one the numerical search would converge to (the search used to stop short of it on larger systems, after minutes). It searches numerically, as before, with regime switching (unless the regimes are known from the data: see Switching VARs with known regimes), linear restrictions under niw or Sims-Zha (the conditional of the covariance is then in general no longer inverse-Wishart), priors in estim_priors, endogenous priors, nonlinear or general restrictions, restrictions on the covariance, estim_mle, missing observations, data_demean or a user-defined template, and when the closed-form mode is rejected by the posterior kernel (an explosive VAR under solve_check_stability, say). estim_var_closed_form = false asks for the search anyway. With complete data and the priors in estim_priors, a search by fmincon or fminunc receives the exact score of the posterior, on the conditions of Exact score of switching VARs.

A closed-form mode of a VAR with constant parameters comes with the exact Hessian of the log posterior: with estim_hessian_type = 'fd' (the default) or 'optimizer' it is used instead of finite differences (hessian_source starts with analytic), and the Laplace marginal data density is reported when the prior is proper. On a VAR with a hundred parameters the finite differences take minutes; hessian(mdlest) still computes them.

Under niw, and generate_sims_zha_prior with its prior on the covariance, a closed-form mode also comes with the exact log marginal data density, log_marginal_data_density_closed_form: see Closed-form marginal data density of VARs.

Posterior draws come from sample_posterior, a Metropolis-within-Gibbs sampler for every VAR class, constant or switching (see Posterior sampling, Which sampler?). Here, with constant parameters and a conjugate template, it alternates two exact draws: the coefficients given the covariance, normal, and the covariance given the coefficients, inverse-Wishart. It starts at the mode and runs burnin sweeps first (500 by default); seed seeds the random numbers. It returns the model carrying one parameterization per draw; the second output holds the draws, the third the draws in the format of the generic samplers, with the acceptance rates, the inefficiency factors and, under switching, the regime paths. The linear restrictions used at estimation are honored: the draws of ve_lr obey them:

post.ve    = sample_posterior(ve,    1000, seed = 20250219);
post.ve_lr = sample_posterior(ve_lr, 1000, seed = 20250220);

Every analytic method (forecast, irf, the decompositions) called on post.ve then returns one result per draw.

2.8. Bayesian forecasting

forecast takes its inputs as name-value pairs: the data in simul_historical_data and the last date of history in simul_history_end_date, so that the forecast starts the period after it. The parameters are those of the model, here the 1000 draws of the posterior:

myfkst       = struct();
date_start   = date2serial('2003Q1');

myfkst.ve    = forecast(post.ve, ...
    simul_historical_data  = db, ...
    simul_history_end_date = date_start - 1);

myfkst.ve_lr = forecast(post.ve_lr, ...
    simul_historical_data  = db, ...
    simul_history_end_date = date_start - 1);

The initial conditions are read from db at the last date of history, 2002Q4 here, and the data after it are not used. The horizon is simul_periods, 12 when it is left empty. No shocks are drawn unless simul_shock_uncertainty = true, so the spread of the forecasts comes from the parameters.

Each series of the output, myfkst.ve.R for instance, is a ts with one column per posterior draw (a draw that fails to solve is left out). fanchart + plot_fanchart give the central tendency plus probability bands at ci = [30 50 68 90] percent:

out = fanchart(myfkst.ve.R, [30 50 68 90]);
plot_fanchart(out, [244 122 66]/255);

2.9. Conditional forecasting

A conditional forecast is a simulation plan (see Simulation plans) passed in simul_historical_data. Condition on the path of the policy rate R that the data record from 2003Q1 to 2004Q4. The plan reads its initial conditions from db at the last date of history, frees every shock over the horizon, and pins R over the window:

date_start  = date2serial('2003Q1');
nsteps      = 12;
cond_dates  = date2serial('2003Q1'):date2serial('2004Q4');
Rpath       = double(db.R('2003Q1:2004Q4')).';

sp = simplan.from_history(post.ve, db, date_start - 1, nsteps);
sp = free_shocks(sp);       % no identification scheme is needed
sp = append(sp, 'R', cond_dates, Rpath);

myfkst.ve = forecast(post.ve, simul_historical_data = sp);

The plan sets the start, the horizon and the initial conditions, so the call gives neither simul_history_end_date nor simul_periods. With more free shocks than conditions, the forecast takes the smallest shocks (least sum of squares) that deliver the path. No shocks are drawn unless simul_shock_uncertainty = true. As in the unconditional case, each series of myfkst.ve has one column per posterior draw, and every column follows the path of R over the window. The full surface of conditional-forecasting options is in Forecasting and simulation.

2.10. Markov-switching reduced-form VARs

A chain is declared with markov_chains and told which parameters it governs. The shorthands expand to the reduced-form parameter families:

Shorthand

Expands to

'b'

every b<lag>_<eq>_<var> – the whole autoregressive block

'c'

every constant c_<eq> and deterministic coefficient c_<eq>_<det>

's'

the diagonal of the residual covariance, covar_sigma_<eq>

'covar'

the FULL residual covariance – variances covar_sigma_<eq> and covariances covar_<i>_<j>

'covar(diag)' / 'covar(offdiag)'

just the variances / just the covariances

A reduced-form VAR carries one residual per equation, correlated across equations. 's' therefore switches only the variances; use 'covar' when the correlation structure should switch too:

markov_chains = struct( ...
    'name'                  , 'vol', ...
    'number_of_states'      , 2, ...
    'controlled_parameters' , {{'b','c','covar'}}, ...
    'endogenous_probabilities', {{}}, ...
    'probability_parameters', {{}});

mdl = rfvar_model(endog, lag_length = nlags, ...
                  constant_term = const, ...
                  markov_chains = markov_chains);

An entry that names nothing is an error rather than a silent no-op, so a typo in controlled_parameters is reported at construction. A parameter may also be named in full (b1_GDP_INF, c_GDP, covar_GDP_INF), and the lags of the lag forms ('b2', 'b1:3', 'b[1,3]') must be whole numbers within the lags of the model.

Note

A covar_* you never set keeps its identity entry – unit variance, zero covariance. Nobody should have to calibrate a covariance matrix by hand just to get a VAR to solve, and estimate seeds these from an OLS pre-fit in any case. Set them only when you mean something other than uncorrelated unit shocks.

A value you do supply must be a valid covariance: a negative variance or an inconsistent pair stops the solve with return code RFVAR_COV_NOT_PD. Unspecified defaults; specified-and- wrong is reported.

The same machinery serves panel VARs. prfvar_model expands the endogenous list to <unit>_<var> and builds an RFVAR on it, so its covariance parameters are covar_sigma_<unit>_<var> and covar_<unit_i>_<var_i>_<unit_j>_<var_j> and behave exactly as above.

2.10.1. Priors under regime switching

An informative VAR prior is defined on the reduced form \((B, \Sigma_u)\). Under switching, each regime has its own reduced form, and the prior counts the density of each value once. When every element switches, that is the prior at every regime, summed – the usual reading of “the same prior applied in each regime”. When a block does not switch (the covariance, when only the coefficients switch), its density is counted once, and the switching elements by their density conditional on it, once per value. Nothing extra is needed: pass the template as before and it spans the regimes:

var_prior=rise.engine.var.var_priors.minnesota(endog,const,exog,nlags,db,...
    tightness=0.25);

ve = estimate(mdl, ...
    data            = db, ...
    estim_var_prior = var_prior);

Three things are worth keeping in mind.

  • Which elements switch is read off the reduced forms of the regimes at a random point, with the restrictions in force: a coefficient that a linear restriction ties across the states is shared. Two switching blocks of which neither switches with the other’s chains (the coefficients with one chain, the covariance with another) are taken to be independent given the shared elements.

  • The conditional densities come from closed-form marginals of the templates (log_marginal): Gaussian marginals of the coefficients, principal blocks of the inverse-Wishart, and the matrix-t of coefficients whose covariance is integrated out. A split with no closed form is an error (var_priors:noClosedFormMarginal): the variances switching and the covariances not ('covar(diag)') under inw or niw, or coefficients shared by regimes whose covariance switches under generate_sims_zha_prior without a prior on the covariance.

  • estim_var_prior and estim_priors are independent and additive. The first is the VAR-shaped template; the second carries priors on individually named parameters (including transition-probability parameters and any parameter appearing in an endogenous_probabilities expression).

2.10.2. Threshold VARs: threshold_chains

A threshold VAR is a switching VAR whose transition probabilities are a hard function of a lagged variable. You can write that chain by hand (see the next section), but threshold_chains says it in one place and encodes the four things the hand-written form gets wrong silently:

m = rfvar_model(endo, ...
        lag_length        = 1, ...
        constant_term     = true, ...
        threshold_chains  = struct( ...
            'name'                 , 'sc', ...
            'controlled_parameters', {{'b','c','covar'}}, ...
            'threshold_variable'   , 'ACR'));

That is all. It desugars to a plain two-state markov_chains entry with

sc_tp_1_2 =   hard_threshold(ACR, sc_bar)
sc_tp_2_1 = 1-hard_threshold(ACR, sc_bar)

and one new estimable parameter, sc_bar, which is the threshold (pass a number as threshold_value to fix it instead — see below). The model then reports the chain it actually has: the sugar leaves no trace, so describe_regimes, filter and everything else behave exactly as they would for a hand-written chain.

Field

Meaning

name

chain name; creates <name>_bar (and <name>_gam if smooth)

controlled_parameters

as for markov_chains; {'b','c','covar'} switches everything

threshold_variable

an endogenous or deterministic name

threshold_value

'estimate' (default) or a number. See below

transition

'hard' (default), 'logistic', 'exponential'

slope

'estimate' (default) or a number; smooth transitions only

delay

the d in \(z_{t-d}\). Default 1

number_of_states

2 (only two states are supported)

State 1 is below the threshold, state 2 above.

Fixed values are literals, not parameters

threshold_value and slope each take 'estimate' or a number, and the two do different things:

  • 'estimate' creates a parameter — <name>_bar, <name>_gam — listed in probability_parameters and free to be given a prior.

  • a number is written into the transition expression as a literal. No parameter is created:

    sc_tp_1_2 =   hard_threshold(ACR, 0.25)
    sc_tp_2_1 = 1-hard_threshold(ACR, 0.25)
    

The asymmetry is deliberate. A fixed value that arrived as a parameter would be one more name you must remember to set, and forgetting is silent: the model builds, filters and returns a likelihood computed at whatever the uncalibrated value happened to be. That is the class of failure this sugar exists to remove, so a fixed threshold does not get a name.

What the sugar encodes

Four things, each of which is invisible when wrong:

  1. Which argument is the threshold. In logistic(x,g,c) it is the third; nothing tells you that.

  2. The two probabilities must be complements. A threshold rule is memoryless in \(s_{t-1}\) — where you go depends only on \(z_{t-d}\), not on where you were. Two independent logistics give a smooth-transition Markov chain, which is a different model, and nothing warns you.

  3. The timing. delay = 1 is written with no lag operator, because the transition matrix built at \(t\) governs the regime at \(t+1\) (see the note below). Writing ACR{-1} yourself would be off by one period.

  4. The steepness. transition = 'hard' uses hard_threshold, a genuine indicator, so there is no slope to choose and no risk of leaving observations in the interior of a logistic — where they become genuine regime mixtures rather than threshold regimes.

For a smooth transition instead, transition = 'logistic' adds a slope parameter <name>_gam and you are back to a smooth-transition VAR (Auerbach–Gorodnichenko style) with the same declaration.

Note

hard_threshold(x,c) is the \(g \to \infty\) limit of logistic(x,g,c), floored into \([\delta, 1-\delta]\) with \(\delta = 10^{-10}\). It is named hard_threshold rather than threshold because MATLAB’s Econometrics Toolbox ships a @threshold class, and a class folder takes precedence over a function on the path.

The floor keeps both regimes possible at every date, so the regimes of a threshold_chains model are a mixture and its posterior mode is searched numerically. A chain written by hand with a zero floor and a calibrated cutoff, hard_threshold(ACR,thr,0), has known regimes. Its posterior mode then comes in closed form under a conjugate prior, and under niw (or Sims-Zha with its prior on the covariance) so does its marginal data density given the cutoff (see Switching VARs with known regimes); threshold_profile scores many cutoffs at once (see VAR threshold profiles).

2.10.3. Time-varying transition probabilities

Transition probabilities may be written as expressions of the model’s own variables, via endogenous_probabilities:

markov_chains = struct( ...
    'name'                  , 'sc', ...
    'number_of_states'      , 2, ...
    'controlled_parameters' , {{'b','c','covar'}}, ...
    'endogenous_probabilities', {{ ...
         'sc_tp_1_2 = logistic(ACR,gam,thr)', ...
         'sc_tp_2_1 = 1-logistic(ACR,gam,thr)'}}, ...
    'probability_parameters', {{'gam','thr'}});

Important

Timing. The transition matrix built from time-\(t\) data governs the regime at \(t+1\). An expression written on the contemporaneous variable ACR therefore implements the lagged rule

\[I_t = \mathbb{1}\{ ACR_{t-1} > \bar{ACR} \}.\]

Writing ACR{-1} would be off by one period. The same convention holds in simulation, so filter and simulator agree.

With gam large the logistic approaches an indicator and the chain becomes a threshold VAR: the regime is a deterministic function of the data and the Hamilton filter collapses onto that path. Keep gam steep enough that no observation lands in the interior of the logistic – an observation that does is treated, correctly, as a genuine mixture of the two regimes, which is no longer a threshold model.