Bayesian Vector Error Correction (VECM)

Python · R · Part 6 of the VAR arc — cointegration

Overview

Part 6 of the VAR arc: cointegration. Every VAR so far treated its variables as either stationary (growth rates) or, in the large BVAR, as unit-root levels shrunk toward random walks. Cointegration is the economically loaded case in between: several series each wander like a random walk (I(1)), yet specific linear combinations of them are stationary — pinned by a long-run equilibrium the economy is always pulled back toward. Difference the level VAR into error-correction form and a single levels term Πyt1\Pi\,y_{t-1} carries all the cointegration; its rank classifies the system. The reduced-rank factorization Π=αβ\Pi=\alpha\beta' splits it into the cointegrating vectors β\beta (the stationary combinations that don't wander) and the adjustment loadings α\alpha (the speed each variable is pulled back off-equilibrium). Only the column space of β\beta is identified, so a linear normalization β=[Ir;B]\beta=[I_r;B] makes the model conditionally linear — a three-block conjugate Gibbs sampler in a new from-scratch module (bvecm.py, leaving bvar.py untouched), with the frequentist Johansen trace test alongside as the rank reference.

Δyt=c+Πyt1+i=1p1ΓiΔyti+εt,Π=αβ,α,βRm×r\Delta y_t = c + \Pi\,y_{t-1} + \sum_{i=1}^{p-1}\Gamma_i\,\Delta y_{t-i} + \varepsilon_t, \qquad \Pi = \alpha\beta', \quad \alpha,\beta \in \mathbb{R}^{m\times r}

A cointegration trilogy — the rank dictates the forecast

The example is built as a trilogy that walks the full spectrum of what a cointegration analysis can find — and shows that the right forecasting model follows directly from the rank. Cointegration is only defined for series that are individually I(1) but share a stationary combination, so every notebook pre-tests the integration order first (Augmented Dickey–Fuller) before running the sampler — the discipline that separates a real long-run equilibrium from a category error. The same machinery meets three verdicts: the term structure is genuinely cointegrated; the Fisher effect fails the premise (one series is already stationary); and money demand is a relation that once held but has broken down.

Results

Getting the rank right is getting the forecasting model right. (1) Term structure (6a): the four Treasury yields are all I(1) but share only two common stochastic trends — Johansen and the Bayesian VECM agree at r=2r=2, the spreads mean-revert as the expectations hypothesis predicts, and the front of the curve does most of the error-correcting. The forecasting lesson is don't over-difference: the VAR-in-differences is clearly worst, while the VECM and levels-VAR track together and win. (2) Fisher effect (6b): the nominal rate tests I(1) but inflation is already I(0) — cointegration is impossible, and forcing a "Fisher coefficient" gives an interval that excludes −1. A cautionary tale: the analysis is only as good as its pre-tests. (3) Money demand (6c): real M2, income and the rate are all genuinely I(1), yet Johansen cannot reject r=0r=0 — the classic equilibrium has broken down (the forced error-correction term wanders like a unit root rather than reverting), so the textbook prescription holds and the VAR-in-differences forecasts best. Across all three, the Bayesian machine supplies the full posterior of the adjustment speeds and cointegrating space where Johansen offers only a sequence of tests; each is cross-checked in R with urca.

Notebooks

Downloads

References