6.1.5Algorithmic & Quant Trading

Understand statistical arbitrage basics

2,278 words10 min readdifficulty · medium2 backlinks

What is Statistical Arbitrage?

The Three Pillars

WHY these matter:

  1. Pair Selection — wrong pairs = no mean reversion = losses
  2. Spread Calculation — defines entry/exit signals
  3. Position Sizing — controls risk per trade

Derivation: The Statistical Arbitrage Spread

Step 1: Define the Spread

For two assets A and B with prices PA(t)P_A(t) and PB(t)P_B(t), the spread is:

S(t)=PA(t)βPB(t)S(t) = P_A(t) - \beta \cdot P_B(t)

WHY subtract β·P_B? We want a stationary series. Raw price difference PAPBP_A - P_B trends if one grows faster. The hedge ratio β neutralizes that trend.

HOW to find β? Linear regression of PAP_A on PBP_B:

β=Cov(PA,PB)Var(PB)=(PAPˉA)(PBPˉB)(PBPˉB)2\beta = \frac{\text{Cov}(P_A, P_B)}{\text{Var}(P_B)} = \frac{\sum (P_A - \bar{P}_A)(P_B - \bar{P}_B)}{\sum (P_B - \bar{P}_B)^2}

Why this step? Minimizes variance of S(t)S(t) — makes spread oscillate around constant mean instead of drifting.

Step 2: Standardize the Spread (Z-Score)

Raw spread S(t)S(t) has arbitrary units. Convert to z-score:

z(t)=S(t)μSσSz(t) = \frac{S(t) - \mu_S}{\sigma_S}

where:

  • μS=1ni=1nS(ti)\mu_S = \frac{1}{n}\sum_{i=1}^{n} S(t_i) (mean spread over lookback window)
  • σS=1ni=1n(S(ti)μS)2\sigma_S = \sqrt{\frac{1}{n}\sum_{i=1}^{n} (S(t_i) - \mu_S)^2} (standard deviation)

WHY z-score? Dimensionless units let us set universal thresholds: "Enter when |z| > 2" works for any pair. Also measures how "extreme" current divergence is.

Why 2? Assuming normal distribution, |z| > 2 happens ~5% of time — rare enough to signal mispricing, common enough for liquidity.

Step 3: Trading Logic

Entry signals:

  • z(t)>+2z(t) > +2: Spread too high → Short A, Long B (bet spread falls)
  • z(t)<2z(t) < -2: Spread too low → Long A, Short B (bet spread rises)

Exit signals:

  • z(t)0z(t) \to 0: Close position (mean reversion complete)
  • z(t)>3|z(t)| > 3: Stop-loss (relationship may have broken)

Why this step? High |z| signals temporary dislocation. Closing at z=0 captures mean reversion profit. Stop-loss prevents holding through structural breaks.

Worked Example 1: Coca-Cola vs. Pepsi

Setup

  • Historical data: 250 trading days
  • KO prices: mean 58,σ=58, σ = 3
  • PEP prices: mean 145,σ=145, σ = 6
  • Correlation: 0.85
  • Calculate β: β=0.8536=0.425\beta = 0.85 \cdot \frac{3}{6} = 0.425

Why this step? β = ρ·(σ_A/σ_B) from regression theory. KO moves ~0.43 dollars per dollar PEP moves.

Day 251: Entry

  • KO = 62,PEP=62, PEP = 150
  • Spread: S=620.425×150=6263.75=1.75S =62 - 0.425 \times 150 = 62 - 63.75 = -1.75
  • Historical: μS=5.75\mu_S = -5.75, σS=1.5\sigma_S = 1.5
  • Z-score: z=1.75(5.75)1.5=4.01.5=+2.67z = \frac{-1.75 - (-5.75)}{1.5} = \frac{4.0}{1.5} = +2.67

Interpretation: Spread is 2.67 SD above mean (KO overpriced relative to PEP).

Action: Short 100 shares KO, Long 42.5 shares PEP (β·100 = 42.5 for dollar neutrality).

Why this step? Position sizes create equal dollar exposure: 100×62=6200100 \times 62 = 6200 vs. 42.5×150=637542.5 \times 150 = 6375 (close enough with rounding).

