GVAR._stacked_innovations#

GVAR._stacked_innovations(linkage)[source]#

Align the unit residuals and rotate them into global coordinates.

Units may lose different numbers of leading observations to their own lag lengths, but every unit’s residuals end on the same date, so the common sample is the last min rows. Rotating by the inverse linkage turns the unit innovations \(u_t\) into the reduced-form innovations \(G_0^{-1} u_t\) of the global system, which is what the moving-average representation propagates.

Parameters:

linkage (NDArray[double]) – The (k, k) contemporaneous matrix \(G_0\).

Return type:

tuple[NDArray[double], int]

Returns:

The (common, k) rotated innovations and the common sample length.

Example

>>> import numpy as np
>>> from cultivars.multivariate.reduced_form.vector_autoregression import VARX
>>> y = np.random.default_rng(0).standard_normal((200, 2))
>>> deep = VARX(y[:, [0]], y[:, [1]], order=2).fit()
>>> shallow = VARX(y[:, [1]], y[:, [0]], order=1).fit()
>>> units = [deep, shallow]
>>> swap = np.array([[0.0, 1.0], [1.0, 0.0]])
>>> system = GVAR(units, swap, variable_labels=["p", "p"])
>>> innovations, common = system._stacked_innovations(np.eye(2))
>>> innovations.shape, common, [unit.resid.shape[0] for unit in units]
((198, 2), 198, [198, 199])
>>> bool(np.allclose(innovations[:, 1], units[1].resid[-198:, 0]))
True