Prism Data Lab

Every analysis here ships its dataset and the code that produced every figure. Nothing on this site is investment advice.

MethodsUpdated 2,199 words, 10 minutes

Backtest overfitting: the deflated Sharpe ratio and a simulation

Why the best of many backtests looks good on pure noise, then the deflated Sharpe ratio and PBO tested on 200 moving-average rules on Treasury yields.

If you try enough strategies on the same data, one of them will have a good backtest. That sentence is obvious and it is also the most common way a research process produces a confident wrong answer, because the person who tried a thousand variants and reports the best one rarely reports the thousand. This article shows the effect with a simulation where every strategy is pure noise, then applies the correction Bailey and Lopez de Prado proposed in 2014, the deflated Sharpe ratio. The script is attached and uses only NumPy. Updated November 21, 2026 with the deflated Sharpe ratio and the probability of backtest overfitting applied to a real rule family: 200 moving-average rules on Treasury yields from FRED, 1963 to 2026.

The simulation

Each "strategy" is a series of 1,260 daily returns (five trading years) drawn from a normal distribution with mean exactly zero and an annual volatility of 16 percent. There is no signal anywhere. For a given number of trials N, the script draws N such strategies, computes each one's in-sample Sharpe ratio, and keeps the best. It repeats that 200 times per N and averages.

rets = rng.normal(0.0, DAILY_VOL, size=(n, T))            # n strategies x T days, true mean 0
srs = rets.mean(axis=1) / rets.std(axis=1, ddof=1)        # daily Sharpe of each
k = int(np.argmax(srs))                                   # the one you would have reported
best_annualised = srs[k] * math.sqrt(252)

Output of python code/backtest-overfitting-deflated-sharpe.py (seed 20260905):

strategies tried N mean of best in-sample Sharpe (annualised) expected max under the null (formula) share of runs where best Sharpe > 1.0 DSR of the best strategy (mean)
1 0.01 0.00 2% 0.50
10 0.69 0.61 16% 0.51
100 1.11 1.12 67% 0.48
1000 1.45 1.47 100% 0.49
10000 1.73 1.73 100% 0.50

With one strategy and no selection, the average Sharpe is zero, as it should be. With a hundred candidates, the best one has an annualised Sharpe above 1.0 in two runs out of three. With a thousand, it always does, and the average "winner" reports 1.45. Nothing was learned about markets in any of these runs; the number is the price of looking.

The expected maximum

The third column is not from the simulation. It is the closed-form expectation the paper gives for the maximum of N Sharpe estimates when the true Sharpe of every candidate is zero:

SR0 = sqrt(V) × [ (1 − γ) Z⁻¹(1 − 1/N) + γ Z⁻¹(1 − 1/(N·e)) ]

where V is the variance of the Sharpe estimates across the trials, Z⁻¹ is the inverse of the standard normal CDF, and γ is the Euler-Mascheroni constant, about 0.5772. The formula and the simulation agree to within a few hundredths at every N above 10, which is a check that the script implements what the paper describes. The formula grows with the logarithm of N, which is why going from 1,000 trials to 10,000 buys only 0.26 of extra apparent Sharpe: the damage is done early.

The deflated Sharpe ratio

The paper's proposal is to test the reported Sharpe not against zero but against SR0, and to account for the non-normality of the returns while doing so. As we read the paper, the statistic is

DSR = Φ[ (SR̂ − SR0) × sqrt(T − 1) / sqrt(1 − γ₃ SR̂ + ((γ₄ − 1)/4) SR̂²) ]

with SR̂ the non-annualised (here daily) Sharpe estimate, T the number of returns, γ₃ the skewness and γ₄ the kurtosis of the returns, and Φ the standard normal CDF. It reads as a probability that the true Sharpe exceeds zero after the selection is accounted for.

def dsr(sr_hat, sr0, t, skew, kurt):
    z = (sr_hat - sr0) * math.sqrt(t - 1) / math.sqrt(1 - skew * sr_hat + (kurt - 1) / 4 * sr_hat ** 2)
    return norm_cdf(z)

