Bootstrap Confidence Intervals for Backtest Sharpe Ratios in Python (2026)

Every backtest ends by collapsing to a single number. A Sharpe ratio gets printed, compared against a threshold, and treated as a verdict. What that number never carries is an error bar.
That matters because you almost never get a fresh history to test against. You reuse the same tape for every variant, which is the data-snooping condition White describes. This post is about measuring the uncertainty in that number with a block bootstrap, using runnable Python.
How This Guide Was Built
This guide is based on the cited papers and the arch library source; we did not run it on a live strategy.
- Sources consulted: the White (2000) abstract, the Ledoit & Wolf (2008) abstract as listed on RePEc, and
arch/bootstrap/base.py(the fetched copy covered only the first ~1,000 of its 2,745 lines). - The demo series in the code is synthetic
numpyRNG output, not a backtest of any real strategy, ticker, or market history. - No console output or numeric result appears below, because the snippets were not executed for this guide. Run them to get numbers.
Why One Sharpe Number Is Not Enough
A backtest Sharpe is a sample statistic computed from the single history you happen to have, and reusing that one history across many candidate strategies is precisely the data-snooping condition White (2000) warns makes chance look like merit. An interval is a cheap way to say how much of that number could be luck.
White’s abstract lays out the mechanism: when data is used more than once for inference or model selection, “there is always the possibility that any satisfactory results obtained may simply be due to chance rather than to any merit inherent in the method yielding the results.” He calls the problem “practically unavoidable in the analysis of time-series data, as typically only a single history measuring a given phenomenon of interest is available for analysis.” He also notes that although researchers acknowledge snooping as a dangerous practice, “in fact it is endemic.”
For a backtester this matters in practice. Every parameter sweep, every filter, every rebalance frequency you compare is another use of the same return series. A point Sharpe ratio cannot tell you how much of the observed edge would survive a different draw from the same process. An interval at least states the sampling uncertainty of the estimate you actually computed.
Why the Classic Sharpe Test Fails on Real Returns
The Jobson–Korkie test, even with Memmel’s correction, is not valid when returns have tails heavier than the normal distribution or are of time series nature — exactly the conditions the abstract names: heavy tails and time-series dependence (Ledoit & Wolf, 2008). That is the reason to bootstrap rather than rely on the closed-form test.
Their alternative, at the abstract level, is a studentized time series bootstrap confidence interval for the difference of two Sharpe ratios, with the decision rule that the ratios are declared different if zero is not contained in the interval. The stated advantage is that one can “simply resample from the observed data as opposed to some null-restricted data.” The published simulation study and the two real-data applications live in the full text, which is paywalled; everything here stays at the level of the abstract, and you should read the paper before implementing studentization details yourself.
The Stationary Block Bootstrap, in One Paragraph
arch’s own documentation describes StationaryBootstrap as “Politis and Romano’s bootstrap with exp. distributed block lengths” — it resamples blocks of consecutive observations with random, exponentially distributed lengths so short-range dependence survives (arch source). The random block lengths distinguish it from fixed-length block schemes; any block scheme keeps more dependence than an iid shuffle of the same returns.
An iid bootstrap shuffles individual days. That destroys the ordering which produced the dependence in your series — volatility clustering, autocorrelation in the sign of returns, the way a drawdown strings losses together. A block bootstrap keeps runs of consecutive observations intact; the stationary variant also draws random block lengths.
The same module exports CircularBlockBootstrap, MovingBlockBootstrap, IIDBootstrap, IndependentSamplesBootstrap, and LocalBlockBootstrap alongside StationaryBootstrap. Treat the quoted phrase above as an API description from arch’s docstring rather than a summary of the original paper, which was not consulted here.
Letting arch Choose the Block Length
optimal_block_length(x) returns a DataFrame with stationary and circular columns, where stationary is the suggested block size for StationaryBootstrap, and it implements the Politis & White (2004) algorithm with the Patton, Politis & White (2009) correction (arch source). You supply the returns; arch picks the window.
The function requires at least 11 observations and finite data, and raises ValueError otherwise, so very short series need a manually chosen block length instead. Two notes from the source are worth keeping in mind: arch states that some tuning parameters are taken from Andrew Patton’s MATLAB program, and that its block lengths “do not match this implementation” because autocovariances and autocorrelations are computed using the maximum sample length. The two constants (2 for the stationary bootstrap, 4/3 for the circular one) are inputs to the block-length formula, so each column is computed for its own bootstrap; use stationary with StationaryBootstrap.
Code — A 95% CI for One Strategy’s Sharpe
The snippet below takes a daily-returns pandas Series, estimates the block length, bootstraps with StationaryBootstrap, and reads the 95% interval from conf_int’s lower/upper rows. The demo data is synthetic RNG output, and no output block appears because the code was not executed for this guide.
import numpy as np
import pandas as pd
from arch.bootstrap import StationaryBootstrap, optimal_block_length
# --- Demo data: SYNTHETIC RNG draws, NOT a backtest of any real strategy. ---
# Replace `returns` with your own daily strategy returns Series (decimals).
rng = np.random.default_rng(42)
returns = pd.Series(rng.standard_normal(750) * 0.01, name="strategy")
def sharpe(x):
"""Illustrative annualized Sharpe: rf=0, sample std (ddof=1), sqrt(252)."""
x = np.asarray(x, dtype=float)
return np.sqrt(252.0) * x.mean() / x.std(ddof=1)
# 1) Data-driven block length (Politis & White 2004 / Patton et al. 2009 via arch)
block_size = int(optimal_block_length(returns)["stationary"].iloc[0])
# 2) Stationary (Politis-Romano) block bootstrap; seed= makes it reproducible
sb = StationaryBootstrap(block_size, returns, seed=42)
# 3) 95% percentile CI; row 0 = lower bounds, row 1 = upper bounds
ci = sb.conf_int(sharpe, reps=1000, method="percentile", size=0.95)
print(f"optimal block length (stationary): {block_size}")
print(f"point estimate, annualized Sharpe: {sharpe(returns):.4f}")
print(f"95% CI: [{ci[0, 0]:.4f}, {ci[1, 0]:.4f}]")
print(f"CI excludes zero: {ci[0, 0] > 0 or ci[1, 0] < 0}")
What the call produces, field by field, with values appearing only when you run it: the stationary optimal block length for the demo series; the point-estimate annualized Sharpe; the lower and upper bounds read from row 0 and row 1 of the conf_int output; and a boolean for whether the interval excludes zero.
Three choices in that code are this post’s, not arch’s. The Sharpe convention — daily returns, zero risk-free rate, sample standard deviation with ddof=1, scaled by the square root of 252 — is illustrative, so match whatever convention your reporting already uses. reps=1000 is arch’s documented default written out explicitly; raising it gives smoother bounds at the cost of runtime. And seed=42 is passed as an integer, which arch forwards to np.random.default_rng.
Code — Strategy vs. Benchmark via the Difference of Sharpe Ratios
Following Ledoit & Wolf (2008), bootstrap the difference of the two Sharpe ratios and treat the strategies as distinguishable only when zero falls outside the interval. The code below also shows one practical author choice: a shared block length and a single bootstrap object holding both series.
# --- Demo data: a second SYNTHETIC series standing in for a benchmark. ---
rng_b = np.random.default_rng(7)
benchmark = pd.Series(rng_b.standard_normal(750) * 0.008, name="benchmark")
def sharpe_diff(a, b):
"""Difference of annualized Sharpes: strategy minus benchmark."""
def sr(x):
x = np.asarray(x, dtype=float)
return np.sqrt(252.0) * x.mean() / x.std(ddof=1)
return sr(a) - sr(b)
# One block-length choice per series, then a shared block for the pair
blocks = [int(optimal_block_length(s)["stationary"].iloc[0]) for s in (returns, benchmark)]
shared_block = int(round(np.mean(blocks)))
# Both Series go into ONE bootstrap object so each replicate keeps the days aligned
sb2 = StationaryBootstrap(shared_block, returns, benchmark, seed=42)
ci_diff = sb2.conf_int(sharpe_diff, reps=1000, method="percentile", size=0.95)
print(f"shared block length: {shared_block}")
print(f"point estimate, Sharpe(a) - Sharpe(b): {sharpe_diff(returns, benchmark):.4f}")
print(f"95% CI: [{ci_diff[0, 0]:.4f}, {ci_diff[1, 0]:.4f}]")
print(f"zero inside CI (indistinguishable): {ci_diff[0, 0] <= 0.0 <= ci_diff[1, 0]}")
It prints the shared block length, the point-estimate Sharpe difference, the interval bounds for that difference, and a boolean for whether zero sits inside the interval.
Table 1 — Two comparisons, one rule
| Question | Quantity bootstrapped | Declare “distinguishable” when |
|---|---|---|
| Strategy vs. zero | Annualized Sharpe of the strategy | 0 lies outside the CI |
| Strategy vs. benchmark | Difference of the two Sharpe ratios | 0 lies outside the CI of the difference — Ledoit & Wolf (2008) |
Both rows share one decision shape: compute the interval, then ask whether zero is inside it. For the single-strategy case the null value is a Sharpe of zero; for the pairwise case it is a difference of zero. The second comparison answers whether a new variant beats the strategy you were already running.
Choosing a conf_int Method (and One Caveat)
arch’s conf_int accepts six method= values, and bca carries a serial-dependence caveat you should know first (arch source).
Table 2 — conf_int methods in arch
method= |
aliases |
Notes |
|---|---|---|
basic |
— | name only; mechanism not in the fetched excerpt |
percentile |
— | name only; used in the snippets above |
studentized |
— | nested bootstrap when std_err_func is not provided |
norm |
var, cov |
name only; mechanism not in the fetched excerpt |
bc |
debiased, bias-corrected |
name only; mechanism not in the fetched excerpt |
bca |
— | acceleration estimated by an iid jackknife for all bootstraps, ignoring serial dependence and block size (arch source) |
reps defaults to 1000 and size to 0.95; output rows are lower and upper bounds, with one column per parameter. The bca row deserves the direct quote: “It is the iid jackknife for all bootstraps, including the block bootstraps, and so does not take account of serial dependence or the block size.” That is a mismatch with the reason you chose a block bootstrap in the first place. studentized shares a label with the Ledoit and Wolf interval; without a supplied std_err_func, arch runs a nested bootstrap.
The Bottom Line
Report intervals, not points: if the bootstrap interval for your Sharpe — or for its difference against a benchmark — straddles zero, your backtest does not yet distinguish the strategy from noise.
The interval quantifies sampling uncertainty of the estimate on the sample you observed. It is not a forecast of next year’s Sharpe, it does not repair a strategy you selected after staring at the same data, and it says nothing about whether an edge is economically real. It describes how much the number would move under resampling of a comparable history.
For reproducibility, pass seed= when constructing the bootstrap; an integer is forwarded to np.random.default_rng. Record the seed next to the code and the data window so a rerun produces the same bounds.
Nothing here is investment advice or a recommendation to trade, deploy, or size any strategy. It is a measurement methodology and nothing more.
FAQ
Short answers to the three questions that come up when wiring this into a pandas backtest loop, each pointing back to the section with the details.
Why not just use the Jobson–Korkie test (with Memmel’s correction)?
Because its validity assumption fails on exactly the data you have. The Ledoit and Wolf abstract states that the Jobson–Korkie test, Memmel correction included, is not valid when returns have tails heavier than normal or are of time series nature. Bootstrap the difference of Sharpe ratios instead and check whether zero is inside the interval.
How many observations does optimal_block_length need?
At least eleven. The arch docstring states that the function requires at least 11 observations and finite data, raising ValueError otherwise. It returns a DataFrame with stationary and circular columns, giving the suggested block size for the stationary and circular bootstraps respectively. Shorter series therefore need a manual block length or a different approach.
Should I use method="bca" for the most accurate interval?
Probably not by default. The arch docstring says the bca acceleration parameter is estimated by an iid jackknife “for all bootstraps, including the block bootstraps, and so does not take account of serial dependence or the block size.” The fetched excerpt documents this caveat only for bca and gives no assumptions for the other methods, so check the arch docs before assuming any. studentized shares a label with the Ledoit and Wolf interval but nests a bootstrap.


