tvpSvFit#
Purpose#
Estimate a Time-Varying Parameter VAR with Stochastic Volatility (Primiceri 2005).
Format#
- result = tvpSvFit(y)#
- result = tvpSvFit(y, p=2, n_draws=10000)
- result = tvpSvFit(y, p=2, n_draws=10000, n_burn=10000, seed=123)
- result = tvpSvFit(y, ctl=adv)
- Parameters:
y (TxM matrix or dataframe) – endogenous variables. If a dataframe, column names are used as variable names.
p (scalar) – Optional keyword, lag order. Default = 1.
n_draws (scalar) – Optional keyword, number of posterior draws to keep. Default = 5000.
n_burn (scalar) – Optional keyword, number of burn-in iterations to discard. Default = 5000.
seed (scalar) – Optional keyword, RNG seed. Default = 42.
quiet (scalar) – Optional keyword, set to 1 to suppress output. Default = 0.
ctl –
Optional keyword, an instance of a
tvpSvControlstructure. When provided, struct values are used and keywords are ignored. An instance is initialized by callingtvpSvControlCreate()and the following members can be set:adv.const
Scalar, include constant (1) or not (0). Default = 1.
adv.n_thin
Scalar, thinning factor. Default = 1 (keep every draw).
adv.seed
Scalar, RNG seed for reproducibility. Default = 42.
adv.use_asis
Scalar, enable ASIS interweaving for SV (recommended). Default = 1.
adv.q_b_shape
Scalar, IG prior shape for B drift covariance Q_B diagonal elements. Q_B,jj ~ IG(shape, scale). Default = 6.0.
adv.q_b_scale
Scalar, IG prior scale for Q_B. Default = 0.01 (slow drift).
adv.q_u_shape
Scalar, IG prior shape for U drift covariance Q_U diagonal elements. Default = 6.0.
adv.q_u_scale
Scalar, IG prior scale for Q_U. Default = 0.01.
adv.p0_b_kappa
Scalar, diffuse initialization scale for B FFBS. P_0 = kappa * I. Default = 10.0.
adv.p0_u_kappa
Scalar, diffuse initialization scale for U FFBS. Default = 10.0.
adv.u_bandwidth
Scalar, band-limited drifting U. 0 = full (default), k > 0 = first k off-diagonals per column. Reduces parameters from m(m-1)/2 to m*k for large systems.
adv.xreg
Matrix, exogenous regressors (T x K). Empty = none.
adv.quiet
Scalar, set to 1 to suppress printed output. Default = 0.
- Returns:
result (struct) –
An instance of a
tvpSvResultstructure containing:result.m
Scalar, number of endogenous variables.
result.p
Scalar, lag order.
result.n_obs
Scalar, effective sample size (T - p).
result.n_total
Scalar, total number of observations (T).
result.n_draws
Scalar, number of posterior draws kept.
result.const
Scalar, 1 if a constant was included.
result.var_names
Mx1 string array, variable names (from dataframe column names, or default).
result.b_mean
K x m matrix, posterior mean of terminal B_T (coefficients at the last observation).
result.b_sd
K x m matrix, posterior standard deviation of terminal B_T.
result.sv_mu
m x 1 vector, posterior mean of SV level parameters mu_i.
result.sv_phi
m x 1 vector, posterior mean of SV persistence parameters phi_i.
result.sv_sigma2
m x 1 vector, posterior mean of SV innovation variance sigma^2_i.
result.phi_accept_rate
m x 1 vector, Metropolis-Hastings acceptance rate for phi per equation. Healthy range: 20-60%.
result.y
Txm matrix, original data (stored for forecasting).
result.xreg
TxK matrix, exogenous regressors. Empty matrix if none.
result.seed
Scalar, RNG seed used.
Examples#
Default TVP-SV-VAR#
new;
library timeseries;
fname = getGAUSSHome("pkgs/timeseries/examples/data/us_macro_quarterly.csv");
y = loadd(fname, "gdp_growth + cpi_inflation + fed_funds");
// Default TVP-SV-VAR(1) with 5000 draws
result = tvpSvFit(y);
The summary includes SV acceptance diagnostics:
================================================================================
TVP-VAR-SV (Primiceri 2005)
Variables: 3, Lags: 1, T: 199
Draws: 5000, Burn-in: 5000
================================================================================
Phi acceptance rates:
0.47 0.41 0.52
================================================================================
Custom Draws and Lags#
Increase the lag order and posterior draws directly:
new;
library timeseries;
fname = getGAUSSHome("pkgs/timeseries/examples/data/us_macro_quarterly.csv");
y = loadd(fname, "gdp_growth + cpi_inflation + fed_funds");
// TVP-SV-VAR(2) with 10000 draws and 10000 burn-in
result = tvpSvFit(y, p=2, n_draws=10000, n_burn=10000);
// Terminal B_T (coefficients at the last observation)
print "Terminal B_T posterior mean:";
print result.b_mean;
Advanced Settings#
Use the tvpSvControl structure for fine-grained prior control:
new;
library timeseries;
fname = getGAUSSHome("pkgs/timeseries/examples/data/us_macro_quarterly.csv");
y = loadd(fname, "gdp_growth + cpi_inflation + fed_funds");
struct tvpSvControl adv;
adv = tvpSvControlCreate();
// Tighter drift priors (less time variation)
adv.q_b_shape = 10.0;
adv.q_b_scale = 0.001;
// Wider diffuse initialization
adv.p0_b_kappa = 25.0;
result = tvpSvFit(y, p=4, n_draws=10000, n_burn=10000, ctl=adv);
// SV parameters
print "SV persistence (phi):";
print result.sv_phi;
print "Phi acceptance rates:";
print result.phi_accept_rate;
Model#
The full Primiceri (2005) TVP-VAR-SV with three time-varying components:
where:
\(B_t\) are the VAR coefficients, following a random walk.
\(U_t\) are the lower-triangular Cholesky off-diagonals of the error covariance, following a random walk.
\(h_{i,t}\) are the log-volatilities, following independent AR(1) processes.
\(Q_B\) and \(Q_U\) are diagonal drift covariance matrices with Inverse-Gamma priors.
Remarks#
Sampler details: The sampler uses equation-by-equation Carter-Kohn forward-filtering backward-sampling (FFBS) for \(B_t\), following Primiceri’s original approach. This reduces the state dimension from \(K \times m\) to \(K\) per equation. The observation variance for each equation comes from the stochastic volatility \(h_{i,t}\).
Priors:
\(Q_B\) and \(Q_U\) have conjugate diagonal Inverse-Gamma posteriors
controlled by adv.q_b_shape, adv.q_b_scale, adv.q_u_shape, and
adv.q_u_scale. Smaller scale values (e.g., 0.001) produce tighter drift
priors, favoring slower parameter evolution. Larger scale values (e.g., 0.1)
allow more rapid time variation.
Initialization:
\(B_0\) is initialized from OLS and redrawn each iteration from its full
conditional. The initial state covariance is \(P_0 = \kappa I\) where
\(\kappa\) is controlled by adv.p0_b_kappa.
ASIS interweaving:
By default, the SV sampler uses the Ancillarity-Sufficiency Interweaving Strategy
(Kastner & Fruhwirth-Schnatter 2014) which alternates between centered and
non-centered parameterizations. This dramatically improves mixing when persistence
\(\phi_i\) is near 1. Disable with adv.use_asis = 0.
Band-limited U for large systems:
For systems with \(m > 15\), set adv.u_bandwidth > 0 to estimate only the
first \(k\) off-diagonals per column of \(U_t\), reducing parameters from
\(m(m-1)/2\) to \(m \cdot k\). This is an approximation that assumes
distant variables have negligible contemporaneous correlation.
Acceptance rates: The persistence parameter \(\phi_i\) is drawn via Metropolis-Hastings. The acceptance rate is reported in result.phi_accept_rate. Rates between 0.2 and 0.6 indicate good mixing. If rates are outside this range, increase n_burn or adjust the SV prior.
References#
Primiceri, G. E. (2005). “Time varying structural vector autoregressions and monetary policy.” Review of Economic Studies, 72(3), 821-852.
Del Negro, M. & G. E. Primiceri (2015). “Time varying structural vector autoregressions and monetary policy: A corrigendum.” Review of Economic Studies, 82(4), 1342-1345.
Carter, C. K. & R. Kohn (1994). “On Gibbs sampling for state space models.” Biometrika, 81(3), 541-553.
Kastner, G. & S. Fruhwirth-Schnatter (2014). “Ancillarity-sufficiency interweaving strategy (ASIS) for boosting MCMC estimation of stochastic volatility models.” Computational Statistics & Data Analysis, 76, 408-423.
Library#
timeseries
Source#
var.src
See also
Functions tvpSvControlCreate(), tvpSvForecast(), bvarSvFit(), varFit()