Quant from Scratch by QuantWright

Backtesting Essentials · Lesson 12

The Sharpe ratio, and its error bar

Return per unit of volatility puts two results on one scale. Measured on a short backtest, that number comes with a wide error bar.

Know the basics? Read the lesson notes

Same return, different ride

A backtest runs a trading rule over past prices to see what it would have made. Here the rules are made up and a computer draws every day. Rules A and B each put $10,000 to work on every trading day of one year: 252 days. A day's return is what the day made, as a percent of that $10,000: +0.25% adds $25. Play the year.

Two rules, one year (simulated)

Colour: rule A. Dark: rule B. Dashed: the $10,000 start.

Day0 of 252
A's account$10,000
B's account$10,000

Both ended at $11,260: +12.6% for the year, or 12.6 ÷ 252 = +0.05% on the average day (they were made that way).

Volatility is the standard deviation of the returns: how far a typical day lands from the average day (lesson A8). A's daily volatility is 0.50% and B's 2.00%, four times as much. The return alone can't tell the two rules apart.

One scale for both

How much a rule makes depends on how much money it works with, which is a choice. With half of its $10,000 at work, B makes half as much every day: the year halves, and so does the volatility. Slide B's size down until its volatility matches A's.

Rule B at a smaller size (simulated)

Colour: rule A. Dark: rule B at the size you set. Grey: rule B at full size.

B's year+12.6%
B's daily volatility2.00%
B's average day ÷ volatility0.025

At a quarter of its size B swings as much as A, 0.50% a day, and made 3.15% where A made 12.6%.

Dividing the average return by the volatility says the same. A: 0.05 ÷ 0.50 = 0.10. B: 0.05 ÷ 2.00 = 0.025 at every size, because the size multiplies both alike. This is the Sharpe ratio, return per unit of volatility: one scale for rules of any size.

One thing comes off the return first: the risk-free rate, what money earns with next to no risk, such as interest on cash. This lesson sets it to 0: its returns are made up, so read each as a return above that rate already.

Theory

The Sharpe ratio

The Sharpe ratio is a rule's average return above the risk-free rate, divided by the standard deviation of its returns.

It is usually annualised: quoted per year. A year's return is the total of 252 days: 252 times the average day. If one day's return doesn't change the next day's, the standard deviation of that total is only √252 times one day's, because up days and down days partly cancel (a +1 and a −1 total 0: lesson A8). So the yearly ratio is 252 ÷ √252 = √252 ≈ 15.87 times the daily one.

For the precise√252 is for daily returns. Other periods use the square root of their own count in a year: √12 for monthly returns.
S = (μ − rf) ÷ s
Syear = S × √252
μ
"mu", the average return per period (a day, in this lesson)
rf
the risk-free rate over the same period (0 in this lesson)
s
the sample standard deviation of the returns, dividing by n − 1 (lesson A8): the volatility
S
the Sharpe ratio per period: a daily one from daily returns
Syear
the annualised Sharpe ratio, from daily returns that are independent, with the same average and volatility all year
Worked example: five made-up days

Five days return +3%, −1%, +3%, −1% and +1%. Average: (3 − 1 + 3 − 1 + 1) ÷ 5 = 1%. Distances from it: +2, −2, +2, −2, 0. Their squares add up to 4 + 4 + 4 + 4 + 0 = 16. 16 ÷ (5 − 1) = 4, and √4 = 2%: the volatility. So S = (1 − 0) ÷ 2 = 0.5 a day.

