Correlation isn’t cointegration, and pairs-trading interviews test it

Updated · techinterview.org

An interviewer pulls up two price series, say Coca-Cola and Pepsi, and asks how you would trade them. The wrong first move is to compute a correlation, see 0.92, and start describing a spread. Correlated prices can still drift apart forever. What a pairs trade needs is cointegration: a linear combination of the two prices that stays stationary, so that when the gap widens it gets pulled back.

This distinction is the most common trap in a statistical arbitrage interview, and getting it right early tells the interviewer you have actually run one of these strategies rather than read about it. Correlation measures whether two assets move together over short windows. It says nothing about whether the distance between their prices is bounded. Two stocks can post 0.95 return correlation while their price ratio grinds steadily apart, which is a reliable way to lose money holding a spread you assumed would revert. Cointegration is the property you want: even if each price is a random walk, some weighted difference of them is mean-reverting.

Building the spread and testing it

The standard construction is the Engle-Granger two-step method. Regress one price on the other with ordinary least squares, take the slope as your hedge ratio, and form the residual as the spread. Written out, Price_A = α + β · Price_B + ε. The β is how many shares of B you hold against one share of A, and ε is the series you trade.

Then you test whether ε is stationary with an augmented Dickey-Fuller test. If the residual is stationary, the two prices are cointegrated and the spread mean-reverts. One detail separates careful candidates here: because β was estimated from the same data, you cannot use the textbook ADF critical values. You use the cointegrating ADF (CADF) values, which are more demanding, because the regression has already fit the residual toward zero and a plain test would call too many pairs cointegrated.

A good interviewer will also ask which stock goes on the left-hand side. Regressing A on B gives a different β than regressing B on A, and the inverse of one is not the other, so the spread you trade depends on the choice. Some desks sidestep this with total-least-squares or by picking the regressand that yields the more stationary residual, and saying that out loud is worth points.

A follow-up that catches people: the hedge ratio is not fixed. The relationship between two stocks drifts as their businesses and valuations change, so a β estimated once on a training window slowly goes stale. The common upgrade is a rolling regression, and the answer interviewers are fishing for at the research level is a Kalman filter, which treats β as a hidden state that updates every day as new prices arrive. It adds parameters to tune and a fresh way to overfit, so it is a tool to reach for with a reason, not by default.

How long the reversion takes

A stationary spread is only tradable if it reverts on a timescale you can hold. The half-life of mean reversion answers that. Model the spread as an Ornstein-Uhlenbeck process, or equivalently fit an AR(1): regress the daily change in the spread on the previous day’s level. The slope λ is negative for a mean-reverting series, and the half-life is −ln(2)/λ. A two-day half-life and a sixty-day half-life are completely different businesses, one needing fast turnover and tight costs, the other tying up capital and exposing you to the relationship breaking while you wait.

import numpy as np, statsmodels.api as sm

# hedge ratio from OLS: price_a ~ price_b
beta = sm.OLS(price_a, sm.add_constant(price_b)).fit().params[1]
spread = price_a - beta * price_b

# half-life from an AR(1) fit on the spread
lag   = spread.shift(1).dropna()
delta = spread.diff().dropna()
lam   = sm.OLS(delta, sm.add_constant(lag.loc[delta.index])).fit().params[1]
half_life = -np.log(2) / lam

Entry and exit usually run off the spread’s z-score, meaning how many standard deviations it sits from its mean. A common rule enters when the z-score passes ±2, scales toward zero as the spread reverts, and stops out past ±3 or ±4 on the theory that a spread that far out has probably broken rather than stretched. The naive version computes the mean and standard deviation over the whole sample, which quietly leaks future information into past trades. Rolling windows fix that, and the window length should track the half-life you measured.

When they push past two assets

Engle-Granger handles one relationship between two series. Ask it to price a basket of three or more and it gets awkward, since the answer depends on which asset you normalize against. The Johansen test is the multivariate answer. It works inside a vector error correction model and tells you how many independent cointegrating vectors exist among the assets, handing you the weights directly. The cost is that it is more sensitive to lag-length choice and far easier to overfit, so a candidate who reaches for Johansen on every problem is signaling the opposite of what they mean to.

Method What it tests Assets it handles Main limitation
Correlation / distance Short-term co-movement of returns or normalized prices 2 Says nothing about whether the price gap stays bounded
Engle-Granger (CADF) Stationarity of the OLS residual between two prices 2 Result depends on which asset is the regressand; one relationship only
Johansen Number of cointegrating vectors in a vector error correction model 2 or more Sensitive to lag choice and easy to overfit
Phillips-Ouliaris Residual-based cointegration, less sensitive to serial correlation 2 Still a single-equation test

The backtest questions that actually decide the round

Once you can build a spread, the interview shifts to why your clean backtest is lying to you. Look-ahead bias is the first suspect: estimating the hedge ratio, the mean, or the standard deviation on data that includes the day you are trading. Fit those on a training window and trade forward only.

In-sample cointegration is subtler and more dangerous. Scan enough pairs and many will pass an ADF test on historical data purely by chance, then come apart the moment you trade them. If you test 500 stocks pairwise you are running roughly 125,000 tests, and a 5% false-positive rate alone hands you thousands of spurious pairs. A holdout period and a correction for multiple testing are the real defenses. Survivorship bias compounds it: pick today’s index members and you have already excluded every pair that blew up and got delisted.

Then there is the part that kills money rather than backtests. Statistical arbitrage margins are thin, so a strategy that looks strong gross can die once you add commissions, the bid-ask spread you cross on both legs, and the borrow cost on the short. And the relationship itself is not permanent. A merger, an index reconstitution, or a shift in one company’s business can break a cointegrating relationship for good, and a mean-reversion rule will keep adding to the position as it moves against you, right up until the stop. The classic index-constituent pairs trade decayed through the 2010s for exactly this reason, as more capital crowded the same signals and the edge compressed.

Questions phrased the way they are actually asked

  • “Two stocks have 0.95 return correlation. Is that enough to pairs-trade them, and if not, what would you check?”
  • “Walk me through deciding whether a spread is mean-reverting and how fast it reverts.”
  • “Does it matter which stock you regress on to get the hedge ratio?”
  • “Your backtested Sharpe is 3. Talk me through why you would distrust it.”
  • “How do you set the entry threshold and the holding period?”

These come up in quant researcher and quant trader rounds at firms like Two Sigma, D.E. Shaw, Cubist, and the systematic pods inside the multi-manager funds, usually mixed with a probability question and a coding screen. The people who do well treat the cointegration test as the easy part. They spend their air time on what happens when the spread stops reverting, because that is the risk that shows up on the desk, and an interviewer who trades this for a living can tell the difference in about two minutes.

newsletter

What's actually being asked right now

Interview patterns & comp trends, straight to your inbox.

No spam. Unsubscribe anytime.

newsletter

What's actually being asked right now

Interview patterns & comp trends, straight to your inbox.

No spam. Unsubscribe anytime.

1972 Soviet postage stamp commemorating the Mars 2 probe

worth a read

Mars For The Rest of Us — a weekly-or-more deep dive on the technical side of Mars exploration: rocket propulsion, microbiology, mission architecture, and everything in between. Written by Maciej Ceglowski.

Read it on Substack →
Scroll to Top