fintech-algorithms
Using a coding agent? Give it the skill: npx skills add IslamBaraka90/Fintech-Algorithms-Library What it does →

Structural VAR

Install and import#

bash
npm install fintech-algorithms
ts
import { fitRecursiveSVAR } from "fintech-algorithms/statistical-time-series/multivariate-systems/structural-var";

Signature#

fitRecursiveSVAR(values, lags)

Identifies structural shocks by Cholesky decomposition of the residual covariance. The identification is recursive, which means **variable ordering is an economic assumption**: the first variable is assumed unaffected contemporaneously by the others, and reordering changes the results.

Parameters#

NameTypeNotes
valuesnumber[][]Multivariate series. Column order encodes the identifying assumption, not merely a layout choice.
lagsnumberLag order.
min: 1 · integer: true

Returns#

{ coefficients, sigma_u_mle, impact_matrix, structural_shocks, reconstructed_shocks, … }

The impact matrix and structural shocks, with reconstructed shocks so the decomposition can be verified rather than trusted.

Errors#

  • When the residual covariance is not positive definite — throws

Complexity: time O(n × (k × lags)² + k³), space O((k × lags)²).

Worked example#

executed Captured by running this function on the input its own test provides. Real output of real code — but not asserted against a published figure.

Input#

values
[
  [-1.4163056264, -0.7075620912],
  [-1.4144491277, -0.24959813],
  [-1.915874322, -0.31233481]
]

Showing 3 of 120 elements.

lags
1

Call#

fitRecursiveSVAR(values, lags)

Returns#

object with 14 fields: coefficients, intercept, sigma_u_mle, impact_matrix, structural_shocks, reconstructed_sigma_u, covariance_reconstruction_max_error, structural_shock_covariance_mle, …

{
  "coefficients": [
    [
      [0.555831819774, 0.20542641337],
      [-0.118628539474, 0.408179850969]
    ]
  ],
  "intercept": [-0.070907764383, -0.013615076949],
  "sigma_u_mle": [
    [0.726815513707, 0.33092608263],
    [0.33092608263, 0.420249111781]
  ],
  "impact_matrix": [
    [0.852534758064, 0],
    [0.388167261804, 0.519206402739]
  ],
  "structural_shocks": [
    [-0.482046841046, 0.138538488641],
    [-1.181766100244, 0.181219012332],
    [-0.473854258318, 0.066359023845]
  ],
  "reconstructed_sigma_u": [
    [0.726815513707, 0.33092608263],
    [0.33092608263, 0.420249111782]
  ],
  "covariance_reconstruction_max_error": 1e-12,
  "structural_shock_covariance_mle": [
    [1, -1e-12],
    [-1e-12, 0.999999999999]
  ],
  "structural_shock_identity_max_error": 1e-12,
  "ordering": [0, 1],
  "companion_spectral_radius": 0.501247229166,
  "stability_state": "stable",
  "state": "identified-recursively",
  "reason": "lower-cholesky-ordering"
}

Other exports#

This module also exports companionMatrix, companionSpectralRadius, fitVAR, choleskyLower, fitVECMFixedBeta, movingAverageMatrices, impulseResponses, forecastErrorVarianceDecomposition. Every module additionally exports run as an alias of its primary function, and a meta object carrying its catalog id, domain, family, shape and article URL.

Diagrams#

Structural VAR — system map

Calculation flow#

Structural VAR system flow
flowchart LR
    A["Reduced-form residuals"] --> B["Declared variable ordering"]
    B --> C["Cholesky impact matrix"]
    C --> D["Orthogonal structural shocks"]
    D --> E["Ordering sensitivity record"]

How it works#

This page states the contract — how to call it correctly. The article explains the concept: why it works, and where it breaks.

Read the article →

References#

The rest of the Multivariate Systems family#