Free lesson · Statistical arbitrage
Construct the spread: price ratios, log ratios and executable units
Open interactive lessonPractice calculationsExplore labs
Start with the idea
A spread is a specified portfolio or statistical residual. You must distinguish a hedge measured in shares from a regression coefficient on log prices. The same numerical coefficient can imply different orders.
Symbols, units & horizon
- P_A,P_B: observed prices in currency/share
- α: fitted intercept in A-price units
- β: B shares hedging one A share for the levels model
- s_t: residual in A-price units
- i: formation observation
- bars: formation-sample averages
- Δ: exit minus entry, with β fixed
- Π: gross marked profit before dividends and financing
When and why to use this
Use a units audit when translating a residual signal into share or contract orders. It prevents a statistical hedge from being traded with the wrong exposure.
For a levels regression, model A’s price as an intercept plus β times B’s price. With both prices in the same currency per share, a unit long spread holds one A share and shorts β B shares. The intercept is part of the statistical mean, not an asset you automatically buy.
Fit the coefficient only on the formation window and freeze it over the trade, or account explicitly for rebalancing when it changes. Rolling refits alter both the residual definition and the trading book. A shrinking fitted residual does not by itself equal realised trading profit.
For a log-price regression, β is an elasticity: a local dollar exposure hedge uses B shares approximately βP_A/P_B for each A share. Currency conversion, contract multipliers and dividends require consistent economic price series. Dollar neutrality, beta neutrality and cointegration are separate properties.
Construct the spread: price ratios, log ratios and executable units
- Minimise the sum of squared residuals in α and β. The intercept condition gives α=Ā−βB̄.
- Substitute the intercept, differentiate in β and set the derivative to zero: Σ(B−B̄)(A−Ā)=βΣ(B−B̄)².
- For fixed holdings, profit is one A price change minus β B price changes. The constant intercept cancels when taking the residual difference.
B=[10,11,12], A=[21,23,25] gives β=2 and α=1. A long spread with ΔA=−1 and ΔB=−1 earns −1−2(−1)=$1 per A share before costs.
Apply it in a strategy
- Fit a levels or log specification on past data, checking corporate actions, currencies and contract multipliers.
- Store the estimated coefficient with each order decision and translate it into actual quantities.
- Reconcile spread changes against cash-and-position P&L; include every rebalance, dividend and borrow charge.
Research deliverable
Produce a hedge sheet showing statistical coefficients, actual quantities, gross/net exposure and cash P&L for a two-leg example.
Python implementation
Self-contained teaching example. Python 3.10+; dependencies and input conventions are shown in the code and notation. Run in your own Python environment.
def levels_hedge(a,b):
if len(a)!=len(b) or len(a)<2: raise ValueError("Aligned observations required")
ma,mb=sum(a)/len(a),sum(b)/len(b)
denominator=sum((x-mb)**2 for x in b)
if denominator==0: raise ValueError("Hedge price has zero variance")
beta=sum((x-mb)*(y-ma) for x,y in zip(b,a))/denominator
return ma-beta*mb,beta
def spread_pnl(delta_a,delta_b,beta): return delta_a-beta*delta_b
print(levels_hedge([21,23,25],[10,11,12]),spread_pnl(-1,-1,2))Continue learning
Statistical Arbitrage: Relative Value to Tradable Portfolios — all lessons- What statistical arbitrage is—and where it applies
- Construct the spread: price ratios, log ratios and executable units
- Cointegration, reversion speed and structural breaks
- Causal z-scores and a complete entry–exit state machine
- From pairs to residual baskets and factor neutrality
- Two-leg backtesting, borrow, capacity and ML extensions
Quantitative finance and development glossary · Python resources and libraries · Research sources and limitations