DeskPrep
PYTHONadvanced~75 min

Pairs Trading & Cointegration

Estimate a hedge ratio, test the spread for stationarity and half-life, then backtest a z-score strategy honestly with costs and an out-of-sample split.

The scenario

A stat-arb pod hands you two price series and asks whether they can be traded as a mean-reverting pair. Estimate the hedge ratio, test the spread for stationarity, measure its half-life, then build and honestly backtest a z-score mean-reversion strategy with costs and an out-of-sample split.

Where this shows up

Testing a pair for cointegration and backtesting a mean-reversion signal is a classic statistical-arbitrage take-home at firms of this type.

statistical arbitragesystematic hedge fundsquant research

Firms such as Two Sigma, Citadel, Man Group.

DeskPrep is not affiliated with, endorsed by, or sponsored by any named firm. Firm names are used for illustrative, educational purposes only and do not imply that these materials are official assessments of, or are connected with, those firms.

Task brief

README.md
# Pairs Trading & Cointegration

**Role relevance:** Quant research / statistical arbitrage take-home
**Estimated time:** 75 minutes
**Difficulty:** Advanced
**Format:** Jupyter notebook (.ipynb)

## What you are given
- pairs_trading_starter.ipynb - a guided notebook that runs end to end even before you fill it in
- prices.csv - 750 business days of two price series
- Validation targets in the final cell, so you can grade your own work

## What you must deliver
1. The hedge ratio, fitted on the in-sample window only
2. An ADF stationarity test and the spread's half-life
3. A causal z-score signal with the position lagged one day
4. A cost-aware backtest reporting in-sample and out-of-sample separately, plus a written verdict

## Constraints & assumptions
The hedge ratio is fitted on the first 500 rows only. The z-score must be rolling, not full-sample. Positions must be lagged before they earn PnL. Costs are 5bp on turnover.

## Submission note
Complete the starter file, then compare your work against the mark scheme.

Your tasks

  1. 01Estimate the hedge ratio by regressing one series on the other and form the spread.
  2. 02Test the spread for stationarity (ADF) and estimate its half-life of mean reversion.
  3. 03Build a z-score strategy: enter when the spread is beyond an entry threshold, exit near zero, with no lookahead.
  4. 04Backtest with transaction costs and an in-sample / out-of-sample split, and report the Sharpe and whether the edge survives.

How you're assessed

Hedge ratio and spread construction2 pts
Stationarity test and half-life2 pts
Lookahead-free z-score signal to PnL3 pts
Cost-aware in/out-of-sample evaluation2 pts
Clean, readable code1 pt
Total10 pts

The full points-based mark scheme is included with the pack.

What you'll learn

  • The difference between correlation and cointegration, and why a pair needs the latter.
  • How the half-life sets a sensible holding period and z-thresholds.
  • Why costs and an out-of-sample split separate a real pair from an overfit.

Study alongside