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

Impulse-Response Analysis

Install and import#

bash
npm install fintech-algorithms
ts
import { impulseResponses } from "fintech-algorithms/statistical-time-series/multivariate-systems/impulse-response-analysis";

Signature#

impulseResponses(coefficients, horizon, impactMatrix)

Traces how a one-off shock to one variable propagates through the system over time. The headline output of any VAR — and only interpretable given the identifying assumption that produced the impact matrix.

Parameters#

NameTypeNotes
coefficientsnumber[][]VAR coefficient matrices.
horizonnumberPeriods to trace.
min: 1 · integer: true
impactMatrixMatrixContemporaneous impact matrix. Defaults to the identity, so the responses are to unit shocks in each variable rather than to structurally identified ones.
optional

Returns#

{ responses, cumulative_responses, horizon, impact_matrix, companion_spectral_radius, stability_state, … }

Responses and their cumulative sums, plus the companion spectral radius — above 1 the system is explosive and the responses diverge rather than decay, which is stated instead of silently plotted.

Errors#

  • When the coefficient matrices are not square or are inconsistent in dimension — throws

Complexity: time O(horizon × k³), space O(horizon × k²).

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#

coefficients
[
  [
    [0.55, 0.18],
    [-0.12, 0.42]
  ]
]
horizon
8
impactMatrix
[
  [0.8, 0],
  [0.35, 0.55]
]

Call#

impulseResponses(coefficients, horizon, impactMatrix)

Returns#

object with 10 fields: responses, cumulative_responses, horizon, impact_matrix, companion_spectral_radius, stability_state, stability_boundary, near_boundary_threshold, …

{
  "responses": [
    [
      [0.8, 0],
      [0.35, 0.55]
    ],
    [
      [0.503, 0.099],
      [0.051, 0.231]
    ],
    [
      [0.28583, 0.09603],
      [-0.03894, 0.08514]
    ]
  ],
  "cumulative_responses": [
    [
      [0.8, 0],
      [0.35, 0.55]
    ],
    [
      [1.303, 0.099],
      [0.401, 0.781]
    ],
    [
      [1.58883, 0.19503],
      [0.36206, 0.86614]
    ]
  ],
  "horizon": 8,
  "impact_matrix": [
    [0.8, 0],
    [0.35, 0.55]
  ],
  "companion_spectral_radius": 0.502593274925,
  "stability_state": "stable",
  "stability_boundary": 1,
  "near_boundary_threshold": 0.9,
  "state": "computed",
  "reason": "ma-recursion-times-declared-impact"
}

Other exports#

This module also exports companionMatrix, companionSpectralRadius, fitVAR, choleskyLower, fitRecursiveSVAR, fitVECMFixedBeta, movingAverageMatrices, 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#

Impulse-Response Analysis — system map

Calculation flow#

Impulse-Response Analysis system flow
flowchart LR
    A["VAR coefficient matrices"] --> B["Phi zero equals identity"]
    B --> C["Moving-average recursion"]
    C --> D["Multiply by impact matrix"]
    D --> E["Response and cumulative paths"]

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#