Day 260: Exit

  • KO = 59,PEP=59, PEP = 148
  • New spread: S=590.425×148=5962.9=3.9S = 59 - 0.425 \times 148 = 59 - 62.9 = -3.9
  • New z-score: z=3.9(5.75)1.5=1.851.5=+1.23z = \frac{-3.9 - (-5.75)}{1.5} = \frac{1.85}{1.5} = +1.23

Why exit? z dropped from 2.67 → 1.23 (substantial mean reversion). Lock in profit.

Profit calculation:

  • KO short: Sold 62,covered62, covered 59 → +$300
  • PEP long: Bought 150,sold150, sold 148 → -$85
  • Net: 30085=+300 - 85 = **+215** (before costs)

Why profitable? Spread narrowed (mean reverted) as predicted. Market-neutral: both stocks could've fallen — we'd still profit if spread converged.

Figure — Understand statistical arbitrage basics

Worked Example 2: Failed Trade (Learning Opportunity)

Setup

  • Gold miners: GDX vs. individual stock GOLD
  • Entry z = -2.5 (GOLD underpriced vs. GDX)
  • Action: Long GOLD, Short GDX

Outcome

  • Gold price crashes 15% industry-wide
  • GOLD falls 18%, GDX falls 14%
  • Spread widens further: z → -3.8
  • Stop-loss triggered at z = -3.0
  • Loss: -$450

Why did this fail?

  1. Structural break: Cointegration assumed stable relationship, but GOLD announced poor earnings
  2. Beta instability: During crashes, correlations spike toward 1 (everything falls together)
  3. Liquidity: Widening spreads in illiquid conditions

Key lesson: StatArb assumes stationarity. Check for cointegration (Engle-Granger test) and monitor news for structural changes.

Key Formulas

The Realistic Picture

Win Rate vs. Profit Factor

Typical StatArb performance:

  • Win rate: 55–65% (barely better than coin flip!)
  • Avg win: $150
  • Avg loss: $100
  • Profit factor: (0.60 × 150) / (0.40 × 100) = 2.25

Why low win rate works: Asymetric payoff. Mean reversion gives small consistent wins; stop-loss caps large losses. It's about expectancy, not accuracy.

Expectancy=(Pwin×Avg win)(Ploss×Avg loss)\text{Expectancy} = (P_{\text{win}} \times \text{Avg win}) - (P_{\text{loss}} \times \text{Avg loss})

For above: (0.6 \times 150) - (0.4 \times 100) = 90 - 40 = +\50 per trade.

Risk: The Half-Life of Mean Reversion

Half-life = time for spread to decay50% toward mean. Calculate from AR(1) model:

S(t)=ϕS(t1)+ϵ,half-life=ln(2)ln(ϕ)S(t) = \phi \cdot S(t-1) + \epsilon, \quad \text{half-life} = -\frac{\ln(2)}{\ln(\phi)}

Why it matters: Short half-life (minutes–hours) = fast profit/loss. Long half-life (weeks) = capital tied up, opportunity cost. Typical pairs trading: half-life 2–10 days.

Example: If ϕ=0.9\phi = 0.9 (90% of previous value persists), half-life = ln(2)/ln(0.9)6.6-\ln(2)/\ln(0.9) \approx 6.6 periods.

Recall Feynman Explanation (ELI12)

Imagine you have two lemonade stands across the street from each other. Usually, Stand A charges50¢ and Stand B charges 45¢ — there's a consistent 5¢ difference because Stand A has better location.

One hot day, Stand A panics and raises prices to 70¢ while Stand B stays at 45¢. Now the difference is 25¢ — way more than usual! You know customers will flock to Stand B until Stand A lowers prices or Stand B raises them.

StatArb is like: "I'll bet Stand A's price will come down." So you promise to sell someone Stand A lemonade (short) at today's high price, while buying Stand B lemonade (long) at normal price. When prices normalize back to 5¢ difference, you pocket the change.

The "statistical" part means you're betting on the pattern (5¢ difference), not guaranteed profit. Sometimes the pattern breaks (Stand A closes!), so you set a "stop-loss" — maximum loss you'll accept before admitting the pattern changed.

