# Pairs Trading Stack

Also known as: spread construction, hedge ratio, half-life/Ornstein-Uhlenbeck.
A Statistics concept (Relationships) in the LuxAlgo Library.

## What is a Pairs Trading Stack?

The pairs trading stack is the chain of statistical steps that turns two related instruments into one tradable spread. Candidates are screened for economic linkage and [correlation](https://www.luxalgo.com/library/concept/correlation/); a hedge ratio is estimated by [linear regression](https://www.luxalgo.com/library/concept/linear-regression/), or recursively with a Kalman filter so it can drift; and the spread is built as one leg minus hedge ratio times the other. The spread is then tested for cointegration, stationarity of the combination even though each leg wanders, and its reversion is modeled, classically as an Ornstein-Uhlenbeck process whose estimated reversion speed converts to a half-life: the time in which the expected deviation decays halfway back.

Each layer has a traceable origin. Pairs trading as a desk practice is usually credited to Gerry Bamberger and later Nunzio Tartaglia's quantitative group at Morgan Stanley in the 1980s. Cointegration, the idea that individually wandering series can share a stationary combination, was formalized by Robert Engle and Clive Granger in 1987, and Granger's share of the 2003 Nobel prize cited that work. The Ornstein-Uhlenbeck process is older still, a 1930 physics model of mean-reverting motion that quantitative finance adopted for spreads. Academic work by Gatev, Goetzmann, and Rouwenhorst later documented the strategy's historical returns, and follow-up studies found the simplest versions eroding as the approach became widely known.

Trading reduces to standardized deviations: enter when the spread's [z-score](https://www.luxalgo.com/library/concept/z-score/) stretches beyond a band, exit near the mean, stop out if the relationship has genuinely broken. That last clause defines the risk. Cointegration is a property of a sample, not a law; hedge ratios drift, half-lives lengthen, and a spread that tested stationary can trend further than a position can survive.

The stack matters because each layer answers a different question. Co-movement screens ask whether the legs travel together at all; the hedge ratio asks in what proportion; stationarity tests ask whether deviations actually get pulled back; the half-life asks whether the pull is fast enough to trade. Skipping a layer produces familiar accidents: high correlation between two trending assets says nothing about their spread, and a beautiful in-sample spread with a nine-month half-life is a position, not a strategy. Checking the [autocorrelation](https://www.luxalgo.com/library/concept/autocorrelation/) of spread changes and [profiling the distribution](https://www.luxalgo.com/library/concept/distribution-of-returns-profiling/) of spread returns rounds out the diagnosis before capital is committed.

## How to build a pairs spread on a chart

Most platforms can chart a spread or ratio directly, which makes the stack inspectable step by step:

1. Chart both legs and confirm an economic reason they should travel together: shared sector, shared inputs, index membership, or a dual listing. Statistical resemblance alone is a weak foundation.
2. Estimate the hedge ratio by regressing one leg's log prices on the other over a training window, then plot the spread: leg A minus beta times leg B.
3. Inspect the spread for stationarity: it should oscillate around a stable level rather than trend, and formal tests (ADF or similar) firm up what the eye suggests.
4. Standardize with a rolling z-score and mark the bands you would trade, commonly near plus and minus two with exits around zero; conventions vary.
5. Fit the reversion and read off the half-life; if it is longer than your intended holding period, the pair fails the audition regardless of how clean the spread looks.

## How it's calculated

The standard mean-reversion pipeline for two related instruments: hedge ratio, spread, z-score, and half-life.

```
1. Estimate the hedge ratio: regress ln(A_t) on ln(B_t) by least squares over the last n bars; the slope is beta.
2. S_t = ln(A_t) - beta × ln(B_t)
3. z_t = (S_t - mean_m(S)) / stdev_m(S)
4. Estimate mean reversion: regress S_t - S_(t-1) on S_(t-1) by least squares over the same window; the slope is b.
5. HalfLife = -ln(2) / b, defined when b < 0

  A_t: price of the first asset (the dependent leg) at bar t
  B_t: price of the second asset (the hedge leg) at bar t
  t: bar index
  ln: natural logarithm
  n: estimation window for the regressions, in bars (commonly 60 to 252)
  beta: hedge ratio, the units of B exposure held against each unit of A
  S_t: spread at bar t
  m: z-score lookback in bars (often set equal to n)
  mean_m(S): mean of the spread over the last m bars
  stdev_m(S): standard deviation of the spread over the last m bars
  z_t: spread z-score at bar t
  b: slope of the mean-reversion regression, negative when the spread mean-reverts
  HalfLife: expected number of bars for the spread to close half its distance to the mean
```

Step 4 is the discrete form of fitting an Ornstein-Uhlenbeck process to the spread, and the same regression underlies the (Augmented) Dickey-Fuller cointegration check on the pair.

Common variants keep the regression intercept inside the spread, use raw instead of log prices, or track beta with a rolling window or Kalman filter since hedge ratios drift.

If b is not negative the spread shows no mean reversion in the sample and the half-life is undefined.

## How traders use it

- To generate entries and exits: z-score bands on the spread define stretch (enter) and fair value (exit), a mean-reversion loop that repeats for as long as the relationship holds.
- To size and time positions from the half-life: a short half-life supports quick round trips, while a half-life of months ties up capital in a slow, uncertain reversion that many traders simply skip.
- To monitor health: hedge ratios are re-estimated on a rolling or recursive basis, and the pair is retired when cointegration tests stop passing.
- To stress the position before it exists: simulating spread paths, in the spirit of [Monte Carlo price paths](https://www.luxalgo.com/library/concept/monte-carlo-price-paths/), shows the adverse excursions a mean-reverting fit still permits and sizes the stop accordingly.
- To rank candidates across a universe: pairs are scored by half-life, spread volatility, and test stability, often via [percentile rank](https://www.luxalgo.com/library/concept/percentile-rank/) across the candidate list, and the book rotates toward pairs whose statistics have stayed consistent.

## Pairs Trading Stack vs its ingredients

- **Correlation** (https://www.luxalgo.com/library/concept/correlation/): Correlation measures short-horizon co-movement of returns; the stack needs a stationary long-run combination of prices, which correlation neither implies nor requires. Two trending assets can be highly correlated while their spread wanders off forever.
- **Z-score** (https://www.luxalgo.com/library/concept/z-score/): The z-score is only the trigger layer: it grades stretch on whatever series it is given. Applied to a spread that was never stationary, the same bands that look like discipline systematically buy a diverging relationship.
- **Linear Regression** (https://www.luxalgo.com/library/concept/linear-regression/): Regression supplies one number, the hedge ratio, from one sample. The stack wraps it in verification: stationarity tests, reversion modeling, and re-estimation, because a fitted beta is a snapshot of a relationship that moves.

## FAQ

### What is a hedge ratio in pairs trading?

The number of units of the second instrument held against one unit of the first so the combined position isolates the spread rather than either leg's direction. It is usually estimated by regressing one price series on the other, or updated bar by bar with a Kalman filter. A stale hedge ratio leaves directional exposure the strategy was designed to remove.

### What does half-life mean for a spread?

The time in which the expected deviation shrinks to half its size, derived by fitting the spread to an Ornstein-Uhlenbeck mean-reversion model: half-life equals the natural log of 2 divided by the estimated reversion speed. Traders use it to set holding periods and judge viability. It is a backward-looking estimate, and it lengthens when the relationship weakens.

### What is the difference between correlation and cointegration?

Correlation describes how returns move together over short horizons; cointegration says a specific combination of the price levels is stationary, so deviations get pulled back. Neither implies the other. Pairs trading needs the second property, because it profits from the pull, not from the co-movement.

### What z-score levels do pairs traders use for entries?

Around two standard deviations for entry and near zero for exit is the textbook convention, sometimes with a stop at three or four. Spread distributions are usually heavier-tailed than normal, so the numbers are calibration points rather than probabilities; some desks set bands from the spread's own historical percentiles instead.

### Does pairs trading still work?

Published evidence says the simplest distance-based versions became much less profitable after the 1990s as the idea spread, while practitioners argue refined versions with better universes, dynamic hedging, and faster execution retain an edge. What is uncontested is the risk profile: many small reversion wins punctuated by occasional large losses when a relationship structurally breaks.

## Related concepts

- Correlation: https://www.luxalgo.com/library/concept/correlation/
- Beta: https://www.luxalgo.com/library/concept/beta/
- Alpha: https://www.luxalgo.com/library/concept/alpha/
- Autocorrelation: https://www.luxalgo.com/library/concept/autocorrelation/
- Lead-lag Detection: https://www.luxalgo.com/library/concept/lead-lag-detection/
- Cointegration: https://www.luxalgo.com/library/concept/cointegration/
- Stationarity & Efficiency Tests: https://www.luxalgo.com/library/concept/stationarity-and-efficiency-tests/

---

Source: https://www.luxalgo.com/library/concept/pairs-trading-stack/ (LuxAlgo Library, the encyclopedia of trading & technical analysis). Free to use with attribution: https://www.luxalgo.com/library/license/