Statistical Arbitrage
Pairs and baskets on NSE stocks, honestly: data and biases, the short leg in India, stationarity, correlation vs cointegration, Engle-Granger, multiple testing, spreads and z-scores, Kalman hedges, Johansen, factor-neutral books, sizing, validation and implementation.
00Statistical arbitrage: atlas and routes
A brutally honest course on trading relationships between NSE stocks: what stat arb is, building and auditing the data, stationarity and cointegration, building a pair and watching it break, Kalman hedges, Johansen baskets, factor-neutral books, risk and sizing, validation and real implementation. Condensed from OpenAlgo's free Open Varsity course. Educational, not investment advice.
Statistical arbitrage topic atlas#
How to use this sheet#
- Start with the honest scorecard and the funnel: they set expectations for everything else.
- Building a pair: stationarity → correlation vs cointegration → Engle–Granger → finding pairs → spread and signal.
- Before believing any result: the reality check and the validation battery.
- Before any order: the short-leg card, implementation, and the nine gates at the end.
The honest scorecard#
| Technique | Headline | Honest verdict |
|---|---|---|
| Naive pair HDFCBANK / KOTAKBANK | In-sample net Sharpe 1.01 | Out-of-sample net 0.34 |
| Kalman dynamic hedge | "Adaptive" | OOS −1.50 vs static +0.76 |
| Johansen 5-bank basket | 94% of sub-baskets stationary in-sample | 0% out of sample |
| Cross-sectional factor-neutral | Gross Sharpe 1.34 | Net −1.99 (≈ 235× turnover) |
| Six vol-targeted pairs | Net Sharpe 0.94 | OOS 0.43: the best survivor |
Most candidates die between "they move together" and "net, out-of-sample, implementable". The best survivor is marginal: small allocation, kill switch, close monitoring.
Check yourself 2 questions
The naive HDFC Bank / Kotak pair: in-sample versus out-of-sample net Sharpe?
Show answer
About 1.0 in sample, about 0.3 out of sample.
Which technique looked strong gross but was negative net, and why?
Show answer
The cross-sectional factor-neutral book: gross Sharpe about 1.3, net about −2, because turnover was enormous.
Takeaway Most stat arb ideas die between 'they move together' and 'net, out of sample'; the best survivor was a small, vol-targeted book of pairs.
From relationship to edge#
flowchart TD C["Correlation: thousands of pairs"] --> I["In-sample cointegration: far fewer"] I --> O["Out-of-sample stability: fewer still"] O --> N["Net of realistic costs: very few"] N --> E["Implementable in India: a handful, if any"]
Each layer removes apparent edge. What survives the whole funnel is the honest estimate, and zero survivors is a legitimate result.
Check yourself 2 questions
List the funnel's stages in order.
Show answer
Correlation, in-sample cointegration, out-of-sample stability, net of realistic costs, implementable in India.
Is ending with zero tradable pairs a failure?
Show answer
No. Zero survivors is a legitimate, honest result.
Takeaway Correlation → in-sample cointegration → out-of-sample stability → net of costs → implementable; each layer removes edge, and zero survivors is a valid result.
01Foundations and honesty
OpenAlgo Open Varsity · Statistical Arbitrage · chapters 1–4 (what stat arb is, the database, data biases, research vs real markets)
What statistical arbitrage really is#
- Classic arbitrage: same cash flow, two prices, no risk. Stat arb has no guarantee, only a statistical tether. "Trade a stationary relationship, not a price."
- BAJFINANCE vs BAJAJFINSV, 2,473 days: return correlation 0.824, β 1.153, yet spread ADF p = 0.199 (random walk not rejected) and half-life 104 days. Rolling correlation ranged 0.71–0.92.
- Dollar-neutral (+1 / −1) leaves net beta +0.09 here; beta-neutral sizes the short at βA/βB ≈ 1.06× for net beta ≈ 0. Neutrality drifts and re-hedging costs money.
Check yourself 2 questions
How is the spread defined for a pair?
Show answer
log A minus (alpha plus beta times log B), with beta from a regression.
Bajaj Finance and Bajaj Finserv had 0.82 return correlation. Why not a pair?
Show answer
Their spread failed the stationarity test (ADF p about 0.2) with a 104-day half-life: correlated, but not reliably mean-reverting.
Takeaway Stat arb trades a stationary spread, not a price; high correlation alone doesn't make a spread revert.
The family tree, and where the edge went#
| Form | Trades |
|---|---|
| Single-name reversion | A stock vs its own average (fragile) |
| Pairs | Two stocks, one hedge ratio |
| Baskets | A cointegrated weighted group |
| Cross-sectional, factor-neutral | A whole universe ranked, market and sector hedged |
- The edge came from providing liquidity, slow news diffusion and structural flows (rebalances, redemptions, tax selling); early quant desks harvested it in the late 1980s–1990s.
- It decayed with faster data, crowded cointegration screens, ETFs and market makers. August 2007's "quant quake" was crowded books unwinding into each other.
- In India, shorting beyond a day isn't free: stock futures, SLB borrow or intraday square-off, each with its own costs, margin and availability, on both legs, both ways.
Check yourself 2 questions
Where did the original stat arb edge come from?
Show answer
Providing liquidity, slow news diffusion and structural flows such as rebalances, redemptions and tax selling.
Why did it decay?
Show answer
Faster data, crowded cointegration screens, ETFs and more competition.
Takeaway From single-name reversion to pairs, baskets and factor-neutral books; the old edge decayed as data got faster and screens got crowded.
Building the historical database#
- Download once, store locally, read the cache every run, verify before trusting. Universe: the 50 Nifty stocks (NSE) plus NIFTY (NSE_INDEX) as the trading calendar, tagged into 14 sectors.
- Ten years of daily bars:
source="db"54.7 ms vssource="api"346 ms (≈ 6.3×), and the cache returns identical bytes each run while vendor history can be revised. - DuckDB tables:
market_data(symbol, exchange, interval, epoch-second timestamp) anddata_catalog(first/last date, rows, last download). - Verify: rows per symbol (≈ 2,477 for full history), start dates for young listings or renames, stale series (> 7 days behind), and internal gaps against the NIFTY calendar (10 of 50 names were perfectly clean; worst missed 3 sessions). One missing bar on a leg fakes a spread move.
- Nightly top-up: fetch after each symbol's last date, re-fetch the last few weeks for revisions, upsert on symbol + date, back off on timeouts and HTTP 429s.
Check yourself 2 questions
Why read history from a local cache instead of the API each run?
Show answer
It's several times faster and reproducible: vendor history can be revised, the cache can't.
What serves as the trading calendar for the Nifty 50 universe?
Show answer
The NIFTY index series itself.
Takeaway Download once, store locally, read the cache every run and verify it; a local cache is faster and gives the same bytes every time.
The data layer and its biases#
| Name | Years of history |
|---|---|
| JIOFIN | 2.8 |
| ETERNAL | 4.9 |
| MAXHEALTH | 5.8 |
| HDFCLIFE / SBILIFE | 8.6 / 8.7 |
| Most others | ≈ 10.5 |
- A rectangular panel (3,195 days × 50 names) is capped by its youngest listing: pairing with JIOFIN leaves ≈ 700 days, about one regime, which is weak evidence.
- Liquidity (365-day close × volume): even the thinnest names trade ₹160–200 crore a day, so the filter ranks cost rather than feasibility. A pair is only as liquid as its thinner leg.
- Adjusted closes are right for measuring relationships; fills happen at raw prices, and hedge ratios can go stale after an ex-date.
- Name your biases: survivorship (delisted and dropped names missing), symbol changes (demergers stitched into one series), and no point-in-time index membership. Blind
dropna()silently favours old large caps.
Check yourself 2 questions
Why is pairing with a recently listed stock weak evidence?
Show answer
Its short history covers only about one regime, leaving few days to test.
What limits a pair's liquidity?
Show answer
Its thinner leg.
Takeaway A rectangular panel is capped by its youngest listing, adjusted closes aren't tradable prices, and a pair is only as liquid as its thinner leg.
Research vs real markets: the short leg decides#
| Short vehicle | How long | Costs and catches |
|---|---|---|
| Intraday cash (MIS) | Same day only | Auto square-off near 15:20; full round trip every day |
| SLB borrow | Days to weeks | Annual borrow fee, thin patchy supply, recall mid-trade |
| Stock futures | Overnight default | Basis, monthly roll, fixed lots, margin, F&O ban; hedge fitted on cash but traded in futures adds tracking error |
| Synthetic (options) | To expiry | Greeks and assignment; rarely worth it for linear spreads |
- Backtests silently assume you can stay short as long as reversion takes, both legs fill at the measured close, and holding is free. In India all three are false.
- Liquidity spans ≈ 15× (HDFCBANK ≈ ₹2,479 crore a day vs TATACONSUM ≈ ₹164 crore; median ≈ ₹399 crore). Futures margin runs ≈ ⅕ to ⅓ of notional per leg; bans (OI ≥ 95% of MWPL) and price bands can freeze a leg and leave naked direction; stock futures held to expiry settle physically.
- Choose the short vehicle first: it sets the cost. Learn on closes; never assume you can trade at them.
Check yourself 2 questions
Why can't a multi-day pair use an intraday cash short?
Show answer
Intraday shorts must be squared off the same day, near 3:20 pm.
Name two catches of shorting via stock futures.
Show answer
Any two of: basis, a monthly roll, fixed lot sizes, margin, the F&O ban, tracking error versus a cash-fitted hedge.
Takeaway The short leg decides what's tradable: intraday-only cash shorts, scarce SLB borrow, or futures with basis, rolls, lots and bans.
02Stationarity, correlation and cointegration
OpenAlgo Open Varsity · Statistical Arbitrage · chapters 5–7 (stationarity, correlation is not cointegration, cointegration mechanics)
Random walks vs stationary series#
- Across 400 simulated paths, random-walk variance reached 391.9 by step 399 and kept growing; AR(1) with φ = 0.85 settled at 3.56 (theory 3.60). Bounded variance is the anchor you trade.
- RELIANCE, 2,477 days: log-price mean jumps 6.27 → 7.16 between halves (non-stationary); returns stay stable. Volatility clustering is not non-stationarity, but it matters for sizing.
- Prices are I(1), returns I(0); stat arb manufactures an I(0) spread and trades that.
Check yourself 2 questions
What happens to a random walk's variance over time?
Show answer
It keeps growing in proportion to time.
How do you turn a non-stationary price series into a stationary one?
Show answer
Take log returns (differences of log prices).
Takeaway A random walk's variance grows without bound; a stationary series settles, and that bounded variance is what you trade.
ADF, KPSS and Hurst#
| RELIANCE | ADF (H0: unit root) | KPSS (H0: stationary) |
|---|---|---|
| Log price | −2.234 vs 10% CV −2.567: can't reject | 7.216 vs 1% CV 0.739: reject |
| Returns | −15.241 vs 1% CV −3.433: reject | 0.317 vs 5% CV 0.463: can't reject |
- The two tests have opposite nulls: agreement is a strong verdict; disagreement means re-specify (trend, breaks). Fix ADF's regression form (c, ct, n) and lag rule before running.
- Power trap: a truly stationary AR(1) with φ = 0.99 is detected only ≈ 61% of the time. "Failed to reject" often means too little data.
- Hurst: ≈ 0.5 random walk, < 0.5 mean-reverting, > 0.5 trending. 14 NSE names ranged 0.46–0.56: no stock is a convincing mean-reverter. One clue only.
- Across 24 names, 100% of price series kept a unit root and 100% of return series rejected it.
Check yourself 2 questions
What are the null hypotheses of ADF and KPSS?
Show answer
ADF: a unit root (non-stationary). KPSS: stationary.
What's the power trap with ADF?
Show answer
A truly stationary but very persistent series (phi about 0.99) is detected only about 61% of the time.
Takeaway ADF and KPSS have opposite null hypotheses; agreement is a strong verdict, disagreement means re-specify.
Correlation is not cointegration#
| Pair (NSE 2016–2026) | Return correlation | Engle–Granger p | Verdict |
|---|---|---|---|
| TATASTEEL / JSWSTEEL | 0.76 (highest) | 0.204 | Not cointegrated |
| KOTAKBANK / HDFCBANK | 0.60 | 0.001 | Cointegrated |
| MARUTI / M&M | 0.53 | 0.000 | Cointegrated |
- Correlation (on returns) is same-day co-movement, useful for hedge stability. Cointegration (on log levels) asks whether the hedged spread keeps returning, which is what a pairs trade needs.
- 75 same-sector pairs → 11 cointegrated; 0 of 4 cross-sector "fake" pairs. Rank correlation between return correlation and cointegration p: −0.04, essentially none.
- Spurious regression: 3,000 pairs of independent random walks gave |t| > 1.96 in 90.1% of runs (should be 5%), median |t| 10.0. High R² on price levels means nothing.
- Verdicts are window-specific: INFY/HCLTECH p 0.007 in the first half, 0.861 in the second. Screen on cointegration first, use correlation as a secondary filter, rank on half-life and cost, confirm out of sample, and correct for the number of pairs tested.
Main card for cointegration. Also covered in Quant trading · Algo trading · this sheet.
Check yourself 2 questions
Tata Steel and JSW Steel had the highest correlation. Were they cointegrated?
Show answer
No (Engle-Granger p about 0.2); correlation and cointegration are different questions.
Which one does a pairs trade actually need?
Show answer
Cointegration: a spread that keeps returning.
Takeaway Correlation measures same-day co-movement of returns; cointegration asks whether the hedged spread of levels keeps returning.
Engle–Granger mechanics on HDFCBANK vs KOTAKBANK#
| Hedge-ratio convention (log prices, 2019–2023) | β |
|---|---|
| OLS A on B (used for the spread) | 1.0545 |
| OLS B on A, flipped | 1.2724 (20.7% higher) |
| Total least squares (symmetric) | 1.1751 |
- Step 1: OLS of log A on log B gives β and the residual spread. Step 2: test the spread. The pair passed with
cointp = 0.0306 (t −3.521 vs 5% critical −3.341); the runner-up HDFCBANK–SBIN failed at 0.096. - Report the honest p: a plain ADF on the residual says 0.0075, but β was estimated, so Engle–Granger's 0.0306 is the number. The hedge ratio is an estimate with a convention, not a fact (errors in both legs bias OLS).
- Spread sd 0.0698 log units, 59 mean crossings, near-symmetric tails. ≈ 2.4% of a gap closes per day.
- Half-life mirage: test stationarity first. A random walk can print a 280-day "half-life"; a near-unit-root drift 64 days with ADF p 0.106. A rolling 120-day β swung −0.31 to 1.30 (range 258% of its mean): a fixed in-sample β can drift out of bands.
Main card on cointegration: this sheet → Also in Quant trading · Algo trading.
Check yourself 2 questions
Why aren't the two OLS slopes reciprocals of each other?
Show answer
Their product equals R squared, so flipping the regression gives a different beta (here about 21% higher).
How is the half-life computed?
Show answer
Regress the spread's change on its lagged level; half-life = ln 2 divided by minus the slope (about 29 days here).
Takeaway Step one regresses log A on log B for beta; step two tests the residual spread; the half-life comes from regressing the spread's change on its lag.
03Building a pair, then breaking it
OpenAlgo Open Varsity · Statistical Arbitrage · chapters 8–10 (finding pairs, spread and signal, the brutal reality check)
Finding pairs without fooling yourself#
| Funnel step | Pairs |
|---|---|
| Blind scan of 50 names, C(50, 2) | 1,225 (≈ 61 chance "winners" at p < 0.05) |
| Same-sector economic prior | 78 (≈ 4 chance winners) |
| Enough history | 73 |
| Naive p < 0.05 in-sample (2018–2023) | 16 |
| After Benjamini–Hochberg (p ≤ 0.0048) | 7 |
| After Bonferroni (p < 0.05 / 73 = 0.00068) | 1 |
| Confirmed out of sample (2024 →) | 0 |
- 6,000 simulated random-walk pairs gave a 5.25% false-positive rate: the test is honest; the danger is how many times you run it.
- "Choosing what not to test is the cheapest risk control in the field." Fix window, universe, sector map, history minimum, correction and split before looking, and report the whole funnel. Zero survivors is a legitimate result.
Check yourself 2 questions
Scanning 1,225 pairs at p < 0.05, about how many chance winners do you expect?
Show answer
About 61.
What did Bonferroni and out-of-sample confirmation leave?
Show answer
One pair after Bonferroni, and zero confirmed out of sample.
Takeaway Testing many pairs manufactures false winners; use an economic prior, correct for multiple tests, and confirm out of sample.
The spread and the signal#
| Rule (HDFCBANK vs KOTAKBANK) | Setting |
|---|---|
| Spread | log A − 1.0545 · log B |
| z-score window | Trailing, sized to the half-life (29 days) |
| Short spread | z between +2 and +3.5 |
| Long spread | z between −3.5 and −2 |
| Exit | |z| < 0.5 |
| Hard stop | |z| > 3.5; flat, no re-entry until back inside |
| Fill | Signal at close t, trade at close t + 1: one .shift(1) |
Robust z = (spread − rolling median) ÷ (1.4826 × MAD) handles gaps. In-sample, gross: +98% total, Sharpe 0.99, 40 round trips, 72.5% wins, ≈ 14-day holds, no stops hit. Fitted on the same data, gross of ≈ 28 bps a round trip, frozen β, equal-rupee legs, an abstract short: "a beautiful in-sample curve is a warning, not evidence".
Check yourself 2 questions
When is the spread shorted?
Show answer
When z is between +2 and +3.5.
Why fill at the next close instead of the signal close?
Show answer
To avoid look-ahead bias: you can't trade at the price that generated the signal.
Takeaway Enter at |z| between 2 and 3.5, exit below 0.5, stop above 3.5, and trade the next bar to avoid look-ahead.
The brutal reality check#
| View (frozen β 1.0545, 60-day z, CNC costs 0.474% a round trip) | Sharpe | Total |
|---|---|---|
| In-sample gross | 1.14 | +134.2% |
| In-sample net | 1.01 | +110.5% |
| Out-of-sample gross | 0.46 | +17.5% |
| Out-of-sample net (2024 →, 2.5 years) | 0.34 | +11.5% (max drawdown −13.8%) |
| Walk-forward, quarterly refit | 0.62 | +22.3% |
- Leak 1, out of sample: about two-thirds of the edge vanished.
- Leak 2, costs: 8 fills a round trip, dominated by delivery STT (0.1% on both the buy and the sell); 33 trips × 0.474% = 15.9% of capital. Out-of-sample net Sharpe hits zero near a 1.9% round-trip cost.
- Leak 3, de-cointegration: rolling 252-day p ranged 0.005–0.978 (latest 0.734) and failed the 5% test in ≈ 90% of windows; the frozen β was ≈ 63% above the test-period average, leaving directional risk.
- Leak 4, look-ahead and survivorship: full-sample z normalisation inflated OOS Sharpe 0.34 → 1.12; same-bar fills flip +135% into −64%; this pair was the best of 10 bank pairs, and 5 of the 10 lost money net out of sample.
Check yourself 2 questions
What was the out-of-sample net Sharpe of the naive pair?
Show answer
About 0.34, against about 1.0 in sample.
Why are delivery round trips so expensive for a pair?
Show answer
Eight fills per round trip, with delivery STT of 0.1% on both the buy and the sell.
Takeaway Out of sample, about two-thirds of the edge vanished, and delivery costs on four legs ate much of the rest.
04Doing it properly: dynamic hedges, baskets, books and risk
OpenAlgo Open Varsity · Statistical Arbitrage · chapters 11–14 (Kalman hedge ratios, baskets and Johansen, cross-sectional factor-neutral, risk, sizing and portfolio)
Kalman filter hedge ratios#
| HDFCBANK on KOTAKBANK, net | IS Sharpe | OOS Sharpe | Trades |
|---|---|---|---|
| Static β | +1.12 | +0.76 | 41 |
| Kalman β | −0.53 | −1.50 | 78 |
Kalman β was smooth (0.64–1.07, never negative) while rolling OLS swung −0.31 to +1.74 and went negative on 7.5% of days, yet the static β won the trade test; 0 of 20 Q × R settings beat it out of sample. "Adaptivity is not free": every re-hedge pays costs on both legs, and the free intercept can absorb the very mispricing you want. Freeze δ and R on in-sample data before any out-of-sample look.
Check yourself 2 questions
Static beta versus Kalman beta out of sample: which won?
Show answer
Static beta (about +0.8 Sharpe) against Kalman (about −1.5).
In the Kalman setup, which parameters actually matter?
Show answer
Only the ratio of the state noise Q to the observation noise R.
Takeaway A smooth, adaptive Kalman beta lost to a simple static beta out of sample; adaptivity can just mean more trades and more noise.
Baskets and the Johansen test#
- A basket has 3–5 legs and k − 1 free weights: pooled reversion, but more estimation error and cost (≈ 69 bps a round trip for five legs vs ≈ 28 for a pair intraday).
- Johansen fits a VECM on log levels and finds the cointegration rank r: eigenvectors are the basket weights. Trace tests rank ≤ r stepwise; max-eigenvalue tests r vs r + 1. Fix det_order and lags in advance.
- Five banks, 2019–2023: trace said r = 1 (75.18 > 69.82, then 45.56 < 47.85); max-eigen said r = 0. Pre-declare which rule wins.
- Weights with HDFCBANK at +1: ICICI −0.166, KOTAK −0.518, AXIS −0.115, SBIN −0.017; spread ADF p 0.0005, half-life 23.7 days (optimistic: fitted on the same data).
- Split at mid-2021 and three of four weights flipped sign (SBIN −0.80 → +8.56); bootstrap noise exceeded the weights themselves. Out of sample the same vector's p went 0.0005 → 0.558; 16 sub-baskets were 94% stationary in-sample and 0% after. Use the fewest legs, never trade the in-sample winner.
Check yourself 2 questions
What does the Johansen test estimate?
Show answer
The cointegration rank of a group; its eigenvectors are the basket weights.
Roughly how much more does a five-leg basket cost per round trip than a pair intraday?
Show answer
About 69 bps versus about 28 bps.
Takeaway Johansen finds cointegrated baskets, but more legs mean more estimation error and cost; the 5-bank basket failed out of sample.
Cross-sectional, factor-neutral books#
- Removing market cuts a median 31% of daily variance; market plus sector 61%. The book trades the remaining third. Sector averages are only known at the close, so act next bar.
- Top-minus-bottom decile +3.89 bps a day gross; gross Sharpe 0.51 (market-only) and 1.34 (market + sector); realised book beta ≈ 0.006.
- But turnover ≈ 235× a year: gross edge ≈ 2.48 bps a day vs cost ≈ 6.45 → net Sharpe −1.99. Breakeven is 2.66 bps a side vs realistic 6.9 (MIS) or 11.9 (CNC). Slowing the signal (k = 15) cut losses to −0.16 but never crossed zero.
- Real capacity needs hundreds of names and a dependable short side; crowded unwinds can flip reversal into momentum (2007).
Check yourself 2 questions
How much daily variance do market plus sector remove?
Show answer
About 61% at the median.
Why was the factor-neutral book negative net?
Show answer
Turnover was so high that costs overwhelmed a small daily edge.
Takeaway Strip out market and sector, trade the residual reversal across the universe; the gross edge was real but turnover destroyed it net.
Risk, sizing and portfolio construction#
| Pair (2019–23) | EG p |
|---|---|
| M&M / MARUTI | 0.0015 |
| INFY / TCS | 0.0017 |
| TCS / HCLTECH | 0.0217 |
| HDFCBANK / KOTAKBANK | 0.0306 |
| TATASTEEL / JSWSTEEL | 0.0356 |
| HINDALCO / TATASTEEL | 0.0686 |
- Six pairs (half-life 5–60 days) vs one: OOS Sharpe 0.43 vs 0.34, max drawdown −10.0% vs −13.8%. Shared legs (TCS, TATASTEEL) mean fewer independent bets than it looks.
- Vol targeting (leverage = target vol ÷ own vol, 8% per pair, 10% book, frozen on train) lifted Sharpe 1.10 → 1.34; cap any pair at 35%; risk parity gives each 1/6 of risk. Ledoit–Wolf shrinkage buys stability, not correctness; correlations near 0.04 can jump toward 1 in a crisis.
- Rupee-neutral is not beta-neutral: pair beta = β_A − hedge × β_B (M&M/MARUTI −1.11). A NIFTY futures overlay can trim residual beta.
- Stops cut both ways: a |z| > 3 stop lost 6.4% in two days on a trade that reverted to +21.4%. A −5% drawdown throttle cut max drawdown to −8.6% but Sharpe to 0.76.
- Retire a pair after 3 rolling readings with p > 0.10; re-admit after 3 with p < 0.05. Retirement always lags the break: median live pairs were 0 of 6.
Check yourself 2 questions
Six pairs versus one: what changed out of sample?
Show answer
Sharpe rose (about 0.43 versus 0.34) and max drawdown shrank (about −10% versus −14%).
How is vol-targeted leverage set?
Show answer
Target volatility divided by the pair's own volatility, frozen on the training data.
Takeaway Several pairs beat one, vol targeting helps, but shared legs mean fewer independent bets than it looks.
05Research to reality: validation and implementation
OpenAlgo Open Varsity · Statistical Arbitrage · chapters 15–17 (honest validation, implementation pathways, capstone and checklist)
The validation battery#
| Layer | Result (HDFCBANK / KOTAKBANK) |
|---|---|
| Single in-sample backtest | Net Sharpe 1.01 |
| Walk-forward, anchored (14 folds of 126 days) | Median 0.47; 93% of folds positive; worst −0.96 |
| Walk-forward, rolling | Median 0.57; 86% positive; best +3.07 |
| Purged + embargoed CV (holding period 39 days) | 0.78 → 0.50: 55% inflation removed |
| Deflated Sharpe (64 trials) | PSR vs 0 = 1.000; DSR = 0.962 |
| Probability of backtest overfitting (CSCV, 8 blocks) | 54%: selection adds little |
| Block bootstrap (20-day blocks, 3,000 resamples) | OOS 0.34, 95% CI [−0.47, 1.15]; ≈ 20% chance the true Sharpe is below 0 |
| Stability sweep | Base 0.82; 3 × 3 neighbourhood 0.79 (sd 0.08); 96% of cells positive |
- Shuffled k-fold leaks because trade labels overlap in time: 100% of test days leak; contiguous blocks 16.6%; purging ±holding period plus an embargo, 0%.
- A ridge (thin spike) dies when a setting is nudged; a plateau is robust but can still be low: 90-day z → OOS 0.99, 60 or 120 → 0.34, tighter stop → 0.19, doubled costs → 0.22.
- Run the battery once on a pre-fixed hypothesis; validators can be overfit too, and the true number of trials is always larger than the ones you wrote down. Here the surviving edge is thin and statistically indistinguishable from zero.
Check yourself 2 questions
What did purged, embargoed cross-validation do to the Sharpe?
Show answer
Cut it from about 0.78 to 0.50, removing about 55% inflation.
What does the deflated Sharpe ratio correct for?
Show answer
The number of trials run: more attempts make a high Sharpe more likely by chance.
Takeaway Walk-forward, purged cross-validation, deflated Sharpe and overfitting probability shrink a single backtest's shine to an honest estimate.
Implementation pathways#
| Route | Cost pattern | Watch-outs |
|---|---|---|
| Cash intraday | A full round trip daily | Square off near 15:20 |
| SLB borrow | One round trip + borrow (≈ 3% a year used) | Lumpy, recallable, can spike to double digits |
| Stock futures | One round trip + roll every ≈ 30 days | Basis wobble, lot rounding, dividends |
- Holding period picks the vehicle: multi-day holds need futures or SLB; daily re-crossing overtakes futures cost after ≈ 1 day.
- Intraday cost stack: effective spread ≈ 5.3 bps (Corwin–Schultz on liquid large caps; daily high-low overstates it ≈ 33×), legged entries median 7.8 bps (p95 16.2), square-root impact 8–26 bps at 1–10% participation → a round-trip hurdle ≈ 123 bps against a per-trade edge of 30–50 bps.
- Legging: with 95% per-leg fill odds, ≈ 9.5% of entries leave a naked leg (≈ 18% at 90%); that tail outweighs slippage.
- Kill-switch gates, any one flattens: |z| beyond the hard limit (4.8 in the sample), drawdown stop, broken leg (flatten the survivor now), thin margin or F&O ban, stale data, square-off clock. Retire decayed pairs (return correlation below 0.5 in 48% of history here) rather than averaging down. Rehearse in OpenAlgo's analyzer first.
Check yourself 2 questions
Which route suits multi-day holds?
Show answer
Stock futures or SLB borrow.
What's the main catch of SLB borrowing?
Show answer
Lumpy, recallable supply, and a fee that can spike to double digits.
Takeaway The holding period picks the vehicle: intraday cash for same-day, SLB or futures for multi-day, each with its own cost pattern.
Should this pair go live?#
Check yourself 2 questions
A pair passes in sample but has a negative out-of-sample net Sharpe. Verdict?
Show answer
Drop it: the in-sample shine was fitting the past.
What if you can't short one leg?
Show answer
It's not implementable; the short leg decides the trade.
Takeaway Go live only after multiple-test-corrected cointegration, positive out-of-sample net Sharpe, a shortable leg and an edge that clears costs.
06Checklists and quick reference
A "no" at any gate sends the idea back to research.
The nine-gate pre-trade checklist#
- Liquidity: can both legs absorb your size without moving price?
- Borrow / short access: SLB or a liquid future, at a known cost?
- F&O eligibility and bans: on the list today and not in an MWPL ban, checked before every entry.
- Net costs: every charge, spread and impact on two legs, both ways; the edge must clear them.
- Fills and legging: next-bar fills, partials, broken-leg risk.
- Capital and margin: margin on both legs, daily MTM, a gap-day buffer.
- Monitoring: spread, z-score, exposure, P&L and broken-leg alerts.
- Kill switch: the flatten rule defined before you need it.
- Tax and entity: futures and cash are taxed differently; model after tax.
Check yourself 2 questions
Name three of the nine gates.
Show answer
Any three of: liquidity, borrow or short access, F&O eligibility and bans, net costs, fills and legging, capital and margin, monitoring, kill rules, records.
Why check the ban list before every entry?
Show answer
A stock in an MWPL ban can't take fresh positions, which breaks the short leg.
Takeaway Liquidity, borrow, F&O eligibility and bans, net costs, fills, margin, monitoring, kill rules, and records all have to pass.
Formulas to keep#
Check yourself 2 questions
Robust z-score formula?
Show answer
(spread minus rolling median) divided by (1.4826 times the MAD).
Bonferroni threshold for m tests at significance alpha?
Show answer
p < alpha divided by m.
Takeaway Spread, half-life, z-score and robust z, beta-neutral sizing, multiple-test corrections and the fair-future formula.
About this sheet#
This sheet condenses the free 17-chapter course Statistical Arbitrage from OpenAlgo Open Varsity (4 modules) into reference cards in our own words. Every number is from the course's own NSE research on adjusted daily closes (mostly 2016–2026) with its stated cost models, and its biases (survivorship, adjusted vs tradable prices) apply here too. Each section links back to its chapters. Educational, not investment advice.
Numbers that expire#
Every figure on this sheet that a regulator, exchange or budget can change, with when it last changed. Last checked 15 Nov 2026; verify before trading.
| What | Current value | As of |
|---|---|---|
| STT | delivery 0.1% both sides · intraday 0.025% sell · futures 0.05% sell · options 0.15% of premium sold, 0.15% of intrinsic on exercise | from 1 Apr 2026 (Budget 2026) · source |