Connections

  • 6.1.01-Introduction-to-algorithmic-trading — StatArb is a quantitative strategy requiring algos for execution
  • 6.1.04-Mean-reversion-strategies — StatArb is the pairs-trading implementation of mean reversion
  • 6.2.03-Correlation-vs-cointegration — Critical to distinguish for pair selection
  • 6.2.05-Backtesting-trading-strategies — Must backtest for stationarity, costs, and slippage
  • 5.3.02-Beta-and-systematic-risk — β here is hedge ratio; related to CAPM β but different context
  • 7.1.03-Value-at-Risk-VaR — StatArb uses VaR for position-level risk management

#flashcards/stock-market

What is statistical arbitrage? :: A market-neutral strategy that profits from mean reversion of spreads between cointegrated asset pairs by taking simultaneous long/short positions when spread deviates >N standard deviations.

What is the hedge ratio β in pairs trading?
β = Cov(P_A, P_B) / Var(P_B), the ratio of shares of asset B to hold per share of A to eliminate directional market risk (make portfolio market-neutral).
Why use z-score instead of raw spread for entry signals?
Z-score is dimensionless and normalized, allowing universal thresholds (e.g., |z| > 2) across any pair regardless of price scale, and measures statistical extremity of divergence.
What is the key difference between correlation and cointegration?
Correlation measures co-movement (can drift apart permanently); cointegration means a linear combination of prices is stationary (mean-reverts), which is required for StatArb profitability.
How do you calculate position sizes for dollar neutrality?
Shares of B = β × Shares of A, ensuring dollar value invested in A approximately equals dollar value in B to hedge market direction.
What is half-life in mean reversion and why does it matter?
Half-life is time for spread to decay 50% toward mean (calculated as -ln(2)/ln(φ) from AR(1) model). Short half-life = fast profit/loss; long half-life = capital tied up longer.
Why can StatArb be profitable with only 55-60% win rate?
Expectancy = (P_win × Avg win) - (P_loss × Avg loss). Small consistent mean-reversion wins + stop-loss capped losses create positive expectancy even with low win rate.
What are typical entry and exit z-score thresholds?
Entry: |z| > 2 (spread is2 SD from mean); Exit: z → 0 (mean reversion) or |z| > 3 (stop-loss, possible structural break).

Concept Map

drives

is

means

requires

requires

requires

needs

defined as

uses hedge ratio

standardized to

threshold triggers

threshold triggers

captures

extreme

Mean Reversion Assumption

Statistical Arbitrage

Market-Neutral Strategy

Beta approx 0 hedged

Pair Selection

Spread Calculation

Position Sizing

Cointegration/Correlation

Spread S = PA - beta times PB

Beta from Regression

Z-Score

Entry when abs z > 2

Exit when z to 0

Convergence Profit

Stop-Loss abs z > 3

Hinglish (regional understanding)

Intuition Hinglish mein samjho

Statistical arbitrage ek smart trading technique hai jisme hum do aisi companies ke stockslete hain jo historicallyek-dusre ke sath move karte hain — jaise Coke aur Pepsi, ya Australia aur Canada ke ETFs. Jab inki price relationship temporarily bigad jati hai (matlab ek stockzyada badh gaya aur dusra peeche reh gaya), tab hum bet lagate hain ki yeh wapas normal ho jayenge.

Iska magic yeh hai ki hum "market-neutral" rehte hain —agar pora market crash bhi ho jaye, humein farak nahi padta kyunki hum simultaneously ek stock long (khareed rahe) aur dusra short (bech rahe) kar rahe hain. Hum direction pe bet nahi kar rahe, hum sirf relationship ki correction pe bet kar rahe hain. Jaise agar normally Coke 50aurPepsi50 aur Pepsi 100 rehta hai (ratio 1:2), lekin aj Coke 60aurPepsi60 aur Pepsi 100 hai, toh hum Coke ko short karenge expecting ki wapas $50 ayega.

Yeh strategy statistical hai matlab100% guaranteed nahi — kabhi-kabhi relationship permanently badal jati hai (jaise ek company bankrupt ho gayi). Isliye hum z-score use karte hain jo bata hai spread kitna "extreme" hai (2 standard deviations se zyada = rare event = trade karo). Aur stop-loss zaroor rakhte hain agar pattern toot gaya. Real institutionsisme milliseconds mein trade karte hain automated algos se, aur transaction costs ko minimize karke chhote-chhote profits repeatedly kamate hain. Retail traders ke liye challenge hai ki brokerage fees zyada hain, toh larger moves ki zaroorat padti hai profitability ke liye.

Test yourself — Algorithmic & Quant Trading

Connections