srvar.analysis

srvar.analysis.fevd_cholesky(fit, *, horizons=24, draws=None, ordering=None, shock_scale='one_sd', quantile_levels=None, stationarity='allow', stationarity_tol=1e-10, stationarity_max_draws=None, rng=None)[source]

Convenience wrapper: compute Cholesky FEVD from a fitted model.

Return type:

FEVDResult

srvar.analysis.fevd_from_irf(irf, *, horizons=None, quantile_levels=None)[source]

Compute FEVD from a structural IRF.

Return type:

FEVDResult

Horizon definition

For forecast horizon h (steps ahead, h >= 1), FEVD uses the cumulative sum of squared structural impulse responses from IRF horizons 0..h-1.

Notes

  • This requires an orthogonal (structural) IRF. Reduced-form IRFs are not supported.

  • The IRF must include all integer horizons 0..(max(horizons)-1).

srvar.analysis.historical_decomposition_cholesky(fit, *, draws=200, ordering=None, shock_scale='one_sd', quantile_levels=None, stationarity='allow', stationarity_tol=1e-10, stationarity_max_draws=None, use_latent=None, rng=None)[source]

Historical decomposition from Cholesky-identified structural shocks.

This decomposes the observed (or latent) dataset into: - a shock-free baseline path conditional on the initial lags - additive contributions from each structural shock at each date

Return type:

HistoricalDecompositionResult

Notes

  • For ELB models, the VAR is defined on the latent shadow series. If use_latent is not specified, this function defaults to using fit.latent_dataset when available.

  • For volatility models, shocks are identified using the time-varying covariance state Sigma_t implied by h_draws (and q_draws for triangular covariance).

srvar.analysis.irf_cholesky(fit, *, horizons=24, draws=None, ordering=None, shock_scale='one_sd', quantile_levels=None, stationarity='allow', stationarity_tol=1e-10, stationarity_max_draws=None, rng=None)[source]

Compute Cholesky-identified structural IRFs.

This function computes reduced-form IRFs for each posterior draw and then applies a Cholesky factorization of the contemporaneous covariance matrix to obtain orthogonal shocks.

Return type:

IRFResult

Volatility models

For stochastic volatility models, the Cholesky factor is computed from the last latent covariance state in each draw (e.g. diag(exp(h_T)), or its triangular-covariance analogue).

Shock scaling

  • “one_sd”: a 1-s.d. structural shock (Var(u_j)=1), impact matrix is the Cholesky factor.

  • “unit”: normalize each shock so its own-variable impact at horizon 0 equals 1.

srvar.analysis.irf_reduced_form(fit, *, horizons=24, draws=None, ordering=None, quantile_levels=None, stationarity='allow', stationarity_tol=1e-10, stationarity_max_draws=None, rng=None)[source]

Compute reduced-form VAR impulse responses from posterior coefficient draws.

Return type:

IRFResult

Notes

  • Reduced-form IRFs do not require a covariance matrix. The impact response at horizon 0 is the identity matrix.

  • When ordering is provided, coefficient matrices are permuted into that ordering prior to computing IRFs.

  • When stationarity=”reject”, unstable VAR draws are filtered/rejection-sampled.

srvar.analysis.irf_sign_restricted(fit, *, horizons=24, restrictions, max_attempts=5000, min_accept=1000, draws=None, ordering=None, quantile_levels=None, stationarity='allow', stationarity_tol=1e-10, stationarity_max_draws=None, sign_tol=0.0, zero_tol=0.0, rng=None)[source]

Compute sign-restricted structural IRFs using random orthonormal rotations.

This uses the standard algorithm:

  1. For each posterior draw, compute reduced-form IRFs and a Cholesky factor P of the contemporaneous covariance.

  2. Draw random orthonormal rotations Q (Haar measure) and set the candidate impact matrix B = P @ Q.

  3. Accept the first rotation that satisfies the sign restrictions (within tolerances).

Restriction schema

restrictions is a nested dict:

  • top-level keys are shock names (in dict insertion order; shocks not listed are unrestricted)

  • second-level keys are variable names

  • leaf specs are either: - {horizon: sign, …} where sign is “+”, “-”, or “0” - {“sign”: “+”, “horizons”: [0, 1, 2], “cumulative”: false}

Horizon conventions

Restriction horizons are IRF horizons (0 = impact response). Output horizons follow the same conventions as irf_cholesky and may be a full 0..H grid (when horizons is an int) or an explicit list.

Notes

  • “+” / “-” require sign * response >= sign_tol.

  • “0” requires abs(response) <= zero_tol and can be infeasible in 1D.

rtype:

IRFResult