# Structural VAR

`D09-F03-A02` · Statistical Time Series → Multivariate Systems · archetype `record-transform` · difficulty 4/5 · verification **contract**

Full page: https://docs.thefintechbuilder.com/statistical-time-series/multivariate-systems/structural-var/
Agent skill: `npx skills add IslamBaraka90/Fintech-Algorithms-Library` — https://docs.thefintechbuilder.com/guides/agent-skill/

## Install and import

```bash
npm install fintech-algorithms
```

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

## Signature

```ts
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

| Name | Type | Required | Notes |
| --- | --- | --- | --- |
| `values` | `number[][]` | yes | Multivariate series. Column order encodes the identifying assumption, not merely a layout choice. |
| `lags` | `number` | yes | Lag 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

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`:

```json
[
  [-1.4163056264, -0.7075620912],
  [-1.4144491277, -0.24959813],
  [-1.915874322, -0.31233481]
]
```

Showing 3 of 120 elements.

`lags`:

```json
1
```

### Call

```ts
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, …

```json
{
  "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

`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.

## Verification and provenance

Tier: **contract**.

The module loads, the entry point is callable and its declared signature matches the compiled code. The example below is real captured output, but no independently published figure asserts the numbers.

Both tiers guarantee the signature. Full explanation: https://docs.thefintechbuilder.com/guides/verification/

Generated from the docs.json payload shipped inside fintech-algorithms@0.13.1.
The signature and parameter list are checked against the compiled implementation at build time,
so a description that contradicts the code fails the build rather than reaching this file.

## Links

- Article (how it works, step by step): https://thefintechbuilder.com/statistical-time-series/multivariate-systems/structural-var/
- Implementation source: https://github.com/IslamBaraka90/Fintech-Algorithms-Library/blob/main/src/statistical-time-series/multivariate-systems/structural-var/impl.ts
- Package on npm: https://www.npmjs.com/package/fintech-algorithms
- Domain index for agents: https://docs.thefintechbuilder.com/statistical-time-series/llms.txt
