# Forecast-Error Variance Decomposition

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

Full page: https://docs.thefintechbuilder.com/statistical-time-series/multivariate-systems/forecast-error-variance-decomposition/
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 { forecastErrorVarianceDecomposition } from "fintech-algorithms/statistical-time-series/multivariate-systems/forecast-error-variance-decomposition";
```

## Signature

```ts
forecastErrorVarianceDecomposition(coefficients, sigmaU, horizon, impactMatrix)
```

Attributes each variable's forecast error variance to the structural shocks, by horizon. Answers 'how much of the movement in this variable is explained by that one' — subject, again, to the identification.

## Parameters

| Name | Type | Required | Notes |
| --- | --- | --- | --- |
| `coefficients` | `number[][]` | yes | VAR coefficient matrices. |
| `sigmaU` | `number[][]` | yes | Residual covariance matrix. |
| `horizon` | `number` | yes | Periods to decompose. · min: 1, integer: true |
| `impactMatrix` | `Matrix` | no | Contemporaneous impact matrix. Defaults to the lower Cholesky factor of `sigmaU`, which is the recursive identification implied by variable order. |

## Returns

`{ shares, impact_matrix, horizon, row_sums, companion_spectral_radius, stability_state, … }`

Variance shares with `row_sums` — each row should sum to 1, and reporting it makes a broken decomposition obvious rather than plausible.

## Errors

- When sigmaU is not symmetric positive definite — throws

## Complexity

Time `O(horizon × k³)`, space `O(horizon × k²)`.

## 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

`coefficients`:

```json
[
  [
    [0.55, 0.18],
    [-0.12, 0.42]
  ]
]
```

`sigmaU`:

```json
[
  [0.64, 0.28],
  [0.28, 0.425]
]
```

`horizon`:

```json
8
```

`impactMatrix`:

```json
[
  [0.8, 0],
  [0.35, 0.55]
]
```

### Call

```ts
forecastErrorVarianceDecomposition(coefficients, sigmaU, horizon, impactMatrix)
```

### Returns

object with 10 fields: shares, impact_matrix, horizon, row_sums, companion_spectral_radius, stability_state, stability_boundary, near_boundary_threshold, …

```json
{
  "shares": [
    [
      [1, 0],
      [0.288235294118, 0.711764705882]
    ],
    [
      [0.989143895172, 0.010856104828],
      [0.260105787983, 0.739894212017]
    ],
    [
      [0.980857224422, 0.019142775578],
      [0.258546673098, 0.741453326902]
    ]
  ],
  "impact_matrix": [
    [0.8, 0],
    [0.35, 0.55]
  ],
  "horizon": 8,
  "row_sums": [
    [1, 1],
    [1, 1],
    [1, 1]
  ],
  "companion_spectral_radius": 0.502593274925,
  "stability_state": "stable",
  "stability_boundary": 1,
  "near_boundary_threshold": 0.9,
  "state": "computed",
  "reason": "orthogonalized-squared-response-share"
}
```

## Other exports

`companionMatrix`, `companionSpectralRadius`, `fitVAR`, `choleskyLower`, `fitRecursiveSVAR`, `fitVECMFixedBeta`, `movingAverageMatrices`, `impulseResponses`. 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/forecast-error-variance-decomposition/
- Implementation source: https://github.com/IslamBaraka90/Fintech-Algorithms-Library/blob/main/src/statistical-time-series/multivariate-systems/forecast-error-variance-decomposition/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