The last column of the table is the mean DSR of the winning strategy, and it is about 0.5 at every N. That is the correct answer: the winner of a noise tournament is, on average, exactly as good as the expected winner of a noise tournament, so the evidence that it is better than nothing is a coin flip. The worked example the script prints for N = 1,000 makes the contrast explicit. The best strategy had a daily Sharpe of 0.0918 (1.46 annualised). Tested naively against zero, ignoring the 999 discarded candidates, its p-value would be 0.0006, a result most people would call highly significant. Its DSR is 0.462. The same Sharpe with N = 1, meaning it was the only strategy ever tried, would carry a DSR of 0.999.

What the correction needs, and what it cannot do

The formula needs N, the number of independent trials, and that is the number nobody records. Variants of a strategy that differ by one parameter are not independent trials, so N overstates; but a research team's collective history of discarded ideas is usually far larger than anyone's notebook shows, so N understates too. The paper's Appendix A.3 estimates an effective number of trials from the average correlation of the candidates' returns. The simulation above does not need it, because its trials are independent by construction; the section below applies it to real rules. The V in the formula was estimated from the trials' own Sharpe estimates, which is available in a simulation and rarely in practice.

The companion paper in the Notices of the AMS makes the broader point with a different construction: the authors show that with enough parameter combinations one can always find a strategy that fits a given sample, and that the in-sample fit carries no information about the out-of-sample result. The deflated Sharpe ratio is a repair for one measurement; it does not repair a process that keeps searching until something passes.

None of this is a recommendation about any strategy, and the simulated strategies here are not tradable objects. The simulation shows one arithmetic fact, that the best of N noise draws has an expected Sharpe that grows with log N, and one published correction for it, with the code to check both. The next section applies that correction, and a second test, to rules run on real data.

On a real rule family: 200 moving-average rules on Treasury yields

In the simulation the answer is known in advance: every strategy is noise. Real research does not come with that guarantee, so on November 21, 2026 we ran the same correction on a family of rules a researcher could plausibly have tried. We downloaded two daily series from FRED after reading its robots.txt: the 10-year Treasury constant-maturity yield, DGS10, and the 3-month Treasury bill rate, DTB3. Both series pages are tagged "Public Domain: Citation Requested". The two columns, as downloaded, are in backtest-overfitting-treasury-yields.csv, and backtest-overfitting-treasury-rules.py computes every figure in this section from that file, with NumPy and no network request. We wrote down the rule grid, the split date and the statistics before the first run.

The returns. On each of the 16,206 days that have both yields (January 2, 1962 to November 19, 2026), holding the note means owning yesterday's 10-year par note for one day: its price at today's yield, plus one day of accrued coupon. Holding bills earns yesterday's bill rate for the same days. A rule earns the note's return minus the bills' return on the days it holds the note, and zero on the days it holds bills. This is an approximation built from two yield series, not a total-return index: it ignores the note's shrinking maturity, trading costs and taxes. As a check on its size, the note series loses 16.4 percent in calendar 2022 and gains 20.5 percent in 2008.

