Free lesson · Statistical arbitrage
From pairs to residual baskets and factor neutrality
Open interactive lessonPractice calculationsExplore labs
Start with the idea
Basket statistical arbitrage removes shared risk from a group of assets, then trades the remaining cross-sectional information. Neutrality is always relative to a selected exposure model; it does not remove every source of loss.
Symbols, units & horizon
- a: raw score vector across n assets
- B: n×k exposure matrix, with full column rank
- w: projected score or unscaled weight vector
- T: transpose
- inverse: defined when factor columns are independent
- A column of ones: dollar-neutral constraint
- Final weights: separately scaled to stated capital convention
When and why to use this
Use projections to understand factor-neutral score construction, then enforce realistic portfolio constraints jointly when turning scores into orders.
Build a point-in-time universe and estimate exposures to market, sectors or statistical factors using the formation window. A PCA factor is a statistical direction of variation; it need not have a stable economic interpretation. Training a representation on the full future panel contaminates residual research.
Project a candidate score away from the selected factor exposures, then scale positions to gross, volatility and liquidity limits. Neutrality constraints can conflict with long-only, borrow or concentration constraints, requiring a constrained optimiser rather than post-hoc clipping.
Pairs share names and factors. Summing independently attractive pair trades may produce a concentrated short in one hard-to-borrow stock. Net at the instrument level before estimating portfolio risk and execution requirements. Model delistings and changing index membership using what was known then.
From pairs to residual baskets and factor neutrality
- Seek the closest vector to a of the form w=a−Bλ while requiring Bᵀw=0.
- Substitute to get Bᵀa−BᵀBλ=0, so λ=(BᵀB)⁻¹Bᵀa.
- Substitute λ back. With only a constant exposure, this subtracts the cross-sectional mean. In code, solve or use a documented least-squares projection rather than form an inverse.
Scores [2,0,−1] have mean 1/3. Removing a constant factor gives [5/3,−1/3,−4/3], whose sum is zero. Normalising by gross 10/3 yields weights [.5,−.1,−.4].
Apply it in a strategy
- Estimate factors and exposures without future information and distinguish economic factors from PCA components.
- Neutralise the score, inspect lost signal and exposure concentration, then solve for feasible instrument weights.
- Audit netted-name exposures, liquidity and borrowing across all pair and basket sleeves.
Research deliverable
Produce a before/after exposure report and compare neutralised versus raw signals at matched gross and risk budgets.
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.
import numpy as np
def neutral_scores(scores,exposures):
a=np.asarray(scores,dtype=float)
b=np.asarray(exposures,dtype=float)
if b.ndim!=2 or b.shape[0]!=len(a): raise ValueError("Exposure rows must match assets")
residual=a-b@np.linalg.lstsq(b,a,rcond=None)[0]
gross=np.abs(residual).sum()
return residual if gross==0 else residual/gross
print(neutral_scores([2,0,-1],[[1],[1],[1]]))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