# VECM

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

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

## Signature

```ts
fitVECMFixedBeta(values, beta, differenceLags, includeIntercept)
```

Vector error correction with a fixed cointegrating vector. For series that wander individually but not apart: differencing them separately would throw away the long-run relationship, which is usually the thing of interest.

## Parameters

| Name | Type | Required | Notes |
| --- | --- | --- | --- |
| `values` | `number[][]` | yes | Multivariate series believed to be cointegrated. |
| `beta` | `number[]` | yes | The cointegrating vector, supplied rather than estimated so the arithmetic stays checkable. |
| `differenceLags` | `number` | yes | Lags of the differenced series included. · min: 0, integer: true |
| `includeIntercept` | `boolean` | no | Whether to fit a constant. |

## Returns

`{ beta, alpha, gamma, intercept, sigma_u_mle, error_correction, pi, adjustment_root, … }`

The adjustment coefficients `alpha` and the error-correction term. `adjustment_root` indicates whether the system actually returns to equilibrium.

## Errors

- When beta length does not match the number of variables — 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
[
  [57.3488705363, 57.391383279],
  [57.9060942406, 57.7180113466],
  [57.8301951168, 57.7940655992]
]
```

Showing 3 of 120 elements.

`beta`:

```json
[1, -1]
```

`differenceLags`:

```json
1
```

### Call

```ts
fitVECMFixedBeta(values, beta, differenceLags, includeIntercept)
```

### Returns

object with 17 fields: beta, alpha, gamma, intercept, sigma_u_mle, error_correction, pi, adjustment_root, …

```json
{
  "beta": [1, -1],
  "alpha": [-0.03243684502, 0.406805203364],
  "gamma": [
    [
      [0.041044635794, -0.023887057656],
      [-0.069691641426, 0.155827060535]
    ]
  ],
  "intercept": [0.004904479316, 0.007790140091],
  "sigma_u_mle": [
    [0.115776128937, 0.119483748379],
    [0.119483748379, 0.19954598501]
  ],
  "error_correction": [
    0.188082894,
    0.0361295176,
    -0.620844851,
    -0.6261144079,
    -0.5222041208,
    -0.7533463451
  ],
  "pi": [
    [-0.03243684502, 0.03243684502],
    [0.406805203364, -0.406805203364]
  ],
  "adjustment_root": 0.560757951616,
  "error_correction_loading_root": 0.560757951616,
  "half_life": null,
  "exact_half_life": null,
  "half_life_scope": "not-reported-short-run-gamma-present",
  "effective_observations": 118,
  "rank": 1
}
```

Showing 14 of 17 fields.

## Other exports

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