The rules. Hold the note on a given day when the average of the last s yields up to the previous day is below the average of the last L yields, that is, when yields have been falling; otherwise hold bills. s runs from 1 to 20 trading days (s = 1 is the previous day's yield itself) and L takes ten values from 30 to 250, which makes 200 rules, each using only data available before the day it trades. Yields are quoted to two decimals, so the two averages are often exactly equal; we compare them in whole basis points, with no rounding error, and a tie means bills.

pos = (ma(s, prev) < ma(L, prev)).astype(float)   # 1 = hold the note the next day, 0 = hold bills
X[:, j] = pos * excess[prev]                       # rule j's daily return over bills

The test period starts on January 3, 1963, the first day all 200 averages exist. The in-sample half runs to December 30, 1994 (7,979 days) and the out-of-sample half from January 3, 1995 to November 19, 2026 (7,977 days).

annualised Sharpe ratio over bills in sample, 1963 to 1994 out of sample, 1995 to 2026
best in-sample rule (s = 1, L = 30) 0.87 0.35
median of the 200 rules 0.47 0.33
always in the note 0.08 0.28

The deflated Sharpe ratio passes the winner. The best in-sample rule holds the note whenever the previous day's yield is below its 30-day average. Tested against zero as if it were the only rule tried, its p-value is 0.0000004. The deflated Sharpe ratio puts the selection back in. The 200 in-sample Sharpe estimates have a variance of 4.19 × 10⁻⁵ in daily units, which makes the expected maximum under the null 0.28 annualised for N = 200. The rules are far from independent: their daily returns have an average pairwise correlation of 0.83, and the equation in the paper's Appendix A.3, N̂ = ρ̂ + (1 − ρ̂) M, turns that into 35.5 implied independent trials, with an expected maximum of 0.22. With either N, and with the winner's skewness of 1.23 and kurtosis of 21.6 in the formula, the DSR rounds to 1.000 (z = 3.41 with N = 200, 3.78 with N = 35.5).

Out of sample, the lead went away. The DSR answered the question it asks correctly: all 200 rules beat the expected maximum under the null in sample, and the winner kept a positive Sharpe after 1994. It does not ask whether the winner is better than the other rules, and after 1994 it mostly was not. Its lead over the median rule fell from 0.40 in sample to 0.02 out of sample, and it ranked 131st of the 200 (200 = best). The best rule out of sample was s = 8, L = 80, at 0.44. Across all 200 rules, the rank correlation between in-sample and out-of-sample Sharpe is 0.12, and only 16 rules did better after 1994 than before.

The probability of backtest overfitting. Bailey, Borwein, Lopez de Prado and Zhu, in The Probability of Backtest Overfitting, estimate how often a selection process picks a rule that finishes below the median out of sample. Their method, combinatorially symmetric cross-validation (CSCV), cuts the history into S equal blocks, uses every possible half of the blocks as the training set and the other half as the test set, and records where the training winner ranks in the test. We used S = 16 blocks of 997 days (the first 4 days of the test period dropped to make the blocks equal), which gives all 12,870 ways to choose 8 blocks of 16. The paper's text gives 12,780 for S = 16; the binomial coefficient is 12,870.

for train in itertools.combinations(range(16), 8):     # 12,870 splits
    ...                                                 # Sharpe of every rule on the 8 training and the 8 test blocks
    n_star = int(np.argmax(a_is))                       # the training winner
    r = int((a_oos < a_oos[n_star]).sum()) + 1          # its test rank, 1 = worst of 200
    logits.append(math.log(r / 201 / (1 - r / 201)))    # PBO = share of logits below zero

The PBO comes out at 12.2 percent: in 11,305 of the 12,870 splits the training winner finished in the top half of the test half, and the median logit, 4.19, puts it near the very top of the 200. The probability of loss, the share of splits where the training winner's test Sharpe was below zero, is 0.1 percent. The paper also looks at performance degradation: across the splits the winner's test Sharpe had a median of 0.53 against 0.61 in training, and the slope of test Sharpe on training Sharpe is -0.66, so the higher the winning training Sharpe, the lower its test Sharpe tended to be.

By that measure the selection looks sound, and the chronological split agrees on rank: 131st of 200 is above the median, a logit of 0.63, so it counts as a split that did not overfit. Both answers are about rank, not size. Most CSCV splits put blocks from several decades on both sides, so training and testing share regimes. Exactly one of the 12,870 puts every training block before every test block: blocks 1 to 8 (to January 3, 1995) against blocks 9 to 16. We looked it up after the first run. It picks the same winner (s = 1, L = 30), which ranks 133rd in the test half, a logit of 0.67, and only 2,331 splits (18.1 percent) gave a lower logit. The split a researcher at the end of 1994 would actually have faced is among the less favourable ones, yet it still counts as no overfitting. One forward split settles little on its own, but it shows what neither statistic measures: a winner can stay above the median and still lose nearly all of its lead.

What each number answers, on these 200 rules: - The deflated Sharpe ratio: is the winner's true Sharpe above zero, given how many rules were tried? Yes, with z = 3.41 at N = 200. - The PBO: how often does the in-sample winner finish below the median out of sample, over many train/test splits? 12.2 percent of 12,870 splits. - The chronological out-of-sample test: how much of the winner's lead over the median survives? 0.02 of 0.40, on the one split that runs forward in time.

The Treasury rules are a measurement, not a recommendation: the note returns are an approximation, and no rule here counts trading costs or taxes.

This article is analysis and education, not investment, tax, or legal advice. Figures are cited to their source and dated; check them before relying on them.