Quant notes · 06 · interactive

Sharpe ratio estimation

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.

Constraints 1 · Signals use only past data. 2 · The one-bar lag, 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.

1 · Definition

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

SR = μ − rfσ

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

SRannual = μσ · √q

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:

t = μσ · √T = SR · √T

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.

2 · Annualisation

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):

VR(q) ≈ 1 + 2 q − 1Σk = 1 ( 1 − kq ) ρ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.

SR(q) = η(q) · SR
η(q) = q√q + 2 q − 1Σk = 1 (q − k) ρk = √q√VR(q)

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.

Lab A · Annualisation with autocorrelated returns

simulated · not market data

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.

Periods per year q:
√h: uncorrelated returns√(h·VR(h)): formula with ρ(k) = ρksimulated: 300 years of daily returns, non-overlapping h-day sums
–daily Sharpe ratio, μ/σ
–annual, √q rule
–variance ratio VR(q)
–scale factor η(q), Lo eq. 22
–annual, η(q) · μ/σ
–annual, simulated: mean of yearly sums ÷ their standard deviation
Lab steps 1. Set ρ = 0. The blue line lies on the grey line, VR(q) = 1, and the two annual Sharpe ratios are equal. 2. Set ρ = 0.10. Each day's return is pushed slightly in the direction of the previous day's. Moves accumulate over the year, the yearly spread is wider than √q predicts, η(q) falls below √q, and the annual Sharpe ratio is lower than the √q figure. 3. Set ρ = −0.10. Each day partly reverses the previous one. The yearly spread is narrower, and the corrected Sharpe ratio is higher. 4. Change the seed. The orange points move; the blue line does not. The points are one simulated history; the line is the formula.

3 · Sampling error

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):

SRannual ~ N( SRannual , Var[SRannual] ) for large T
Var[SRannual] ≈ 1y · ( 1 + SRannual22 q ) SE[SRannual] = √Var

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.

Lab B · Distribution of the estimate

simulated · not market data

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.

simulated estimatesasymptotic Normal, Lo eq. 9true valuezero
–mean of the estimates
–standard deviation, simulated
–standard error, Lo eq. 9
–central 95% of the estimates
–share of histories with SR < 0
Lab steps 1. True Sharpe ratio 0.5, 5 years. By Lo eq. 9, 95% of estimates fall between and . A history with a true Sharpe ratio of 0.5 can report almost any value in that range. 2. Increase y to 15. The spread narrows by about √3, the ratio of √15 to √5. 3. Set the true Sharpe ratio to 0. Every estimate is noise. About half are positive, and the largest of the 600 is far above zero; section 4 uses that maximum.

4 · Selection among trials

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

E[maxN] ≈ (1 − γ) · Z−1[ 1 − 1N ] + γ · Z−1[ 1 − 1N · e ]

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):

MinBTL ≈ ( E[maxN]SR*IS )2 < 2 ln N(SR*IS)2

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).

Lab C · The best of N trials with no skill

simulated · not market data

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.

one trialretained maximumE[maxN]/√y, eq. 5upper bound √(2 ln N)/√y
–maximum in this simulation
–expected maximum, eq. 5
–MinBTL in years for this N, eq. 6
–largest N for y years
Lab steps 1. N = 1. One trial, one estimate near zero. A single test with no selection. 2. Increase N to 100 with y = 5. The maximum moves above 1. No strategy in the simulation has any edge. 3. Hold N = 100 and increase y. The cloud contracts toward zero and the maximum falls with 1/√y. A longer history is the only input that lowers the expected maximum for a fixed N.

5 · The deflated Sharpe ratio and the haircut

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.

PSR[SR*] = Z[ ( SR − SR* ) · √T − 1√1 − γ3 · SR + ¼ (γ4 − 1) · SR2 ]
DSR = PSR[ SR0 ]
SR0 = √V[{SRn}] · ( (1 − γ) · Z−1[ 1 − 1N ] + γ · Z−1[ 1 − 1N · e ] )

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.

Lab D · Deflated Sharpe ratio and haircut calculators

published examples · editable

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.

Deflated Sharpe ratio, Bailey and López de Prado (2014)

annual SR
periods per year q
sample length T
trials N
V[annual SR across trials]
skewness γ3
kurtosis γ4

Multiple-testing haircut, Harvey and Liu (2015)

annual SR
periods per year q
sample length T
tests N

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.

Lab steps 1. The deflated Sharpe ratio opens on the paper's example: an annual Sharpe ratio of 2.5 over five years, selected from 100 trials, with skewness −3 and kurtosis 10. The output reproduces the paper's threshold of 0.1132 per period and DSR of 0.9004, below 0.95. 2. Set N = 46. The DSR rises above 0.95, as the paper reports. Fewer trials lower the threshold. 3. Return to N = 100 and select "Normal returns". The denominator shrinks and the DSR rises. The paper reports that with Normal returns the strategy would pass after as many as 88 trials. 4. In the haircut calculator, set N = 1. With one test there is no adjustment and the haircut is zero.

6 · Non-Normal returns and drawdown

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.

In this project

How backtest.py computes the Sharpe ratio Lines 89 and 94 of 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).

Terminology

Each entry: the technical definition first, then the same idea in everyday words in the orange strip.