Holds when
  • the risk-free rate covers the same period as the returns;
  • for the yearly figure: the days are independent (one day's return doesn't change the next day's), with the same average and volatility all year.
Breaks when

One day's return depends on the day before (lesson C1, Time series basics): × √252 then gives the wrong yearly figure.

New numbers. A rule averaged +0.07% a day with a daily volatility of 1.2%, while cash earned 0.01% a day. What is its yearly Sharpe ratio?

Take the risk-free rate off, then divide by the volatility: (0.07 − 0.01) ÷ 1.2 = 0.06 ÷ 1.2 = 0.05 a day. Then annualise: 0.05 × 15.87 = 0.79.

One rule, five backtests

Now take a rule built so that its true Sharpe ratio, the one it would show over endless days, is known. Each day is drawn from a bell curve (most days near the average, few far out: lesson A5) with an average of +0.063% and a volatility of 1%, whatever the day before did. Its true daily Sharpe ratio is 0.063 ÷ 1 = 0.063, and its true yearly one 0.063 × 15.87 = 1.00.

A one-year backtest sees 252 such days and works out a Sharpe ratio from them. Run five.

One rule, one year at a time (simulated)

Colour: the latest backtest. Grey: the ones before it. Dashed: the $10,000 start.

Backtest0 of 5
Ended at–
Measured Sharpe ratio–

Five backtests of one rule measured yearly Sharpe ratios of 2.1, 0.5, 0.4, 1.3 and 0.0. The rule never changed: its true Sharpe ratio was 1.00 every time.

The gap comes from which days a backtest happened to get: sampling error (lesson B5).

1,000 backtests of one rule

Guess first. In 1,000 one-year backtests of this rule, most of the measured Sharpe ratios will land within how far of the true 1.00?

1,000 one-year backtests of one rule (simulated)

Each column counts the backtests in a range 0.25 wide. Dashed: the true 1.00. Shaded: the band you picked.

Your guess:
Backtests run0
Lowest · highest–
Inside the band–

The three bands held 74, 370 and 949 of the 1,000 backtests. The lowest measured −2.15 and the highest 4.48, and 168 measured a Sharpe ratio below zero for a rule whose true one is 1.00.

Their standard deviation is 1.03. The standard deviation of a measured number is its standard error (lesson B5): how far luck typically moves it.

Shorter and longer backtests

The same rule, in 1,000 backtests of 50 days and 1,000 of 2,000 days, about eight years. Guess first: of the 1,000 backtests of 50 days, how many measure a Sharpe ratio below zero? Then look at both lengths.

1,000 backtests of each length (simulated)

Dashed: the true 1.00.

Your guess:
Length:
Standard error–
Lowest · highest–
Below zero–

Over 50 days the standard error was 2.31, and 345 of the 1,000 backtests were below zero. Over 2,000 days it was 0.36, and 2 were below zero.

A longer backtest holds more days, so more of the luck cancels.

Theory

The standard error of a Sharpe ratio

You get one backtest, not 1,000. For independent returns drawn from one bell curve, the standard error of a measured Sharpe ratio follows from the Sharpe ratio and the number of returns. The error bar is lesson B5's 95% confidence interval: 1.96 standard errors either side, a range from a method that catches the true value about 95 times in 100.

SE ≈ √((1 + S² ÷ 2) ÷ n)
SEyear = SE × √252
error bar = Syear ± 1.96 × SEyear
n
the number of returns in the backtest (days, in this lesson)
S
the Sharpe ratio per period, not annualised: a yearly figure goes back to daily first, ÷ √252. The measured one stands in for the unknown true one
SE
the standard error of that per-period Sharpe ratio, for independent returns drawn from one bell curve and measured once
SEyear
the standard error of the annualised Sharpe ratio, from daily returns, under the same conditions
Worked example: your 1,000 one-year backtests

S = 0.063 a day and n = 252. 0.063² ÷ 2 = 0.002. (1 + 0.002) ÷ 252 = 0.003976, and √0.003976 = 0.0631. The yearly ratio is the daily one × 15.87, so its standard error is too: 0.0631 × 15.87 = 1.00, against the 1.03 you measured. With n = 50 the same sum gives 2.247 (measured: 2.31), and with n = 2,000 it gives 0.355 (measured: 0.36).

The S² ÷ 2 is there because the volatility is itself an estimate. For daily returns it is tiny, so SE is close to 1 ÷ √n: four times the days, half the bar.

Holds when
  • each return is independent of the ones before it;
  • the returns are all drawn from one bell curve: the same average and volatility throughout;
  • there are enough returns: the formula is approximate, and rougher for few;
  • the backtest was run once, as planned, not picked as the best of several.
Breaks when

One day's return depends on the day before, as when each return is an average over several days (lesson C1, Time series basics). A rule has rare large losses (lesson A6, Fat tails). The backtest was picked from many, so it is not one measurement (lesson B7, The best of many). Two steps on, the lesson counts all three.

New numbers. A backtest of 400 days measured a daily Sharpe ratio of 0.08. What is the standard error of its yearly Sharpe ratio?

0.08² ÷ 2 = 0.0032. (1 + 0.0032) ÷ 400 = 0.002508, and √0.002508 = 0.0501. Per year: 0.0501 × 15.87 = 0.795, about 0.80.

1.5 on 50 days, or 1.0 on 2,000?

Two rules, one backtest each. The first measured a yearly Sharpe ratio of 1.5 over 50 days, the second 1.0 over 2,000 days. Which is the better rule? Guess, then see their error bars.

Two measured Sharpe ratios with their 95% error bars

Your guess:

The formula takes the daily Sharpe ratio, so the yearly 1.5 goes back to daily first: 1.5 ÷ 15.87 = 0.0945. Then 0.0945² ÷ 2 = 0.0045, (1 + 0.0045) ÷ 50 = 0.02009, √0.02009 = 0.1417, and 0.1417 × 15.87 = 2.249 a year. The error bar reaches 1.96 × 2.249 = 4.41 either side of 1.5: from −2.91 to 5.91.

If your own sum gives 3.27 for that standard error, you put the yearly 1.5 into the formula: divide by 15.87 first.

The second, the same way with n = 2,000: 0.355 a year, so its bar reaches 1.96 × 0.355 = 0.70: from 0.30 to 1.70.

The first bar holds zero, and the whole of the second bar. Now a count, for a rule with nothing in it: the same bell-curve days with an average of 0%, a true Sharpe ratio of 0.

A rule with nothing in it (simulated)

The rule with nothing in it measured 1.5 or more in 247 of its 1,000 backtests of 50 days, and 1.0 or more in 5 of its 1,000 backtests of 2,000 days.

So the two numbers do not show that the first rule is better: the 0.5 between them is far inside the first bar, and in this simulation a rule with nothing in it reached the first result far more often than the second. This is for independent, bell-curve days and one backtest of each rule.

For the preciseThe second rule's sum in full: 1.0 ÷ 15.87 = 0.063 a day. 0.063² ÷ 2 = 0.002. 1.002 ÷ 2,000 = 0.000501, √0.000501 = 0.0224, and 0.0224 × 15.87 = 0.355. Standard errors that go into an error bar are carried to three decimals. Set side by side 1,000 times, a 50-day backtest of the rule with nothing in it measured a higher Sharpe ratio than a 2,000-day backtest of the rule with a true 1.00 in 323 pairs.

Three ways to a high Sharpe ratio

A Sharpe ratio sees an average and a standard deviation, nothing else. In this simulation the rule with nothing in it, backtested once over one year, measured 2.0 or more in 28 of 1,000 backtests. Three things raise such a count. Look at all three.

1,000 one-year backtests of each (simulated)

Columns as before. Colour: measured 2.0 or more. Dashed: the true Sharpe ratio.

True Sharpe ratio–
Average measured–
Measured 2.0 or more–

The best of 20. Backtest the rule with nothing in it 20 times and keep the best, as a search does (lesson B7). The kept backtests averaged 1.86, and 361 of the 1,000 measured 2.0 or more. Run over one more year, the kept ones averaged 0.03.

A rare large loss. On an ordinary day this rule makes +0.05% on average, with a volatility of 0.2%. On 1 day in 250, on average, it loses 12.45%, which makes its true average day 0%. In 338 of its 1,000 backtests the year held no such day, and those measured 3.98 on average. In all, 331 of the 1,000 measured 2.0 or more.

Smoothed returns. Take the rule with a true 1.00 and let each day report the average of its last five days' returns, for example when prices are updated late. The average day barely moves and the swings shrink: the smoothed backtests measured 2.21 on average, against 0.97 for the same days unsmoothed, and 517 of the 1,000 measured 2.0 or more, against 144 unsmoothed.

The error bar fails with them: where a 95% bar should hold the true value about 950 times in 1,000, it held the true 0 in 617 of the best-of-20 backtests and 668 of the rare-loss ones, and the rule's true 1.00 in 592 of the smoothed ones.

And a standard deviation counts days above and below the average alike, so the ratio cannot tell a large loss from a large gain of the same size.

For the preciseAround the plain one-year backtests of the rule with a true 1.00, the error bar held the true value in 946 of 1,000. The rare loss: 249 days in 250 are ordinary, a chance of 0.996, and 0.996 × 0.05 = 0.0498%. The loss takes 0.004 × 12.45 = 0.0498%, which leaves an average of 0%. All 331 rare-loss backtests that measured 2.0 or more were among the 338 with no large loss; the 662 with one or more averaged −0.34. A loss and a gain of the same size: five days of +2%, +2%, +2%, +2% and −3%, and five of 0%, 0%, 0%, 0% and +5%, both average 1% with a volatility of 2.24%, so both have a daily Sharpe ratio of 1 ÷ 2.24 = 0.45. The textbook names: a return that depends on the one before it is autocorrelation, and the smoothed days have it, because neighbours share four of their five days. More extreme days than a bell curve are fat tails, and extreme days that fall on one side are skew; the rare loss is both.

What this means for your backtest

  1. A Sharpe ratio is a measured number.

    Read it with the number of returns behind it and its error bar: about 2 either side for one year of independent, bell-curve days.

Practice 1 of 2

"A Sharpe ratio above 3"

The situationAn imagined sales page says: "Sharpe ratio above 3 in our first three months." The small print: 63 daily returns, with a daily Sharpe ratio of 0.2.

How far either side of the yearly Sharpe ratio does the 95% error bar reach?

Hint: SE ≈ √((1 + S² ÷ 2) ÷ n) with S = 0.2 and n = 63. Multiply by 15.87 for the yearly standard error, then by 1.96.

0.2² ÷ 2 = 0.02. (1 + 0.02) ÷ 63 = 0.01619, and √0.01619 = 0.1272. Per year: 0.1272 × 15.87 = 2.019, and 1.96 × 2.019 = 3.96. The yearly Sharpe ratio is 0.2 × 15.87 = 3.17, so the bar runs from 3.17 − 3.96 = −0.79 to 3.17 + 3.96 = 7.13. Zero is inside it.
Practice 2 of 2

Your own two rules

The situationYour own research, one backtest of each rule. Rule P measured a yearly Sharpe ratio of 2.4 over 42 days. Rule Q measured 0.9 over 1,512 days, six years. By the formula, P's 95% error bar runs from −2.43 to 7.23 and Q's from 0.10 to 1.70.

What do the two numbers tell you?

The 1.5 between them is well inside P's bar, which runs from −2.43 to 7.23 and holds zero.
A longer backtest makes Q's number better measured, not higher. P's true Sharpe ratio could still be above Q's, or below zero.
P's bar holds zero and all of Q's bar, so P's true Sharpe ratio could be above Q's or below zero. Q's bar does stay above zero, if its days are independent and the rule was not picked from many.
✓

Lesson done

The Sharpe ratio is a rule's average return above the risk-free rate, divided by the standard deviation of its returns. Measured on a backtest it is an estimate. For independent returns drawn from one bell curve and measured once, its standard error is about √((1 + S² ÷ 2) ÷ n) per period, so a short backtest gives a wide error bar: in this lesson's simulation a rule with a true Sharpe ratio of 1.00 measured from −2.15 to 4.48 over one year. Two Sharpe ratios can differ by luck alone.

Key ideas

Sharpe ratio
the average return above the risk-free rate, divided by the standard deviation of the returns: return per unit of volatility
Risk-free rate
what money earns with next to no risk, such as interest on cash
Annualised Sharpe ratio
the Sharpe ratio per year: the daily one × √252, for independent days with the same average and volatility all year
Standard error of a Sharpe ratio
how far luck typically moves a measured Sharpe ratio: about √((1 + S² ÷ 2) ÷ n) per period, for independent returns drawn from one bell curve and measured once
Smoothed returns
returns that each report an average over several days: the swings shrink, pushing the measured Sharpe ratio away from zero (up in 843 of 1,000 backtests in the lesson's simulation, down in 157)

Formulas

S = (μ − rf) ÷ s · Syear = S × √252

SE ≈ √((1 + S² ÷ 2) ÷ n) · SEyear = SE × √252

error bar = Syear ± 1.96 × SEyear

S in the standard error is per period. Every line needs independent returns with the same average and volatility throughout; the standard error also needs one bell curve and one backtest, not picked.

Lesson notes

The Sharpe ratio divides a rule's average return above the risk-free rate (what money earns with next to no risk) by the standard deviation of its returns, which puts results of different sizes on one scale. Measured on a backtest it is an estimate. Its standard error, how far luck typically moves it, is about √((1 + S² ÷ 2) ÷ n) per period for enough independent returns drawn from one bell curve, measured once. So a short backtest leaves a wide error bar (the range that should hold the true value about 95 times in 100), and two Sharpe ratios can differ by luck alone. Every count below is from the lesson's simulation, in which a computer draws every day.

Why return alone can't compare two results

A backtest runs a trading rule over past prices to see what it would have made, and a day's return is what the day made, in percent. Two made-up rules, A and B, each put $10,000 to work on every one of 252 trading days, one year. Both were made to end at $11,260: +12.6% for the year, or 12.6 ÷ 252 = +0.05% on the average day. Volatility is the standard deviation of the returns, how far a typical day lands from the average day (lesson A8): 0.50% a day for A and 2.00% for B, four times as much.

How much a rule makes depends on how much money it works with, which is a choice. At a quarter of its size B has A's volatility and makes 3.15% in the year against A's 12.6%. Dividing the average return by the volatility says the same: 0.05 ÷ 0.50 = 0.10 a day for A, and 0.05 ÷ 2.00 = 0.025 a day for B at any size, because the size multiplies both alike. That number is the Sharpe ratio: return per unit of volatility.

The risk-free rate and the yearly figure

One thing comes off the return first: the risk-free rate, what money earns with next to no risk, such as interest on cash. The lesson sets it to 0: its returns are made up, so each can be read as a return above that rate already. A Sharpe ratio is usually annualised, quoted per year. A year's return is the total of 252 days, 252 times the average day. If the days are independent (one day's return doesn't change the next day's), with the same average and volatility all year, the standard deviation of that total is only √252 times one day's, because up days and down days partly cancel: a +1 and a −1 total 0. So the yearly Sharpe ratio is 252 ÷ √252 = √252 ≈ 15.87 times the daily one.

A measured Sharpe ratio is an estimate

Next, a rule whose true Sharpe ratio, the one it would show over endless days, is known. Every day is drawn from a bell curve (most days near the average, few far out) with an average of +0.063% and a volatility of 1%, whatever the day before did: a true daily Sharpe ratio of 0.063 and a true yearly one of 0.063 × 15.87 = 1.00. Five one-year backtests of this one rule measured yearly Sharpe ratios of 2.1, 0.5, 0.4, 1.3 and 0.0. The gap comes from which days a backtest happened to get: sampling error (lesson B5).

Across 1,000 one-year backtests in this simulation, the measured yearly Sharpe ratios ran from −2.15 to 4.48; 949 landed within 2 of the true 1.00 and 168 were below zero. Their standard deviation was 1.03. The standard deviation of a measured number is its standard error (lesson B5): how far luck typically moves it. Over 50 days the same rule's yearly Sharpe ratio had a standard error of 2.31, with 345 of 1,000 backtests below zero. Over 2,000 days, about eight years, it had one of 0.36, with 2 of 1,000 below zero. A longer backtest holds more days, so more of the luck cancels.

Is 1.5 on 50 days better than 1.0 on 2,000?

Two rules, one backtest each: the first measured a yearly Sharpe ratio of 1.5 over 50 days and the second 1.0 over 2,000 days. The error bar is the 95% confidence interval of lesson B5, 1.96 standard errors either side: a range from a method that catches the true value about 95 times in 100. The standard-error formula below takes the daily Sharpe ratio, so each yearly figure goes back to daily first (÷ 15.87). That gives the first a yearly standard error of 2.249 and a bar from −2.91 to 5.91, and the second a yearly standard error of 0.355 and a bar from 0.30 to 1.70. The first bar holds zero and the whole of the second bar.

In the simulation a rule with nothing in it (the same bell-curve days with an average of 0%, a true Sharpe ratio of 0) measured a yearly Sharpe ratio of 1.5 or more in 247 of 1,000 backtests of 50 days, and 1.0 or more in 5 of 1,000 backtests of 2,000 days. So the two numbers do not show that the first rule is better: the 0.5 between them is far inside the first bar, and a rule with nothing in it reached the first result far more often than the second. This is for independent, bell-curve days and one backtest of each rule.

What a Sharpe ratio can't see

A Sharpe ratio sees an average and a standard deviation, nothing else. In the simulation the rule with nothing in it, backtested once over one year, measured a yearly Sharpe ratio of 2.0 or more in 28 of 1,000 backtests. Three things raised such a count, each over 1,000 one-year backtests.

The best of 20. The rule with nothing in it was backtested 20 times and the best backtest kept, as a search does (lesson B7). The kept backtests averaged 1.86 and 361 of 1,000 measured 2.0 or more; run over one more year, the kept ones averaged 0.03. A rare large loss. A rule that makes +0.05% on an ordinary day on average, with a volatility of 0.2%, and on 1 day in 250, on average, loses 12.45%, has a true average day of 0%. In 338 of its 1,000 backtests the year held no such day, and those measured 3.98 on average; in all, 331 of the 1,000 measured 2.0 or more. Smoothed returns. When each day reports the average of its last five days' returns, for example when prices are updated late, the average day barely moves and the swings shrink. For the rule with a true 1.00, the smoothed backtests measured 2.21 on average against 0.97 for the same days unsmoothed, and 517 of 1,000 measured 2.0 or more, against 144 unsmoothed.

The formula's error bar failed on all three. Where a 95% bar should hold the true value about 950 times in 1,000, in the simulation it held the true 0 in 617 of the 1,000 best-of-20 backtests and 668 of the 1,000 rare-loss ones, and the rule's true 1.00 in 592 of the 1,000 smoothed ones. For a picked backtest the lesson gives that count, not a correction. The corrections for a short backtest and for the number of versions tried, the Probabilistic Sharpe ratio and the Deflated Sharpe ratio (Bailey and López de Prado), are taught in lesson C5, Many tests at once. And a standard deviation counts days above and below the average alike, so the ratio cannot tell a large loss from a large gain of the same size.

Formula: the Sharpe ratio

The Sharpe ratio is the average return above the risk-free rate, divided by the standard deviation of the returns. The annualised figure, from daily returns, is the daily one times √252.

S = (μ − rf) ÷ s
Syear = S × √252
μ
"mu", the average return per period (a day, in this lesson)
rf
the risk-free rate over the same period (0 in this lesson)
s
the sample standard deviation of the returns, dividing by n − 1 (lesson A8): the volatility
S
the Sharpe ratio per period: a daily one from daily returns
Syear
the annualised Sharpe ratio, from daily returns that are independent, with the same average and volatility all year
Worked example: five made-up days

Five days return +3%, −1%, +3%, −1% and +1%. Average: (3 − 1 + 3 − 1 + 1) ÷ 5 = 1%. Distances from it: +2, −2, +2, −2, 0. Their squares add up to 4 + 4 + 4 + 4 + 0 = 16. 16 ÷ (5 − 1) = 4, and √4 = 2%: the volatility. With a risk-free rate of 0, S = (1 − 0) ÷ 2 = 0.5 a day.

Holds whenBreaks when

One day's return depends on the day before (lesson C1, Time series basics): × √252 then gives the wrong yearly figure. The lesson's smoothed returns are one such case.

Formula: the standard error of a Sharpe ratio

For independent returns drawn from one bell curve, the standard error of a measured Sharpe ratio follows from the Sharpe ratio and the number of returns. The error bar reaches 1.96 standard errors either side.

SE ≈ √((1 + S² ÷ 2) ÷ n)
SEyear = SE × √252
error bar = Syear ± 1.96 × SEyear
n
the number of returns in the backtest (days, in this lesson)
S
the Sharpe ratio per period, not annualised: a yearly figure goes back to daily first, ÷ √252. The measured one stands in for the unknown true one
SE
the standard error of that per-period Sharpe ratio, for independent returns drawn from one bell curve and measured once
SEyear
the standard error of the annualised Sharpe ratio, from daily returns, under the same conditions
Worked example: the lesson's backtests, then a yearly figure

One year of the rule with a true 1.00: S = 0.063 a day and n = 252. 0.063² ÷ 2 = 0.002. (1 + 0.002) ÷ 252 = 0.003976, and √0.003976 = 0.0631. The yearly ratio is the daily one × 15.87, so its standard error is too: 0.0631 × 15.87 = 1.00, against the 1.03 measured across the simulation's 1,000 one-year backtests. With n = 50 the same sum gives 2.247 (measured: 2.31), and with n = 2,000 it gives 0.355 (measured: 0.36).

From a yearly figure: a yearly Sharpe ratio of 1.5 measured over 50 days goes back to daily first, 1.5 ÷ 15.87 = 0.0945. Then 0.0945² ÷ 2 = 0.0045, (1 + 0.0045) ÷ 50 = 0.02009, √0.02009 = 0.1417, and 0.1417 × 15.87 = 2.249 a year. The error bar reaches 1.96 × 2.249 = 4.41 either side of 1.5: from −2.91 to 5.91.

The S² ÷ 2 is there because the volatility is itself an estimate. For daily returns it is tiny, so SE is close to 1 ÷ √n: four times the days, half the bar.

Holds whenBreaks when

One day's return depends on the day before, as when each return is an average over several days (lesson C1, Time series basics). A rule has rare large losses (lesson A6, Fat tails). The backtest was picked from many, so it is not one measurement (lesson B7, The best of many). In the lesson's simulation the bar then held the true value in 592, 668 and 617 of 1,000 backtests, where about 950 is what a 95% bar should do.

One more worked example

Made-up numbers

A backtest of 1,008 days, four years: +0.10% on the average day, a daily volatility of 1.0%, cash at 0.02% a day. Daily Sharpe ratio: (0.10 − 0.02) ÷ 1.0 = 0.08. Yearly: 0.08 × 15.87 = 1.27. Standard error: 0.08² ÷ 2 = 0.0032, (1 + 0.0032) ÷ 1,008 = 0.000995, √0.000995 = 0.0315, and 0.0315 × 15.87 = 0.500 a year. Error bar: 1.96 × 0.500 = 0.98 either side, from 1.27 − 0.98 = 0.29 to 1.27 + 0.98 = 2.25. Zero is outside the bar, if the days are independent and drawn from one bell curve and the backtest was run once, not picked.

Common mistakes

Check yourself

  1. Three days return +1%, +5% and +3%, and the risk-free rate is 0. What is the daily Sharpe ratio?
    Answer

    Average: (1 + 5 + 3) ÷ 3 = 3%. Distances: −2, +2, 0. Squares: 4, 4, 0, which add up to 8. 8 ÷ (3 − 1) = 4, and √4 = 2%, the volatility. S = (3 − 0) ÷ 2 = 1.5 a day.

  2. A rule averaged +0.03% a day with a daily volatility of 0.75%, and the risk-free rate is 0. What is its yearly Sharpe ratio, and what does the yearly figure assume?
    Answer

    0.03 ÷ 0.75 = 0.04 a day, and 0.04 × 15.87 = 0.63 a year. The × √252 step assumes independent days (one day's return doesn't change the next day's) with the same average and volatility all year.

  3. A backtest of 100 days measured a yearly Sharpe ratio of 1.6. What is its 95% error bar, and is zero inside it?
    Answer

    Back to daily first: 1.6 ÷ 15.87 = 0.1008. Then 0.1008² ÷ 2 = 0.0051, (1 + 0.0051) ÷ 100 = 0.010051, √0.010051 = 0.1003, and 0.1003 × 15.87 = 1.592 a year. The bar reaches 1.96 × 1.592 = 3.12 either side: from 1.6 − 3.12 = −1.52 to 1.6 + 3.12 = 4.72. Zero is inside, by the formula, which needs independent, bell-curve days and one backtest run once.

  4. (from lesson A8) One day's return has a standard deviation of 1.5%. What is the standard deviation of a year's total return, over 252 days? The standard deviation of a total of 252 independent days is one day's × √252, and √252 ≈ 15.87.
    Answer

    1.5 × 15.87 = 23.81%, if the days are independent with the same volatility all year. Up days and down days partly cancel, so it is not × 252.

Try it yourself

Run the script. Every number in this lesson comes from one Python script (below). It makes rules A and B, draws 1,000 backtests of each kind, works out every Sharpe ratio, and counts. Change the length of a backtest, the true Sharpe ratio, the number of versions the search keeps the best of, the size of the rare loss, or the number of days the smoothing averages, and see what moves.

By hand, in a spreadsheet. Put a list of daily returns in column A, one a row. =AVERAGE(A:A) gives the average day and =STDEV.S(A:A) the sample standard deviation. Take the risk-free rate for one day off the average, divide by the standard deviation, and multiply by =SQRT(252): that is the yearly Sharpe ratio. For the error bar, with the daily Sharpe ratio in D1 and the number of days in D2, the yearly standard error is =SQRT((1+D1^2/2)/D2)*SQRT(252).

The code behind every number (Python, numpy; seed 2026111200)
Loading…

Going further: time, other periods, and the corrections

What narrows the bar is time. Put the two formulas together for a backtest that covers a number of years. The yearly standard error squared comes to 1 ÷ years + Syear² ÷ (2 × n), and for daily returns the second part is tiny. So the standard error of a yearly Sharpe ratio is close to 1 ÷ √years: 1.00 for one year, 0.50 for four and 0.35 for eight, under the formula's conditions. Counting returns more often barely helps. Take eight years as 96 monthly returns with a yearly Sharpe ratio of 1.0: a year holds 12 months, so the monthly one is 1.0 ÷ √12 = 1.0 ÷ 3.46 = 0.289. Then 0.289² ÷ 2 = 0.0418, 1.0418 ÷ 96 = 0.010852, √0.010852 = 0.1042, and 0.1042 × 3.46 = 0.36, the same as for 2,000 daily returns. By the same formula, at a yearly Sharpe ratio of 1.0, eight years cut into 50 returns give a standard error of 0.37 on it, and the same eight years cut into 2,000 returns give 0.35.

Why smoothing raises the number. The average of five independent days has a volatility of 1 ÷ √5 of one day's, and √5 = 2.24. In the simulation the smoothed returns' volatility averaged 0.44 of the unsmoothed returns', and the measured Sharpe ratio rose by about that factor, 2.21 against 0.97. The smoothed days lean on each other, because neighbours share four of their five days. That is autocorrelation, and it is why × √252 gave the wrong yearly figure. The smoothed Sharpe ratio was the higher one in 843 of the 1,000 backtests and the lower one in 157: smoothing pushes a measured Sharpe ratio away from zero in whichever direction it already points.

The best of 20, in more detail. The lowest of the 1,000 kept Sharpe ratios was 0.62 and the highest 3.71; 974 were 1.0 or more. In the year after, the same rule measured lower than its kept backtest 949 times in 1,000.

The rare large loss, in more detail. The 662 backtests whose year held at least one large loss measured −0.34 on average, and the highest of them 0.62. Of the 338 with no such day, the error bar caught the true 0 in 7.

The corrections. The Probabilistic Sharpe ratio asks how likely it is that the true Sharpe ratio is above a chosen level, given the length of the backtest and the shape of its returns. The Deflated Sharpe ratio raises that level to allow for the number of versions tried. Lesson C5, Many tests at once, works through both.

Pairs. Set side by side 1,000 times, a 50-day backtest of the rule with nothing in it measured a higher Sharpe ratio than a 2,000-day backtest of the rule with a true 1.00 in 323 pairs.

Honest notes

Where this comes from