NarrativeSignRestrictedSVAR.identify#

NarrativeSignRestrictedSVAR.identify()[source]#

Draw rotations and keep those reproducing signs and history alike.

Each candidate’s structural shocks at the event periods are recovered as B^{-1} u_t; traditional and shock-sign requirements on a column are checked jointly under the column flip, and contribution events, which are flip-invariant, are checked once after every column’s orientation is settled.

Return type:

SignRestrictedSVARResult

Returns:

The accepted set.

Raises:
  • SpecificationError – If no rotation is accepted within the attempt budget – the narrative events contradict the traditional signs, or the history at this reduced form.

  • NumericalError – If the innovation covariance is not positive definite.

Example

Every accepted rotation reproduces the declared history through its own shocks; declaring the wrong sign for a dominant event exhausts the budget:

>>> import numpy as np
>>> from cultivars.multivariate.reduced_form.vector_autoregression import VAR
>>> rng = np.random.default_rng(0)
>>> B = np.array([[1.0, 0.5], [0.3, 1.0]])
>>> A = np.array([[0.5, 0.1], [0.0, 0.4]])
>>> eps = rng.standard_normal((402, 2))
>>> y = np.zeros((402, 2))
>>> for t in range(1, 402):
...     y[t] = A @ y[t - 1] + B @ eps[t]
>>> res = VAR(y, order=1, names=("gdp", "infl")).fit()
>>> signs = {"demand": {"gdp": "+", "infl": "+"}}
>>> event = (("demand", "gdp", 238, "overwhelming"),)
>>> sset = NarrativeSignRestrictedSVAR(
...     res, signs, shock_signs=(("demand", 238, "-"),), contributions=event, draws=100
... ).identify()
>>> shocks = np.linalg.solve(sset.impacts, np.tile(res.resid[238], (100, 1))[..., None])
>>> bool(np.all(shocks[:, 0, 0] < 0.0))
True
>>> shares = np.abs(sset.impacts[:, 0, :] * shocks[:, :, 0])
>>> bool(np.all(shares[:, 0] > shares[:, 1]))
True
>>> NarrativeSignRestrictedSVAR(
...     res, signs, shock_signs=(("demand", 238, "+"),), contributions=event,
...     draws=10, max_attempts=500,
... ).identify()
Traceback (most recent call last):
cultivars.exceptions.SpecificationError: no rotation satisfied the declared signs ...