BVARResult._irf_draws#

BVARResult._irf_draws(horizon, *, orthogonalized)[source]#

Impulse responses of every retained draw, (S, horizon + 1, k, k).

The shared engine behind irf() and irf_bands(). For each draw it builds the companion matrix \(F^{(s)}\) from _stack_of() and reads the moving-average coefficients off its powers, \(\Psi_h^{(s)} = J (F^{(s)})^h J^\top\) with \(J = [I_k\ 0\ \cdots\ 0]\), accumulating the power one multiplication per lead rather than recomputing it. When orthogonalized it post-multiplies every lead by the draw’s own lower Cholesky factor, \(\Theta_h^{(s)} = \Psi_h^{(s)} P^{(s)}\) with \(\Sigma^{(s)} = P^{(s)} P^{(s)\top}\). With order zero the responses are the identity at lead zero and zero after, before any rotation.

Cost is \(O(S \cdot H \cdot (kp)^3)\) from the companion powers and \(O(S \cdot k^3)\) from the Cholesky factors, with the whole (S, H + 1, k, k) array held in memory. Callers summarize across the draw axis; nothing is cached, so irf() and irf_bands() with the same arguments each recompute it.

Parameters:
  • horizon (int) – Largest lead H; the array has H + 1 leads.

  • orthogonalized (bool) – Rotate each draw by its own Cholesky factor.

Return type:

NDArray[double]

Returns:

A (S, horizon + 1, k, k) array; entry [s, h, i, j] is draw s’s response of variable i at lead h to shock j.

Raises:

SpecificationError – If horizon is negative.

Example

>>> import numpy as np
>>> from cultivars.multivariate.large_dim.bayesian import BVAR
>>> y = np.random.default_rng(0).standard_normal((60, 2))
>>> res = BVAR(y, order=1).fit(n_draws=10, seed=0)
>>> draws = res._irf_draws(3, orthogonalized=False)
>>> draws.shape
(10, 4, 2, 2)
>>> np.allclose(draws[:, 0], np.eye(2))
True