irfSvCompute#
Purpose#
Compute posterior impulse response bands from SV-BVAR draws.
Format#
- irf = irfSvCompute(result, n_ahead)#
- Parameters:
result (struct) – an instance of a
bvarSvResultstructure returned bybvarSvFit().n_ahead (scalar) – number of horizons to compute.
var_names (Mx1 string array) – Optional keyword, override variable names.
quiet (scalar) – Optional keyword, set to 1 to suppress printed output. Default = 0.
- Returns:
irf (struct) –
An instance of an
svIrfResultstructure containing:irf.median
Array of (n_ahead+1) mxm matrices, posterior median impulse responses.
irf.lower_68
Array of (n_ahead+1) mxm matrices, lower 68% credible band (16th percentile).
irf.upper_68
Array of (n_ahead+1) mxm matrices, upper 68% credible band (84th percentile).
irf.lower_90
Array of (n_ahead+1) mxm matrices, lower 90% credible band (5th percentile).
irf.upper_90
Array of (n_ahead+1) mxm matrices, upper 90% credible band (95th percentile).
irf.n_ahead
Scalar, number of horizons computed.
irf.m
Scalar, number of variables.
irf.n_draws
Scalar, number of posterior draws used.
irf.var_names
Mx1 string array, variable names.
Examples#
SV-BVAR IRF with Credible Bands#
new;
library timeseries;
data = loadd(getGAUSSHome("pkgs/timeseries/examples/macro.dat"));
ctl = bvarSvControlCreate();
ctl.p = 4;
ctl.n_draws = 10000;
ctl.n_burn = 5000;
result = bvarSvFit(data, ctl, quiet=1);
struct svIrfResult irf;
irf = irfSvCompute(result, 20);
Accessing Median and Bands#
new;
library timeseries;
data = loadd(getGAUSSHome("pkgs/timeseries/examples/macro.dat"));
result = bvarSvFit(data, quiet=1);
irf = irfSvCompute(result, 20, quiet=1);
// Median response of GDP (1) to FFR shock (3) at h=5
print "Median:" irf.median[6, 1, 3];
// 68% credible band
print "68% band:" irf.lower_68[6, 1, 3] "to" irf.upper_68[6, 1, 3];
// 90% credible band
print "90% band:" irf.lower_90[6, 1, 3] "to" irf.upper_90[6, 1, 3];
// Full path with bands
print "GDP response to FFR shock:";
print " h Median 68%lo 68%hi 90%lo 90%hi";
for h (0, 20, 1);
print h;;
print irf.median[h+1, 1, 3];;
print irf.lower_68[h+1, 1, 3];;
print irf.upper_68[h+1, 1, 3];;
print irf.lower_90[h+1, 1, 3];;
print irf.upper_90[h+1, 1, 3];
endfor;
Remarks#
Posterior bands: For each posterior draw \((B^{(i)}, U^{(i)})\), the function computes the Cholesky IRF using the time-averaged \(U^{(i)}\) for the structural rotation. The reported bands are pointwise quantiles across all draws:
68% bands: 16th and 84th percentiles (approximately \(\pm 1\sigma\))
90% bands: 5th and 95th percentiles
These are pointwise bands, not simultaneous bands. They capture parameter uncertainty but do not control joint coverage across all horizons.
Requires full draws. The estimation must be run with sv_keep = "full"
(the default) so that the posterior draws of B and U are available. If
sv_keep = "online" was used, an error is raised.
Model#
For each posterior draw \((B^{(s)}, U^{(s)})\) from the SV-BVAR, the structural IRF is computed using the time-averaged Cholesky factor:
where \(\bar{P}^{(s)}\) is derived from the draw-specific \(U^{(s)}\) and the mean of the time-varying diagonal \(D_t\). The posterior distribution of \(\{\Theta_h^{(s)}\}\) yields pointwise credible bands. Algorithm ———
For each of n_draws posterior draws:
Construct companion matrix \(F^{(s)}\) from \(B^{(s)}\).
Construct structural rotation \(\bar{P}^{(s)}\) from the draw’s Cholesky factor.
Compute \(\Theta_0^{(s)}, \ldots, \Theta_h^{(s)}\) via companion powers.
At each horizon, compute pointwise quantiles across all draws.
Complexity: \(O(n\_draws \cdot h \cdot m^2 p^2)\). Troubleshooting —————
“Requires full draws” error:
The SV-BVAR was estimated with sv_keep = "online" or "last", which does
not store the individual \((B, U)\) draws needed for posterior IRF bands.
Re-estimate with sv_keep = "full" (the default).
Bands are asymmetric: This is expected — the posterior distribution of IRFs is typically skewed, especially at longer horizons. Asymmetric bands reflect this correctly.
Bands include zero at all horizons: The shock may not have a statistically significant effect on the response variable. This is a finding, not a problem. References ———-
Primiceri, G.E. (2005). “Time varying structural vector autoregressions and monetary policy.” Review of Economic Studies, 72(3), 821-852.
Clark, T.E. (2011). “Real-time density forecasts from Bayesian vector autoregressions with stochastic volatility.” Journal of Business & Economic Statistics, 29(3), 327-341.
Library#
timeseries
Source#
irf.src
See also
Functions bvarSvFit(), irfCompute(), irfPlotData(), svarIdentify()