Markets: A Rigorous Course

4.6 Selection bias and multiple testing

Core about 35 min

Motivation

Researchers do not run one backtest. They run hundreds: parameter grids, universes, filters, exits. The best result is then reported. The best of many noisy estimates is biased upward, and the bias can be computed. This section computes it, gives three ways to control error rates across many tests, and describes two tools (White's Reality Check and the probability of backtest overfitting) that work directly on the set of backtests.

Reading guide

4.6.1–4.6.3 (the expected maximum Sharpe ratio of NN noise trials and the deflated Sharpe ratio) and the research protocol of 4.6.7 are for every reader; the playbooks and C2 use them. The proofs in 4.6.4 (Bonferroni, Holm, Benjamini–Hochberg), White's Reality Check (4.6.5) and the CSCV construction of the probability of backtest overfitting (4.6.6) are advanced and can be skipped on a first reading.

4.6.1The problem in one line#

If you test mm independent rules with no edge at level α=5%\alpha=5\%, the probability of at least one false "discovery" is 1−0.95m1-0.95^m: 40% for m=10m=10, 87% for m=40m=40, 99.4% for m=100m=100.

4.6.2The expected maximum Sharpe ratio of noise#

Proposition 4.13expected maximum of NN Gaussians

Let Z1,…,ZNZ_1,\dots,Z_N be iid N(0,1)N(0,1) and MN=max⁡iZiM_N=\max_iZ_i. Then (MN−aN)/bN(M_N-a_N)/b_N converges in distribution to the standard Gumbel law G(y)=exp⁡(−e−y)G(y)=\exp(-e^{-y}), where aN=Φ−1(1−1/N)a_N=\Phi^{-1}(1-1/N) and bN=Φ−1(1−1/(Ne))−aNb_N=\Phi^{-1}(1-1/(Ne))-a_N. Hence

E[MN]≈(1−γ) Φ−1 ⁣(1−1N)+γ Φ−1 ⁣(1−1Ne),(4.17)\mathbb E[M_N]\approx(1-\gamma)\,\Phi^{-1}\!\Big(1-\frac1N\Big)+\gamma\,\Phi^{-1}\!\Big(1-\frac1{Ne}\Big), \tag{4.17}

where γ≈0.5772\gamma\approx0.5772 is the Euler–Mascheroni constant. For NN trial Sharpe ratios that are iid N(Sˉ,V)N(\bar S,V), E[max⁡S^]≈Sˉ+V E[MN]\mathbb E[\max\hat S]\approx\bar S+\sqrt V\,\mathbb E[M_N].

Proofsketch at the level of Leadbetter, Lindgren and Rootzén, 1983, Ch. 1

First, P(MN≤x)=Φ(x)NP(M_N\le x)=\Phi(x)^N. Choose aNa_N with N(1−Φ(aN))=1N(1-\Phi(a_N))=1. The normal tail satisfies 1−Φ(x)∼ϕ(x)/x1-\Phi(x)\sim\phi(x)/x as x→∞x\to\infty (Mills' ratio), so for fixed yy and b=1/aNb=1/a_N,

1−Φ(aN+by)1−Φ(aN)∼ϕ(aN+y/aN)ϕ(aN)=exp⁡ ⁣(−y−y22aN2)→e−y.\frac{1-\Phi(a_N+by)}{1-\Phi(a_N)}\sim\frac{\phi(a_N+y/a_N)}{\phi(a_N)}=\exp\!\Big(-y-\frac{y^2}{2a_N^2}\Big)\to e^{-y}.

Hence N(1−Φ(aN+bNy))→e−yN(1-\Phi(a_N+b_Ny))\to e^{-y} and P(MN≤aN+bNy)=(1−e−y+o(1)N)N→exp⁡(−e−y)P(M_N\le a_N+b_Ny)=\big(1-\tfrac{e^{-y}+o(1)}{N}\big)^N\to\exp(-e^{-y}). Any bNb_N asymptotically equivalent to 1/aN1/a_N gives the same limit. The choice bN=Φ−1(1−1/(Ne))−aNb_N=\Phi^{-1}(1-1/(Ne))-a_N makes the approximation exact at y=1y=1, since then N(1−Φ(aN+bN))=e−1N(1-\Phi(a_N+b_N))=e^{-1}; by the same Mills-ratio argument it is ∼1/aN\sim1/a_N. The mean of the standard Gumbel law is γ\gamma: with u=e−yu=e^{-y},

∫−∞∞y dG(y)=∫0∞(−ln⁡u) e−u du=−Γ′(1)=γ.\int_{-\infty}^{\infty}y\,dG(y)=\int_0^\infty(-\ln u)\,e^{-u}\,du=-\Gamma'(1)=\gamma.

So E[MN]≈aN+γbN=(1−γ)aN+γΦ−1(1−1/(Ne))\mathbb E[M_N]\approx a_N+\gamma b_N=(1-\gamma)a_N+\gamma\Phi^{-1}(1-1/(Ne)). (Convergence of the mean, not only of the distribution, follows from uniform integrability of (MN−aN)/bN(M_N-a_N)/b_N, which holds for Gaussian tails.)∎

The right-hand side of (4.17) is a pure number: E[max⁡S^]\mathbb E[\max\hat S] in units of the cross-trial standard deviation V\sqrt V of the Sharpe estimates. With V=1V=1, (4.17) gives 1.574598 for N=10N=10, 2.530603 for N=100N=100 and 3.255122 for N=1000N=1000, and the module's code reproduces these values from (4.17) directly. The Gumbel approximation slightly overstates the exact mean ∫xNϕ(x)Φ(x)N−1dx\int xN\phi(x)\Phi(x)^{N-1}dx:

NN Gumbel approximation (4.17) Exact E[MN]\mathbb E[M_N]
2 0.5198 0.5642 (=1/π=1/\sqrt\pi)
10 1.5746 1.5388
100 2.5306 2.5076
1000 3.2551 3.2414

For N=2N=2 the approximation is poor; it is designed for large NN.

From units to Sharpe ratios Under the null that no trial has skill, each per-period S^\hat S has standard deviation ≈1/T\approx1/\sqrt T by (4.13). So V=1/T\sqrt V=1/\sqrt T per period and q/T\sqrt{q/T} annualised.

Worked example 4.7

You try 100 variants of a breakout rule on five years of daily data (T=1260T=1260), and none has any edge. The annualised standard deviation of each Sharpe estimate is 252/1260=0.447\sqrt{252/1260}=0.447. The expected best annualised Sharpe ratio is 0.447×2.531=1.130.447\times2.531=1.13. With three years of data it is 1.46, and with 1,000 variants over three years it is 1.88. An annualised Sharpe ratio of 1.5 from the best of a few hundred backtests is what pure noise produces.

4.6.3The deflated Sharpe ratio#

Bailey and López de Prado (2014) replace the benchmark S∗S^* in the PSR by the expected maximum under the null:

DSR=PSR(S0),S0=V[(1−γ)Φ−1 ⁣(1−1N)+γΦ−1 ⁣(1−1Ne)],(4.18)\mathrm{DSR}=\mathrm{PSR}(S_0),\qquad S_0=\sqrt{V}\left[(1-\gamma)\Phi^{-1}\!\Big(1-\frac1N\Big)+\gamma\Phi^{-1}\!\Big(1-\frac1{Ne}\Big)\right], \tag{4.18}

where NN is the number of independent trials and VV the variance of the Sharpe estimates across trials. In practice NN is estimated by clustering correlated trials (strategies that differ only slightly are not independent), and VV is the sample variance of the trial Sharpe ratios.

Worked example 4.8

The best of N=100N=100 trials shows an annualised Sharpe ratio of 1.5 over five years of daily data, with γ^3=−0.5\hat\gamma_3=-0.5, γ^4=6\hat\gamma_4=6. Per day S^=0.0945\hat S=0.0945. Take V=1/TV=1/T, so S0=2.531/1260=0.0713S_0=2.531/\sqrt{1260}=0.0713 per day (1.13 annualised). The variance factor is 1+0.5×0.0945+54×0.09452=1.05841+0.5\times0.0945+\frac54\times0.0945^2=1.0584. Then

DSR=Φ ⁣((0.0945−0.0713)12591.0584)=Φ(0.800)=0.788.\mathrm{DSR}=\Phi\!\left(\frac{(0.0945-0.0713)\sqrt{1259}}{\sqrt{1.0584}}\right)=\Phi(0.800)=0.788.

The undeflated PSR(0)\mathrm{PSR}(0) is 0.9994. After deflation, the probability that the true Sharpe ratio exceeds what selection alone would produce is 0.79, below the usual 0.95 bar. With N=1000N=1000 the DSR falls to 0.54; with N=10N=10 it is 0.96. The number of trials you admit to is the most important input in the calculation.

4.6.4Family-wise error and false discovery rate#

Test mm hypotheses H1,…,HmH_1,\dots,H_m with pp-values p1,…,pmp_1,\dots,p_m. Let I0I_0 be the set of true nulls, m0=∣I0∣m_0=|I_0|, VV the number of true nulls rejected, and RR the total number rejected. A valid pp-value for a true null satisfies P(pi≤u)≤uP(p_i\le u)\le u.

  • Family-wise error rate: FWER=P(V≥1)\mathrm{FWER}=P(V\ge1).
  • False discovery rate (Benjamini and Hochberg 1995): FDR=E[V/max⁡(R,1)]\mathrm{FDR}=\mathbb E[V/\max(R,1)].

FWER control is right when a single false positive is costly, such as deploying capital on one strategy. FDR control is right when screening many candidates for further work, such as a list of factors to investigate.

Proposition 4.14Bonferroni

Rejecting HiH_i when pi≤α/mp_i\le\alpha/m gives FWER≤α\mathrm{FWER}\le\alpha under any dependence.

Proof

P(V≥1)=P(⋃i∈I0{pi≤α/m})≤∑i∈I0α/m=m0α/m≤αP(V\ge1)=P\big(\bigcup_{i\in I_0}\{p_i\le\alpha/m\}\big)\le\sum_{i\in I_0}\alpha/m=m_0\alpha/m\le\alpha.∎

Proposition 4.15Holm 1979

Order the pp-values p(1)≤⋯≤p(m)p_{(1)}\le\dots\le p_{(m)}. Reject H(1),…,H(k−1)H_{(1)},\dots,H_{(k-1)}, where kk is the first index with p(k)>α/(m−k+1)p_{(k)}>\alpha/(m-k+1) (reject all if there is none). Then FWER≤α\mathrm{FWER}\le\alpha under any dependence, and Holm rejects every hypothesis Bonferroni rejects.

Proof

Suppose some true null is rejected, and let jj be the step at which the first true null is rejected. All hypotheses rejected before step jj are false nulls, so j−1≤m−m0j-1\le m-m_0, that is m−j+1≥m0m-j+1\ge m_0. The rejected true null has p(j)≤α/(m−j+1)≤α/m0p_{(j)}\le\alpha/(m-j+1)\le\alpha/m_0. Therefore {V≥1}⊆{min⁡i∈I0pi≤α/m0}\{V\ge1\}\subseteq\{\min_{i\in I_0}p_i\le\alpha/m_0\}, and by the union bound P(V≥1)≤m0⋅α/m0=αP(V\ge1)\le m_0\cdot\alpha/m_0=\alpha. Holm's thresholds α/(m−k+1)\alpha/(m-k+1) are all at least α/m\alpha/m, so it rejects at least what Bonferroni rejects.∎

Proposition 4.16Benjamini–Hochberg 1995

Let k∗=max⁡{k:p(k)≤kα/m}k^*=\max\{k:p_{(k)}\le k\alpha/m\} and reject H(1),…,H(k∗)H_{(1)},\dots,H_{(k^*)}. If the true-null pp-values are independent of each other and of the false-null pp-values, then FDR≤m0α/m≤α\mathrm{FDR}\le m_0\alpha/m\le\alpha.

Proof

Write FDR=∑i∈I0E[1{Hi rejected}/max⁡(R,1)]\mathrm{FDR}=\sum_{i\in I_0}\mathbb E\big[\mathbf 1\{H_i\text{ rejected}\}/\max(R,1)\big]. Fix i∈I0i\in I_0 and let R(i)R^{(i)} be the number of BH rejections when pip_i is replaced by 0; R(i)R^{(i)} is a function of the other pp-values only.

Claim: for each k≥1k\ge1, {pi≤kα/m, R=k}={pi≤kα/m, R(i)=k}\{p_i\le k\alpha/m,\ R=k\}=\{p_i\le k\alpha/m,\ R^{(i)}=k\}. If pi≤kα/mp_i\le k\alpha/m and R=kR=k, lowering pip_i to 0 only shifts order statistics at or below pip_i's position. The values above position kk do not change, so the conditions p(j)>jα/mp_{(j)}>j\alpha/m for j>kj>k still hold, and p(k)p_{(k)} can only fall. Hence R(i)=kR^{(i)}=k. Conversely, if R(i)=kR^{(i)}=k and pi≤kα/mp_i\le k\alpha/m, then at least kk of the original pp-values are ≤kα/m\le k\alpha/m (the k−1k-1 others rejected with pi=0p_i=0, and pip_i itself), so R≥kR\ge k. If R=j>kR=j>k, then lowering pip_i to 0 keeps p(j)≤jα/mp_{(j)}\le j\alpha/m, giving R(i)≥j>kR^{(i)}\ge j>k, a contradiction. So R=kR=k.

On {Hi rejected,R=k}\{H_i \text{ rejected}, R=k\} we have pi≤kα/mp_i\le k\alpha/m. Using the claim and independence,

E[1{Hi rej.}max⁡(R,1)]=∑k=1m1kP(pi≤kαm, R(i)=k)=∑k=1m1kP(pi≤kαm)P(R(i)=k)≤∑k=1mαmP(R(i)=k)=αm.\begin{aligned} \mathbb E\Big[\frac{\mathbf 1\{H_i\text{ rej.}\}}{\max(R,1)}\Big]&=\sum_{k=1}^m\frac1kP\Big(p_i\le\frac{k\alpha}m,\,R^{(i)}=k\Big)=\sum_{k=1}^m\frac1kP\Big(p_i\le\frac{k\alpha}m\Big)P(R^{(i)}=k)\\ &\le\sum_{k=1}^m\frac{\alpha}{m}P(R^{(i)}=k)=\frac\alpha m. \end{aligned}

Summing over the m0m_0 true nulls gives FDR≤m0α/m\mathrm{FDR}\le m_0\alpha/m.∎

Under arbitrary dependence, Benjamini and Yekutieli (2001) show that replacing α\alpha by α/∑i=1mi−1\alpha/\sum_{i=1}^m i^{-1} restores control. Backtests of related rules on the same market are strongly dependent, so this matters.

Worked example 4.9

Eight swing-rule variants give pp-values 0.001, 0.008, 0.039, 0.041, 0.042, 0.060, 0.074, 0.205 at α=0.05\alpha=0.05.

  • Unadjusted: five rejections.
  • Bonferroni (p≤0.00625p\le0.00625): one rejection.
  • Holm: 0.001≤0.05/80.001\le0.05/8 rejects; 0.008>0.05/7=0.007140.008>0.05/7=0.00714 stops. One rejection.
  • BH: thresholds k×0.00625k\times0.00625 are 0.00625, 0.0125, 0.01875, 0.025, 0.03125, 0.0375, 0.04375, 0.05. The largest kk with p(k)p_{(k)} below its threshold is k=2k=2 (0.008 ≤ 0.0125). Two rejections.

Harvey, Liu and Zhu (2016) They catalogue 316 factors proposed to explain the cross-section of US expected returns, apply Bonferroni, Holm and Benjamini–Hochberg–Yekutieli adjustments to the growing set of tests over time, and conclude that a newly proposed factor should clear a tt-ratio of about 3.0 rather than 2.0, and that many published findings are likely false. For orientation, the Bonferroni two-sided cut-off Φ−1(1−α/2m)\Phi^{-1}(1-\alpha/2m) at α=5%\alpha=5\% is 1.96 for m=1m=1, 2.81 for m=10m=10, 3.48 for m=100m=100 and 3.76 for m=300m=300. Their figure of about 3.0 comes from less conservative methods applied to the time path of discoveries. For a private researcher the lesson is concrete: if you have tried 100 things, your t>2t>2 is not evidence.

4.6.5White's Reality Check#

Bonferroni and Holm ignore the correlation between rules, which makes them conservative for families of similar strategies. White (2000) tests the best rule directly against the distribution of the best rule under the null.

Let fk,tf_{k,t} be the excess return of rule kk over a benchmark (for example buy-and-hold) at tt, k=1..Kk=1..K, and fˉk\bar f_k its mean. The null is H0:max⁡kE[fk]≤0H_0:\max_k\mathbb E[f_k]\le0: no rule beats the benchmark. The statistic is VK=Tmax⁡kfˉkV_K=\sqrt T\max_k\bar f_k. Its null distribution is approximated by resampling time periods with the stationary bootstrap of Politis and Romano (1994), which draws blocks of random geometric length to preserve serial dependence, and computing

VK,b∗=Tmax⁡k(fˉk,b∗−fˉk),b=1..B.V^*_{K,b}=\sqrt T\max_k\big(\bar f^*_{k,b}-\bar f_k\big),\qquad b=1..B.

Recentring by fˉk\bar f_k imposes the null in the least favourable configuration (all means equal to zero). The pp-value is the fraction of VK,b∗≥VKV^*_{K,b}\ge V_K. Because the maximum is taken jointly over all KK rules in every bootstrap draw, the correlation between rules is handled automatically.

Hansen (2005) showed the test loses power when the family contains many very poor rules, and proposed the Superior Predictive Ability (SPA) test, which studentises and drops clearly inferior rules. Romano and Wolf (2005) extended the approach to a step-down procedure (StepM) that identifies which rules beat the benchmark. The arch Python package implements SPA and StepM. The code reality_check implements White's version; its test checks that 30 noise rules give a pp-value above 0.05 and that adding a genuine edge to one rule gives a pp-value below 0.05.

The essential requirement is that KK must be every rule you tried, not only the ones you kept. A Reality Check over the 26 survivors of an unrecorded search is meaningless.

4.6.6The probability of backtest overfitting#

Bailey, Borwein, López de Prado and Zhu (2017) ask a different question: if I choose the best variant in-sample, how often is it below median out-of-sample?

Algorithm 4.3combinatorially symmetric cross-validation, CSCV

Input: a T×NT\times N matrix of per-period returns of NN variants.

  1. Split the rows into SS contiguous blocks of equal length (SS even, e.g. 16).
  2. For each of the (SS/2)\binom{S}{S/2} ways to choose half the blocks as in-sample (IS), with the rest out-of-sample (OOS):
    • compute each variant's Sharpe ratio on IS rows and on OOS rows;
    • let n∗n^* be the IS-best variant; let ωˉ\bar\omega be its OOS rank divided by N+1N+1 (rank 1 = worst);
    • record the logit λ=ln⁡(ωˉ/(1−ωˉ))\lambda=\ln(\bar\omega/(1-\bar\omega)).
  3. PBO=\mathrm{PBO}= fraction of splits with λ≤0\lambda\le0.

If the variants are all noise, the IS winner's OOS rank is uniform and PBO≈0.5\mathrm{PBO}\approx0.5. If one variant has a genuine edge, it wins IS and stays above median OOS, and PBO is near 0. A high PBO means your selection procedure is choosing noise. With S=16S=16 there are 12,870 splits. The symmetric design means every block is IS in half the splits and OOS in the other half, which avoids the arbitrariness of a single hold-out.

The method assumes that the NN variants are the whole search, and that blocks are long enough for serial dependence not to leak across block boundaries. It says nothing about whether the family of variants has an edge: a family of uniformly good strategies can have a high PBO simply because their OOS ranks are random. Read it together with DSR.

4.6.7A research protocol#

  1. Keep a research log. Every backtest run, including failed ideas, is a line with date, hypothesis, parameters and result. NN in the DSR is the number of lines, adjusted for correlation.
  2. State the hypothesis and the economic reason before testing. Momentum (4.3) has a documented mechanism; "RSI 37 crossing on Tuesdays" does not.
  3. Reserve a final hold-out period that you touch once.
  4. Report: the full distribution of trial Sharpe ratios, DSR, PBO, the walk-forward curve, turnover and breakeven cost.
  5. Require a margin. Post-publication evidence (Case study 4.7.1) says that even published, peer-reviewed effects lose about half their return. Assume yours will lose more.

Data lab Open on OI Charts (opens in a new tab)

A Nifty trend rule, with costs

The rule is long (or short) the Nifty when SMAm(P)t>SMAn(P)t\mathrm{SMA}_m(P)_t > \mathrm{SMA}_n(P)_t at the close of day tt, and holds that position over day t+1t+1: the one-bar lag of Proposition 4.8. Net daily return is atRt−c ∣at−at−1∣a_tR_t - c\,|a_t - a_{t-1}| with cc the cost per side. Cash earns zero, so compare the rule's Sharpe ratio with buy and hold rather than reading it as an excess return.

What to look at

  • The gap between the gross and net curves is the cost drag c⋅TOc\cdot\mathrm{TO} of Proposition 4.10. Compare the break-even cost c∗=μg/TOc^* = \mu_g/\mathrm{TO} with the 11.9 bp per side delivery cost of worked example 4.3.
  • The Sharpe ratio is shown with ±1.96\pm1.96 standard errors from (4.13). Most settings do not separate the rule from buy and hold.
  • Every distinct (m,n,mode)(m, n, \text{mode}) you try is counted. The last row is the expected best annualised Sharpe of that many rules with no edge over this sample, (4.17). Proposition 4.2 says that under a random walk any timing profit is a diluted share of the drift.

Questions

  1. Find the (m,n)(m, n) with the best net Sharpe. How many variants did you try, and does the best one beat the noise benchmark in the table? Compute its deflated Sharpe ratio (4.18) with NN equal to your count.
  2. For m=1m = 1, n=200n = 200, how does the break-even cost compare with realistic costs for a Nifty ETF and for Nifty futures? What turnover would make the rule unprofitable at 11.9 bp per side?
  3. Switch to long/short. Where does the extra return or loss come from, in terms of the drift and autocovariance terms of (4.2)?
  4. Does the rule's maximum drawdown improve on buy and hold? Is that evidence of timing skill or of lower exposure?

Create a free account

Reading is open to everyone. An account keeps your progress, answers, notes and code drafts, and gives you the study plan, the journals and the simulator. Running code needs an account approved for it.