# VAR

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

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

## Signature

```ts
fitVAR(values, lags, includeIntercept)
```

Vector autoregression: every series regressed on lags of all of them. The natural model when variables move together, and the base every impulse-response and variance-decomposition result is computed from.

## Parameters

| Name | Type | Required | Notes |
| --- | --- | --- | --- |
| `values` | `number[][]` | yes | Multivariate series, one row per observation and one column per variable. Column order is meaningful — everything downstream refers to variables by position. |
| `lags` | `number` | yes | Lag order. Parameters grow with the square of the number of variables, so this is where a VAR runs out of data. · min: 1, integer: true |
| `includeIntercept` | `boolean` | no | Whether to fit a constant term. |

## Returns

`{ intercept, coefficients, sigma_u_mle, residuals, fitted, one_step_forecast, effective_observations, … }`

Coefficients and the residual covariance, which is the input to structural identification.

## Errors

- When observations are fewer than the parameters to estimate — throws

## Complexity

Time `O(n × (k × lags)²)`, 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
fitVAR(values, lags, includeIntercept)
```

### Returns

object with 16 fields: intercept, coefficients, sigma_u_mle, residuals, fitted, one_step_forecast, effective_observations, variables, …

```json
{
  "intercept": [-0.070907764383, -0.013615076949],
  "coefficients": [
    [
      [0.555831819774, 0.20542641337],
      [-0.118628539474, 0.408179850969]
    ]
  ],
  "sigma_u_mle": [
    [0.726815513707, 0.33092608263],
    [0.33092608263, 0.420249111781]
  ],
  "residuals": [
    [-0.410961687007, -0.115184732022],
    [-1.00749667636, -0.364632839724],
    [-0.403977225473, -0.149480679886]
  ],
  "fitted": [
    [-1.003487440693, -0.134413397978],
    [-0.90837764564, 0.052298029724],
    [-1.199973495027, 0.086173519486]
  ],
  "one_step_forecast": [0.452328292866, -0.113742494174],
  "effective_observations": 119,
  "variables": 2,
  "lags": 1,
  "row_sum_stability_bound": 0.761258233144,
  "companion_spectral_radius": 0.501247229166,
  "stability_state": "stable",
  "stability_boundary": 1,
  "near_boundary_threshold": 0.9
}
```

Showing 14 of 16 fields.

## Other exports

`companionMatrix`, `companionSpectralRadius`, `choleskyLower`, `fitRecursiveSVAR`, `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/var/
- Implementation source: https://github.com/IslamBaraka90/Fintech-Algorithms-Library/blob/main/src/statistical-time-series/multivariate-systems/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
