VECM
Install and import#
npm install fintech-algorithmsimport { fitVECMFixedBeta } from "fintech-algorithms/statistical-time-series/multivariate-systems/vecm";Signature#
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 | Notes |
|---|---|---|
values | number[][] | Multivariate series believed to be cointegrated. |
beta | number[] | The cointegrating vector, supplied rather than estimated so the arithmetic stays checkable. |
differenceLags | number | Lags of the differenced series included. min: 0 · integer: true |
includeIntercept | boolean | Whether to fit a constant. optional |
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#
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#
[
[57.3488705363, 57.391383279],
[57.9060942406, 57.7180113466],
[57.8301951168, 57.7940655992]
]Showing 3 of 120 elements.
[1, -1]1Call#
fitVECMFixedBeta(values, beta, differenceLags, includeIntercept)Returns#
object with 17 fields: beta, alpha, gamma, intercept, sigma_u_mle, error_correction, pi, adjustment_root, …
{
"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#
This module also 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.
Diagrams#
Calculation flow#
VECM system flow
flowchart LR
A["Aligned integrated levels"] --> B["Supplied rank and normalized beta"]
B --> C["Lagged equilibrium error"]
C --> D["Alpha and short-run Gamma"]
D --> E["Adjustment diagnostics"]
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.
References#
- statsmodels vector autoregression documentation — statsmodels developers
- statsmodels VECM API documentation — statsmodels developers
- Co-integration and Error Correction: Representation, Estimation, and Testing — Robert F. Engle and Clive W. J. Granger
- New Introduction to Multiple Time Series Analysis — Helmut Lütkepohl
- Macroeconomics and Reality — Christopher A. Sims
- Statistical Analysis of Cointegration Vectors — Søren Johansen
- Publication boundary