Backtesting and Statistical Testing

Hard·22 min read
Statistical / ML for QuantsBacktestingSharpe RatioMultiple Hypothesis TestingOverfitting

Setup

The Fundamental Problem

A backtest is a simulation of a trading strategy applied to historical data to estimate future performance. The core challenge is that the future is not the past — and research processes that iterate over historical data until a "good" strategy is found will produce results that are statistically meaningful in-sample but economically meaningless out-of-sample.

Backtesting is the most abused tool in quantitative finance. Bailey et al. (2014) estimate that the majority of published financial research results are false discoveries, driven by data mining over a finite sample. The antidote is rigorous statistical testing with explicit multiple hypothesis adjustment.

Conventions throughout. Returns are continuously compounded unless stated. Daily returns assumed 252 trading days per year. Sharpe ratio computed as annualised mean excess return divided by annualised return standard deviation. All statistics are defined for excess returns (above cash).


Theory

1. The Sharpe Ratio: Distribution and Inference

The Sharpe ratio of a strategy with daily excess returns (r1,,rT)(r_1, \ldots, r_T) is:

SR^=rˉσ^,rˉ=1Tt=1Trt,σ^2=1T1t=1T(rtrˉ)2.\widehat{\text{SR}} = \frac{\bar{r}}{\hat{\sigma}}, \qquad \bar{r} = \frac{1}{T}\sum_{t=1}^T r_t, \qquad \hat{\sigma}^2 = \frac{1}{T-1}\sum_{t=1}^T (r_t - \bar{r})^2.

Annualised: multiply by 252\sqrt{252} (daily frequency).

Asymptotic distribution. Under iid\text{iid} returns with finite kurtosis (Lo 2002):

T(SR^SR)dN ⁣(0,  1+SR22(κ1)),\sqrt{T}\left(\widehat{\text{SR}} - \text{SR}\right) \xrightarrow{d} \mathcal{N}\!\left(0,\; 1 + \frac{\text{SR}^2}{2}\left(\kappa - 1\right)\right),

where κ\kappa is the excess kurtosis of returns. For κ=0\kappa = 0 (Gaussian returns):

SR^N ⁣(SR,  1+SR2/2T).\widehat{\text{SR}} \approx \mathcal{N}\!\left(\text{SR},\; \frac{1 + \text{SR}^2/2}{T}\right).

A t-statistic for testing H0:SR=0H_0: \text{SR} = 0 against HA:SR>0H_A: \text{SR} > 0:

t=SR^T/1+SR^2/2,t = \widehat{\text{SR}} \cdot \sqrt{T} / \sqrt{1 + \widehat{\text{SR}}^2/2},

which follows an approximately standard normal distribution under H0H_0.

Minimum track record. Solving for TT such that the one-sided test at level α\alpha rejects H0H_0:

T=(zα1+SR^2/2SR^)2.T^* = \left(z_\alpha \cdot \frac{\sqrt{1 + \widehat{\text{SR}}^2/2}}{\widehat{\text{SR}}}\right)^2.

For SR^=1\widehat{\text{SR}} = 1 (annualised) in daily data, z0.05=1.645z_{0.05} = 1.645: this gives T5.8T^* \approx 5.8 years of daily data to establish statistical significance at 5%.

2. Multiple Hypothesis Testing: The False Discovery Problem

Suppose a researcher tests NN independent strategies, each with H0:SRk=0H_0: \text{SR}_k = 0, at significance level α=0.05\alpha = 0.05. Expected false discoveries under all-null hypotheses:

E[false discoveries]=Nα.\mathbb{E}[\text{false discoveries}] = N \cdot \alpha.

For N=100N = 100: expect 5 false discoveries even if every strategy has zero alpha. If only the best Sharpe is reported, selection bias inflates it systematically.

Bonferroni correction. Test each hypothesis at level α/N\alpha / N. Controls the familywise error rate (FWER) — probability of any false discovery. Overly conservative when NN is large.

Benjamini-Hochberg (BH) procedure. Controls the false discovery rate (FDR) — expected proportion of discoveries that are false:

  1. Order p-values: p(1)p(2)p(N)p_{(1)} \leq p_{(2)} \leq \cdots \leq p_{(N)}.
  2. Find the largest kk such that p(k)kNαp_{(k)} \leq \frac{k}{N} \alpha.
  3. Reject all H(1),,H(k)H_{(1)}, \ldots, H_{(k)}.

BH controls FDR α\leq \alpha under independence (and under positive dependence, PRDS condition). For correlated strategies, the Benjamini-Yekutieli (BY) procedure controls FDR under arbitrary dependence at the cost of a lnN\ln N factor in the threshold.

3. The Deflated Sharpe Ratio

Bailey and López de Prado (2014) propose the Deflated Sharpe Ratio (DSR) to adjust for the selection bias introduced by testing multiple strategies:

DSR(SR)=Φ ⁣((SRE[SRmax])T11ρ^SR2+SR22(γ1)),\text{DSR}(\text{SR}^*) = \Phi\!\left(\frac{(\text{SR}^* - \mathbb{E}[\text{SR}^{\max}]) \cdot \sqrt{T - 1}}{\sqrt{1 - \hat{\rho} \cdot \text{SR}^{*2} + \frac{\text{SR}^{*2}}{2} (\gamma - 1)}}\right),

where:

  • SR\text{SR}^* is the observed maximum Sharpe across NN tried strategies,
  • E[SRmax](1γE)Φ1(11/N)+Φ1(11/(Ne))\mathbb{E}[\text{SR}^{\max}] \approx (1 - \gamma_E)\Phi^{-1}(1 - 1/N) + \Phi^{-1}(1 - 1/(Ne)) is the expected maximum of NN iid standard normals (approximation),
  • ρ^\hat{\rho} is average pairwise correlation of the NN strategy returns,
  • γ\gamma is excess kurtosis of the selected strategy's returns,
  • γE0.5772\gamma_E \approx 0.5772 is the Euler-Mascheroni constant.

DSR >0.95> 0.95 means the observed Sharpe, after deflating for search over NN strategies, remains statistically significant.

Minimum Backtest Length. The expected maximum Sharpe ratio over NN trials grows as 2lnN\sim \sqrt{2 \ln N}. A backtest of length TT with NN strategies tried produces a statistically robust conclusion only if:

T>(z1αSR2lnN)2(1+SR^2/2).T > \left(\frac{z_{1-\alpha}}{\text{SR}^* - \sqrt{2\ln N}}\right)^2 (1 + \widehat{\text{SR}}^{*2}/2).

For N=50N = 50, SR=1.5\text{SR}^* = 1.5: minimum T3,500T \approx 3{,}500 daily observations (14\approx 14 years).

4. Walk-Forward Backtest Design

A properly structured backtest:

  1. Split data before touching it. Designate an out-of-sample (OOS) holdout of at least 20–30% of history. The model is never fitted on this period.
  2. Training/validation split. Use purged walk-forward CV (see ML Signal Generation module) on the in-sample period to select hyperparameters.
  3. Single test on holdout. Run the finalised strategy once on the OOS period and report those results.
  4. Report honestly. Report: number of strategies tried, number discarded, all parameter combinations explored. Failure to disclose is p-hacking.

This topic requires Premium

Only today's featured topic is free. Unlock the full Today's Focus archive with Premium.

Read the theory? Run the code.

View Notebook