Quant notes · 06 · interactive
The Sharpe ratio is the mean of a strategy's excess returns divided by their standard deviation. This page states the definition and its annualisation, the sampling error of the estimate, the inflation of the best estimate among several trials, and two published corrections: the deflated Sharpe ratio and the multiple-testing haircut. Each section is followed by a lab on simulated returns.
pos = target.shift(1), is never removed. 3 · Every result includes costs. A Sharpe ratio reported by the project is computed on returns produced under all three.All series on this page are simulated, not market data. No performance is reported. The worked examples in sections 4 and 5 are the hypothetical examples published in the cited papers.
Sharpe (1994, eq. 3–6) defines the ex post ratio on the differential return Dt = RFt − RBt, the return of the fund minus the return of a benchmark, over periods t = 1, …, T. The ratio is the average of Dt divided by its standard deviation, computed with T − 1 in the denominator. When the benchmark is the risk-free return rf, with μ the sample mean of the returns and σ the sample standard deviation, the Sharpe ratio per period is
Read aloud: the estimated Sharpe ratio is the average return in excess of the risk-free rate, divided by the standard deviation of those returns. The hat on a symbol marks a quantity estimated from a sample.
Sharpe ratios are quoted in annual units so that strategies sampled at different frequencies can be compared. With q periods per year and returns independent and identically distributed (IID), Sharpe (1994, eq. 7–10) and Bailey, Borwein, López de Prado and Zhu (2014, eq. 2) give
Read aloud: the annual Sharpe ratio is the per-period ratio of mean to standard deviation, multiplied by the square root of the number of periods in a year. Daily data with one row per calendar day has q = 365.
Sharpe (1994) notes that "the t-statistic will equal the Sharpe Ratio times the square root of T", and Harvey and Liu (2015, eq. 1–2) use the same relation to test the null hypothesis that the mean return is zero:
Read aloud: the t-statistic is the per-period Sharpe ratio times the square root of the number of observations. For a fixed sample length, a higher Sharpe ratio means a higher t-statistic and a smaller p-value.
Select a term of the formula for its definition and its counterpart in backtest.py.
Over q periods the mean of a sum of returns is q times the per-period mean. If the returns are uncorrelated, the variance of the sum is q times the per-period variance, so the standard deviation grows with √q. The ratio of the two therefore grows with q / √q = √q (Sharpe, 1994, eq. 7–10, under the stated condition of "zero serial correlation"). Lo and MacKinlay (1988, p. 44) state the underlying property: "the variance of the increments of a random walk is linear in the observation interval."
When returns are autocorrelated the variance of the q-period sum is no longer q times the one-period variance. Lo and MacKinlay measure the departure with the variance ratio VR(q), the variance of q-period returns divided by q times the variance of one-period returns. Their equation 16 expresses it through the autocorrelations ρ(k):
Read aloud: the variance ratio is one plus twice the sum, over lags k = 1 to q − 1, of the autocorrelation ρk weighted by (1 − k/q); the weight falls in a straight line from nearly 1 at lag 1 to 1/q at lag q − 1. Positive autocorrelation makes VR(q) greater than 1; negative autocorrelation makes it less than 1.
Read aloud: the q-period Sharpe ratio is the one-period ratio multiplied by the scale factor η(q). The scale factor is q divided by the square root of q plus twice the weighted sum of the autocorrelations, which is the same as √q divided by the square root of the variance ratio. With no autocorrelation, η(q) = √q.
This is Lo (2002, eq. 20). Lo concludes that "monthly Sharpe ratios cannot be annualized by multiplying by √12 except under very special circumstances" (p. 36). For a first-order autoregressive process, with ρk = ρk, his eq. 22 gives η(q) in closed form. Computed here for monthly data (q = 12): η = with ρ = 0, with ρ = 0.20 and with ρ = −0.20, the values Lo reports in the text and in Table 2 (p. 41). Positive serial correlation lowers the annual Sharpe ratio below the √q figure; negative serial correlation raises it.
Daily returns are simulated from a first-order autoregressive process, rt − μ = ρ (rt−1 − μ) + εt, for which ρ(k) = ρk. The standard deviation of ε is set so that the standard deviation of r is σ for every ρ. The chart shows the standard deviation of h-day summed returns, in units of σ, against the horizon h.
The true Sharpe ratio is a property of the process that generates returns and is not observed. A backtest of y years returns an estimate, and a different y-year history from the same process would return a different estimate. For IID returns, Lo (2002, eq. 9) gives the standard error of the per-period estimate as √((1 + ½SR²)/T). With SRper period = SR/√q and T = yq this becomes, for the annualised estimate (Bailey et al., 2014, eq. 3):
Read aloud: as the sample grows, the estimated annual Sharpe ratio is approximately Normal, centred on the true value, with variance one plus SR squared over 2q, all divided by the number of years y. The standard error falls with the square root of the number of years, not with the number of observations: sampling daily instead of monthly does not shorten the history required.
Lo's Table 1 (p. 39) tabulates eq. 9 for per-period ratios. Computed here for T = 60: a true Sharpe ratio of 1.50 gives a standard error of and 3.00 gives , the values printed in the table. A 95% interval is approximately SR ± 1.96 standard errors (Lo, 2002, eq. 10). The interval excludes zero only when y exceeds 1.96² (1 + SR²/2q) / SR². For a true annual Sharpe ratio of 0.5 that is – years; for 1.0 it is – years. The formula assumes IID Normal returns. For returns with autocorrelation and changing volatility, the stationary bootstrap of Politis and Romano (1994) resamples blocks of consecutive returns of random, geometrically distributed length, and is the method the research plan applies to the project's own returns.
Each run simulates 600 independent histories of y years of daily Normal returns (q = 365) whose true annual Sharpe ratio is fixed by the first slider. Each history yields one estimate, computed as line 94 of backtest.py computes it. The histogram is the distribution of the 600 estimates; the curve is the asymptotic Normal above.
A trial is one backtested configuration: a rule with one set of parameters. If N independent trials are run and the configuration with the highest Sharpe ratio is retained, the retained estimate is the maximum of N noisy estimates, and it exceeds zero even when every true Sharpe ratio is zero. For N independent standard Normal variables, Bailey et al. (2014, eq. 4) approximate the expected maximum as
Read aloud: the expected largest of N standard Normal draws is a weighted combination of two Normal quantiles, with weights set by the Euler–Mascheroni constant γ ≈ 0.5772. Z−1 is the inverse of the standard Normal cumulative distribution and e is Euler's number. The value grows with N without limit, but slowly, and stays below √(2 ln N).
With zero true Sharpe ratio, the annualised estimate over y years has standard deviation y−1/2 (eq. 3 with SR = 0). The expected maximum annual Sharpe ratio among N skill-less trials is therefore E[maxN] / √y (eq. 5). For N = 10 and one year this is –, the figure the paper reports as 1.57. Solving for y gives the minimum backtest length, MinBTL, the number of years required for the expected maximum to stay at a chosen level, here 1 (eq. 6):
Read aloud: the minimum backtest length in years is the square of E[maxN], the expected largest of N standard Normal draws, divided by SR*IS, the in-sample annual Sharpe ratio that the best skill-less trial must not be allowed to reach. The paper writes this target as E[maxN] too; the two symbols are separated here. More trials, or a lower target, require more years.
The paper's statement, computed here: with five years of data, at most – independent configurations can be tried before the best of them is expected to show an annual Sharpe ratio of 1 with no skill; with two years, –. The paper concludes that "a backtest which does not report the number of trials N used to identify the selected configuration makes it impossible to assess the risk of overfitting" (Bailey et al., 2014, p. 461).
Each run simulates N independent strategies, each with y years of daily Normal returns of mean zero, so every true Sharpe ratio is 0. Each dot is one strategy's estimated annual Sharpe ratio. The orange dot is the maximum, the configuration a search would retain.
Bailey and López de Prado (2014) combine the two sources of inflation, selection among trials and non-Normal returns, in one statistic. The deflated Sharpe ratio is the probability that the true Sharpe ratio exceeds the threshold SR0 expected from the best of N skill-less trials (eq. 2). All Sharpe ratios in the formula are per period, not annualised.
Read aloud, line by line. The probabilistic Sharpe ratio PSR[SR*] is the standard Normal probability that the true Sharpe ratio exceeds a threshold SR*: the gap between the per-period estimate SR and the threshold, times the square root of the sample length minus one, divided by a term that grows when returns are negatively skewed (γ3 < 0) or fat-tailed (γ4 > 3). The deflated Sharpe ratio is the PSR evaluated at the threshold SR0. That threshold is the expected maximum of N skill-less trials, scaled by the standard deviation of the Sharpe ratios across the trials. A DSR above 0.95 is evidence at the 95% level that the selected strategy has a positive true Sharpe ratio.
Harvey and Liu (2015, eq. 3–5) take a p-value route. The single-test p-value of the t-statistic SR·√T is converted to a multiple-testing p-value for N independent tests, pM = 1 − (1 − pS)N, and the haircut Sharpe ratio is the Sharpe ratio whose single-test p-value equals pM. Their example: twenty years of monthly returns, an annual Sharpe ratio of 0.75, and 200 tests reduce the Sharpe ratio to about 0.32. Select a term for its definition.
Both calculators open on the hypothetical examples published in the papers, so each output can be compared with the printed value. The inputs can be edited.
Probabilities use the standard Normal. The paper's printed values (pS = 0.0008, pM = 0.15, haircut Sharpe ratio 0.32) agree with that choice to the digits shown.
The Sharpe ratio uses two moments of the return distribution, the mean and the standard deviation. Harvey and Liu (2015, p. 13) state the limitation: "high observed Sharpe ratios could be the results of non-normal returns, for instance, an option-like strategy with high ex ante negative skew. In this case, Sharpe ratios should be viewed in the context of the skew." The DSR denominator includes the skewness γ3 and kurtosis γ4 for this reason: with negative skewness or kurtosis above 3, the same Sharpe ratio carries less evidence.
The Sharpe ratio is also unchanged by the order of the returns. A history in which the losses arrive consecutively and a history in which they are scattered have the same mean and standard deviation, and therefore the same Sharpe ratio, but different maximum drawdowns. The project reports the maximum drawdown from stats() next to every Sharpe ratio for this reason.
src/backtest.py: vol = net.std() * np.sqrt(bars_per_year) and Sharpe = (net.mean() * bars_per_year) / vol. This equals (μ/σ)·√q with q = bars_per_year = 365, the annualised form of section 1.
Risk-free rate. The code uses net, not net minus a risk-free return, so rf = 0. Sharpe (1994) states that "it is essential that the Sharpe Ratio be computed using the mean and standard deviation of a differential return". His example: fund X returns 5% with 10% volatility, fund Y 8% with 20%, and cash 3%. Mean over volatility ranks X first ( against ); the Sharpe ratio on excess return ranks Y first ( against ), and Y is the better choice at equal risk. For a long/short position financed at a cost, the carry line (line 70) already charges financing; for a funded long position, setting rf = 0 overstates the Sharpe ratio by approximately the cash rate divided by the volatility. Each model report states the benchmark used.
Costs and lag. net is computed after the one-bar lag (line 62), after transaction costs (line 69) and after carry (line 70). Every Sharpe ratio the project reports therefore satisfies constraints 2 and 3.
Gold on a calendar-day table. The clean table has one row per calendar day, and gold's forward-filled weekend rows carry zero return. Annualisation sums per-row means and variances over the 365 rows of a year; rows with zero return add nothing to either sum. The result is close to the figure from gold's own trading days with q ≈ 252, which keeps the two instruments on one annualisation convention.
Trials. Every grid entry evaluated by walk_forward, and every rule or parameter tried by hand, is one trial in the sense of section 4. The research log records each one, so that N is known when a result is reported.
What stats() does not report. stats() returns a point estimate only. The research plan adds two items before a model report is written: a stationary-bootstrap confidence interval for the Sharpe ratio (section 3) and the deflated Sharpe ratio with N taken from the research log (section 5).Each entry: the technical definition first, then the same idea in everyday words in the orange strip.
W. F. Sharpe (1966), cited by Sharpe (1994) as the origin of the measure, is quoted from the reading list, not from the text.
All numbers on this page are computed by the page's JavaScript from simulated series or from the published inputs. Part of quant-notes. See also 02 · Volatility estimation by EWMA, 03 · Backtest errors and controls and 04 · Backtester implementation.