Phase 12 - Lesson 12.6

Cointegration, VAR, and Backtest Pitfalls

Modeling several series together, the long-run equilibrium of cointegrated pairs, and the research-integrity traps that turn great backtests into losing strategies.

⏱ 60 min● Advanced🔗 Prereqs: 12.1-12.5, 11.7
↖ Phase 12 hub
Builds on: Unit roots (12.1), VAR generalizes AR (12.2), and 11.7's leakage lessons return with teeth.
Leads to: These pitfalls govern every strategy in Phases 14-18; this is the capstone of quant-research discipline.

Learning Objectives

Click a status chip to cycle: Not started → In progress → Studied → Practiced → Needs review → Mastered.

Key Vocabulary

VAR(\(p\)
Vector autoregression: \(x_t=c+\sum_{i=1}^p \Phi_i x_{t-i}+\varepsilon_t\) for a vector \(x_t\) of series.
Cointegration
Two or more \(I(1)\) series whose linear combination is \(I(0)\) (stationary): a shared stochastic trend / long-run equilibrium.
Error-correction model
A representation where changes respond to the lagged equilibrium error: \(\Delta y_t=\alpha(y_{t-1}-\beta x_{t-1})+\dots\).
Spurious regression
A high-\(R^2\), significant-looking regression between independent \(I(1)\) series - an artifact of common trends, not a real relationship.
Look-ahead bias
Using information not available at decision time; the most common way backtests cheat.
Backtest overfitting
Selecting a strategy from many trials so its performance is largely luck; apparent Sharpe inflated by the search.
Regime change / structural break
A shift in the data-generating process (policy, liquidity, crisis) that breaks a previously fitted relationship.

Intuition & Motivation

Intuition
One series was Phase 12 so far; markets give us many at once. A VAR lets each series depend on the recent past of all the others - the natural multivariate generalization of AR. But the most useful multivariate idea is cointegration: two prices can each wander (each is \(I(1)\), non-stationary) yet be tied together so that a particular combination - a spread - is stationary and mean-reverting. That tether is the mathematical backbone of pairs trading and relative-value strategies: trade the spread, not the levels.

The other half of this lesson is a warning. Cointegration is easy to fake: two unrelated trending series will show a gorgeous, highly significant regression - a spurious regression - that means nothing. And even a real edge is trivially destroyed in a backtest by using tomorrow’s data today (look-ahead bias), by trying a thousand variants and reporting the winner (backtest overfitting), or by assuming the world does not change (regime shifts). Getting the statistics right is necessary; getting the research process right is what actually protects your capital.

Vector autoregression (VAR)

Stack \(d\) series into \(x_t\in\R^d\). A VAR(\(p\)) is \(x_t=c+\Phi_1 x_{t-1}+\dots+\Phi_p x_{t-p}+\varepsilon_t\) with \(\varepsilon_t\) vector white noise. It is stationary iff all roots of \(\det(I-\Phi_1 z-\dots-\Phi_p z^p)=0\) lie outside the unit circle. VARs are estimated equation-by-equation by OLS and used for multivariate forecasting, impulse-response analysis, and Granger-causality tests - but they need stationary inputs.

Cointegration and error correction

If each component of \(x_t\) is \(I(1)\) but there exists a vector \(\beta\) with \(\beta^\top x_t\) stationary (\(I(0)\)), the series are cointegrated: they share a common stochastic trend and cannot drift arbitrarily far apart. Granger's representation theorem says such a system has an error-correction form:

\[\Delta y_t=\gamma+\alpha\,(y_{t-1}-\beta x_{t-1})+\sum_i \phi_i \Delta y_{t-i}+\sum_j \theta_j \Delta x_{t-j}+\varepsilon_t,\] (12.7)

where \((y_{t-1}-\beta x_{t-1})\) is the lagged equilibrium error (the spread) and \(\alpha\lt 0\) is the speed of adjustment pulling the system back. Test for it with Engle-Granger (regress, then unit-root-test the residual spread) or Johansen (a systems test allowing several cointegrating vectors). This is the engine of statistical-arbitrage pairs trading: the spread is your tradable, mean-reverting signal.

Spurious regression: the trap that looks like a discovery

Regress one independent random walk on another. Because both trend, OLS reports a large \(R^2\) and a \(t\)-statistic that looks wildly significant - yet there is no relationship. The classical inference is invalid because the residuals are themselves \(I(1)\) (non-stationary), violating Gauss-Markov. The tell: a very high \(R^2\) with a Durbin-Watson near 0 (hugely autocorrelated residuals). Genuine cointegration requires the residual spread to be stationary; that is the test that separates a real tether from a coincidence of trends.

Worked Example - Engle-Granger test for a cointegrated pair
1
Confirm each leg is \(I(1)\): an ADF test fails to reject a unit root on \(y_t\) and \(x_t\) (both wander).
2
Estimate the long-run relation by OLS: \(y_t=a+\beta x_t+u_t\); the fitted \(\hat\beta\) is the hedge ratio and \(\hat u_t=y_t-a-\hat\beta x_t\) the spread.
3
Unit-root-test the residual spread \(\hat u_t\) (ADF, with cointegration-adjusted critical values). Rejecting the unit root means \(\hat u_t\) is \(I(0)\) - genuine cointegration.
4
If instead \(\hat u_t\) is itself \(I(1)\) (fails to reject), the high \(R^2\) was a spurious regression, not a tradable equilibrium - do not trade it.
5
Caveat: estimating \(\beta\) on the whole sample and then trading the in-sample spread is look-ahead bias; re-estimate on a rolling backward window for any live signal.

The backtest pitfalls, made explicit

Look-ahead bias
Any use of data unavailable at the decision instant: estimating a cointegration vector \(\beta\) on the full sample and then ‘trading’ the in-sample spread; using a smoothed (not filtered) state (12.5); aligning fundamentals to reference rather than publication dates; filling a signal with a same-bar close. Rule: at time \(t\) use only information dated \(\le t\), and estimate parameters on a rolling/expanding window that ends at \(t\).
Backtest overfitting (multiple testing)
Search enough strategies and one will look brilliant by chance. With \(N\) independent zero-alpha trials over \(T\) years, the best apparent Sharpe is \(\approx\sqrt{2\log N}/\sqrt{T}\) (recall 11.7): \(N=1000,\ T=10\) gives \(\approx1.2\) purely from luck. Defenses: track the trial count and report a deflated Sharpe ratio; pre-register the hypothesis; hold out an untouched out-of-time set; and prefer economically-motivated signals over data-mined ones.
Regime change / structural breaks
A cointegration or predictive relationship fitted in one regime (say, pre-2008 liquidity) can vanish or invert after a policy shift, crisis, or crowding. In-sample stability is no guarantee. Guard with rolling re-estimation, break tests (Chow/CUSUM), out-of-time validation across different regimes, and position sizing that survives the relationship breaking.
Key Idea
The three defenses that matter most: (1) fit everything on a strictly backward-looking window (no look-ahead); (2) count your trials and deflate performance (no overfitting); (3) validate across regimes and re-estimate as you go (no false permanence). A backtest without these is marketing, not evidence.

Interactive: spurious regression between two random walks

Common Mistakes to Avoid
  • Running a VAR or regression on non-stationary levels and trusting the \(t\)-stats - spurious significance; difference or model in error-correction form.
  • Estimating the cointegration vector \(\beta\) on the whole sample, then backtesting the in-sample spread - look-ahead bias.
  • Reporting the best of many pairs/strategies with no trial-count adjustment - overfit Sharpe (eq. 11.17).
  • Assuming a cointegrating relationship is permanent - pairs de-cohere after mergers, index changes, and regime shifts.
  • Backtesting on a survivorship-biased universe or with same-bar execution - both silently manufacture returns (11.7).
Quant Practitioner Tips
  • Confirm each leg is \(I(1)\) and the spread is \(I(0)\) before calling it cointegration; a stationary residual is the whole test.
  • Estimate \(\beta\) and signals on a rolling window that ends strictly at the decision time; re-estimate as new data arrive.
  • Report deflated Sharpe / trial count, keep an untouched out-of-time set, and prefer signals with an economic rationale.
  • Stress-test across regimes and add break tests; size positions so a broken relationship is survivable, not fatal.
  • Trade the spread, not the levels - and put a stop on the spread in case the cointegration itself breaks.

Knowledge Check

Q1 Medium
Two \(I(1)\) series are cointegrated if:
Both have unit roots
Some linear combination of them is stationary (\(I(0)\)
They are positively correlated
Their VAR is stationary in levels
Q2 Medium
A regression of one independent random walk on another typically shows:
Low \(R^2\) and an insignificant slope
High \(R^2\) and a significant-looking slope despite no real relationship
Stationary residuals
A negative \(R^2\)
Q3 Medium
You estimate a pair's hedge ratio on the full history, then backtest trading the resulting spread over that same history. This is:
A valid out-of-sample test
Look-ahead bias: the ratio used future data relative to early trades
Regime change
Survivorship bias

Practical Exercise

You build a stat-arb pairs strategy: pick the 5 best-cointegrated pairs from 500 stocks over 2005-2015, estimate each hedge ratio on the full window, trade the spreads, and report a backtest Sharpe of 3.0. (a) Identify every pitfall. (b) Explain each mechanism. (c) Redesign the study honestly and state what an honest Sharpe estimate would require.

▶ Show full solution

(a) Look-ahead bias (full-window hedge ratios), backtest overfitting / multiple testing (5 best of \(\binom{500}{2}\approx125{,}000\) candidate pairs), survivorship bias (a fixed 2005-2015 universe of names that existed throughout), and regime risk (one decade, no out-of-regime test).

(b) Full-window \(\beta\) leaks future price relationships into early trades; screening ~125,000 pairs and keeping the top 5 is an extreme maximum-over-noise, so the reported Sharpe is dominated by luck (the \(\sqrt{2\log N}/\sqrt T\) inflation is huge here); a survivorship universe drops delisted/merged names, and cointegration often breaks because of the merger you excluded; a single regime hides fragility to structural breaks.

(c) Use a point-in-time, delisting-inclusive universe; select pairs and estimate hedge ratios on a rolling in-sample window and trade only the subsequent out-of-sample window (walk-forward, with purge/embargo); reserve a final untouched out-of-time period (e.g. 2016 onward) never used in selection; report the number of pairs screened and a deflated Sharpe ratio; and add break tests plus spread stop-losses. The honest number is whatever survives on the untouched out-of-time data after deflation - likely far below 3.0, and that lower figure is the one to trust or trade.

After the reveal, answer for yourself: Every extra pair you screen, every full-sample parameter, every excluded delisting nudges the backtest Sharpe up and the live Sharpe down. The discipline is to make those two numbers converge.

Lesson Summary

A VAR generalizes AR to several series and must be run on stationary inputs. Cointegration - when non-stationary \(I(1)\) series share a stationary combination - gives a mean-reverting spread and an error-correction representation, the basis of pairs trading; but a spurious regression between independent random walks mimics it, so the residual spread must be tested for stationarity. The lesson's core is research integrity: look-ahead bias, backtest overfitting (apparent Sharpe \(\approx\sqrt{2\log N}/\sqrt T\)), and regime change each turn a great backtest into a losing strategy unless defended by backward-looking estimation, trial-count deflation, and cross-regime out-of-time validation.

Formula Sheet Additions

Error-correction model
\[\Delta y_t=\alpha(y_{t-1}-\beta x_{t-1})+\dots\]
Changes respond to the lagged equilibrium error; \(\alpha\lt 0\) pulls back.
Overfit Sharpe
\[\E[\max_i \widehat{SR}_i]\approx\sqrt{2\log N}/\sqrt T\]
Best of \(N\) trials from luck alone; deflate by \(N\).
Error Log Checklist
  • Did I confirm each leg is \(I(1)\) and the spread \(I(0)\) (real cointegration, not spurious)?
  • Is every parameter estimated on a strictly backward-looking window (no look-ahead)?
  • Did I count trials and report a deflated Sharpe, with an untouched out-of-time set?
  • Did I test across regimes and add break tests / spread stops?
  • Is the universe point-in-time and delisting-inclusive (no survivorship)?

Retrieval Practice

Close the lesson and answer from memory before checking. This is deliberate, effortful recall - the single highest-yield study action.

▶ Show retrieval prompts & answers
Q: Define cointegration and its tradable consequence.
A: Non-stationary \(I(1)\) series with a stationary linear combination \(\beta^\top x_t\) (a common trend); the stationary spread mean-reverts and is the pairs-trade signal.
Q: How do you tell a spurious regression from genuine cointegration?
A: Spurious: high \(R^2\) but \(I(1)\) (non-stationary) residuals and near-zero Durbin-Watson. Cointegration: the residual spread is stationary \(I(0)\) (Engle-Granger/Johansen).
Q: Name the three core backtest defenses.
A: Backward-looking (no look-ahead) estimation; trial-count deflation of Sharpe (no overfitting); cross-regime out-of-time validation with re-estimation (no false permanence).

Flashcards

Click to flip. These feed the site-wide spaced-repetition queue.

Cointegration
Individually \(I(1)\) series with a stationary combination \(\beta^\top x_t\); mean-reverting spread; error-correction form.
Spurious regression
High \(R^2\)/\(t\)-stat between independent \(I(1)\) series with \(I(1)\) residuals; test the spread for stationarity.
Backtest defenses
No look-ahead (backward windows), deflate for trials, validate across regimes; apparent best-of-\(N\) Sharpe \(\approx\sqrt{2\log N}/\sqrt T\).

Completion Checklist

Confidence / mastery rating
Personal notes

Source References

This lesson synthesizes and paraphrases concepts from the sources below. No copyrighted text, problem sets, or solutions are reproduced. Return to the originals for full depth.