Skip to content
SK Subham KumarTSF Hub · time-series forecasting
Classical & statistical1987MultivariateCointegration

VECM

Vector Error Correction Model

When non-stationary series move together in the long run, such as GDP and consumption or pairs of prices, VECM models both their short-run dynamics and the pull back to equilibrium.

Overview

Differencing non-stationary series before a VAR throws away information about their long-run relationship. If a combination of the series is stationary, they are cointegrated, and a VECM keeps that relationship: short-run changes depend on recent changes and on how far the system is from equilibrium.

The cointegration rank (how many independent long-run relations exist) is chosen with Johansen’s trace or maximum-eigenvalue test. Rank 0 means no cointegration (use a VAR in differences); full rank means the series are already stationary (use a VAR in levels).

How it works

\[\Delta y_t=\alpha\beta^\top y_{t-1}+\sum_{i=1}^{p-1}\Gamma_i\,\Delta y_{t-i}+c+\varepsilon_t\]

\(\beta^\top y_{t-1}\) are the \(r\) stationary long-run relations (error-correction terms); \(\alpha\) holds the adjustment speeds: how strongly each variable reacts to disequilibrium. \(\Gamma_i\) capture short-run dynamics.

When to use it

Use it for

  • Macroeconomic systems (GDP, consumption, investment, rates)
  • Pairs and baskets of related prices
  • Energy prices across connected markets

Avoid it for

  • Stationary series (use VAR)
  • Many variables with short samples: the parameter count grows quickly

Key settings

SettingWhat it controlsTypical value
k_ar_diffLags in differencesAIC/BIC via select_order
coint_rankNumber of long-run relationsJohansen test
deterministicWhere constants and trends enter'ci' (constant in the relation)

Python example

✓ Tested: runs end to endDownload vecm.py
import numpy as np
import pandas as pd
from statsmodels.datasets import macrodata
from statsmodels.tsa.vector_ar.vecm import VECM, select_coint_rank, select_order

data = macrodata.load_pandas().data
data.index = pd.period_range("1959Q1", periods=len(data), freq="Q")
y = np.log(data[["realgdp", "realcons", "realinv"]])
train, test = y[:-8], y[-8:]

lags = select_order(train, maxlags=8, deterministic="ci").aic          # lag order in differences
rank = select_coint_rank(train, det_order=0, k_ar_diff=lags, method="trace", signif=0.05)
print(f"lags: {lags}, cointegration rank: {rank.rank}")

res = VECM(train, k_ar_diff=lags, coint_rank=rank.rank, deterministic="ci").fit()
print("long-run relation (beta):", res.beta.ravel().round(3))

forecast = pd.DataFrame(res.predict(steps=8), index=test.index, columns=y.columns)
mape = ((np.exp(test) - np.exp(forecast)).abs() / np.exp(test)).mean() * 100
print("MAPE %:", mape.round(2).to_dict())

Tips & pitfalls

  • Work with logs so relations are in elasticities.
  • Check the sign and size of α: meaningful adjustment speeds are a good sanity check.
  • Cointegration tests have low power in short samples; confirm with economic reasoning.

References

  1. Engle, R. F., & Granger, C. W. J. (1987). Co-integration and error correction: representation, estimation, and testing. Econometrica, 55(2), 251–276.
  2. Johansen, S. (1991). Estimation and hypothesis testing of cointegration vectors in Gaussian vector autoregressive models. Econometrica, 59(6), 1551–1580.