Sharpe ratiomean excess return divided by the standard deviation of returns, usually annualised.how much a strategy earns for each unit of risk it takes. Two strategies with the same profit: the one with the smaller swings has the higher Sharpe ratio.
differential returnthe return of a fund minus the return of a benchmark over the same period (Sharpe, 1994).how much better or worse the strategy did than the thing it is compared against.
excess returnthe return minus the risk-free return over the same period.what the strategy earned beyond what cash would have earned with no risk.
risk-free ratethe return on a riskless asset, conventionally a short-term government bill.the interest that money in the safest place would earn.
annualisationconversion of a per-period statistic to annual units: mean × q, standard deviation × √q.turning a daily number into a yearly one so that different strategies can be compared on the same scale.
IIDindependent and identically distributed: each return is drawn from the same distribution, unaffected by earlier returns.each day's return is a fresh draw from the same distribution, with no memory of yesterday.
autocorrelation ρ(k)correlation between a return and the return k periods earlier.how much today's move tends to follow (positive) or reverse (negative) the move k days ago.
variance ratiovariance of q-period returns divided by q times the variance of one-period returns; 1 for uncorrelated returns.a check on whether risk adds up over time the simple way. Above 1: moves build on each other. Below 1: moves partly cancel.
standard errorstandard deviation of an estimator across repeated samples.how much the number would change if the same strategy were tested on a different stretch of history.
t-statistican estimate divided by its standard error; for the mean return it equals SR·√T.how many standard errors the result is away from zero. Larger means less likely to be chance.
p-valueprobability, under the null hypothesis, of a test statistic at least as extreme as the one observed.the chance of getting a result this good if the strategy had no edge at all.
trialone backtested configuration of a rule and its parameters.one version of the idea that was tested. Changing a lookback from 63 to 126 days is a second trial.
selection biasinflation of a reported statistic caused by reporting only the best of several trials.showing only the best attempt makes the result look better than the method really is.
MinBTLminimum backtest length: years of data needed so that the best of N skill-less trials is not expected to exceed a given Sharpe ratio.how long the test history must be before trying N versions stops producing an impressive result by chance.
skewness γ₃third standardised moment of returns; negative when large losses are more likely than large gains of the same size.whether the bad surprises are bigger than the good ones. Negative skew: many small gains, occasional large losses.
kurtosis γ₄fourth standardised moment; 3 for the Normal distribution, higher when extreme returns are more frequent.how often very large moves happen compared with a bell curve.
DSRdeflated Sharpe ratio: the probability that the true Sharpe ratio exceeds the expected maximum of N skill-less trials, adjusted for skewness and kurtosis.the chance that the strategy is genuinely better than the best of the failures that were tested alongside it.
haircutthe percentage reduction from the reported Sharpe ratio to the multiple-testing-adjusted Sharpe ratio.how much of the reported result is removed once the number of tests is taken into account.

Sources

Bailey et al.D. H. Bailey, J. M. Borwein, M. López de Prado and Q. J. Zhu, "Pseudo-Mathematics and Financial Charlatanism: The Effects of Backtest Overfitting on Out-of-Sample Performance", Notices of the AMS 61(5), 2014. Annualised Sharpe ratio (eq. 2), its asymptotic distribution (eq. 3), the expected maximum of N trials (eq. 4–5), MinBTL (eq. 6) and the five-years, 45-trials statement. Sections 1, 3 and 4.
SharpeW. F. Sharpe, "The Sharpe Ratio", Journal of Portfolio Management 21(1), Fall 1994. The ex post ratio on differential returns (eq. 3–6), the relation to the t-statistic, time aggregation under zero serial correlation (eq. 7–10), and the example of funds X and Y. Sections 1 and 2; In this project.
LoA. W. Lo, "The Statistics of Sharpe Ratios", Financial Analysts Journal 58(4), July/August 2002. Standard error under IID returns (eq. 9–10, Table 1), time aggregation with serial correlation (eq. 17–22, Table 2). Sections 2 and 3; Lab A.
Bailey and López de PradoD. H. Bailey and M. López de Prado, "The Deflated Sharpe Ratio: Correcting for Selection Bias, Backtest Overfitting and Non-Normality", Journal of Portfolio Management, 2014. Eq. 1–2 and the numerical example (N = 100, V = 1/2, T = 1250, γ₃ = −3, γ₄ = 10). Section 5 and Lab D.
Harvey and LiuC. R. Harvey and Y. Liu, "Backtesting", Journal of Portfolio Management, Fall 2015. The t-statistic and Sharpe ratio (eq. 1–2), the multiple-testing p-value and haircut Sharpe ratio (eq. 3–5) and the twenty-year, 200-test example; the caveat on non-normal returns. Sections 1, 5 and 6.
Lo and MacKinlayA. W. Lo and A. C. MacKinlay, "Stock Market Prices Do Not Follow Random Walks: Evidence from a Simple Specification Test", Review of Financial Studies 1(1), 1988. Variance linear in the observation interval (p. 44); the variance ratio as a weighted sum of autocorrelations (eq. 16). Section 2 and Lab A.
Politis and RomanoD. N. Politis and J. P. Romano, "The Stationary Bootstrap", Journal of the American Statistical Association 89(428), 1994. Resampling of blocks of random, geometrically distributed length for weakly dependent series. Section 3.

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.