insideout Get Pro

10 · The bootstrap

Pro

Statistics and Regression, lesson 10

The bootstrap

Resampling your data to see how sure you should be.

A Sharpe ratio, a median or a model's test score has no simple formula for its standard error. The bootstrap gets one from your data alone, by drawing new samples from the one you have. You need standard errors from Samples and estimates, and intervals from Confidence intervals.

By the end, you can:

  1. Build bootstrap resamples and read a standard error from them.
  2. Read a percentile bootstrap interval for a Sharpe ratio.
  3. Spot data the plain bootstrap gets wrong, and resample in blocks instead.

Part 1. Resample your own data

Build bootstrap resamples and read a standard error from them.

For an average there's a formula, s / √n. Most numbers you'd want error bars on don't have one. The bootstrap needs no formula, so start where you can check it: five months of a simulated strategy.

Example 1.1

Five months, resampled

A strategy returned −4%, 0%, 2%, 4% and 8% over five months, an average of 2%. How far would the average of five other months typically land from it?

  1. Draw one resample8, 0, 8, −4, 2 → average 2.8

    Pick one of the five months at random, put it back, and repeat until you have five. Some months come twice, some not at all.

  2. Draw them all5⁵ = 3,125 resamples

    Each of five picks can be any of five months. A computer usually draws a few thousand. Here you can list them all.

  3. Measure their spreadsd of the 3,125 averages = 1.79

    It stands in for how far another five months' average lands.

  4. Check it by hand√(80 / 5) / √5 = 4 / 2.24 = 1.79

    The squared distances from 2% add to 80, so one pick has a spread of √(80 / 5) = 4. An average of five moves √5 times less.

  5. Compare the formulas / √n = √(80 / 4) / √5 = 2.0

    The formula divides by n − 1, so on tiny samples the bootstrap runs a little narrow.

AnswerAbout 1.8 points, close to the formula's 2.0.

You can't draw five new months from the market. The bootstrap treats your five as the best picture of the market you have, and draws from that instead. If the picture is fair, resamples vary the way new samples would.

Your five months, %−40248average 2Three resamples: pick 5, putting each back808−42→ 2.80224−4→ 0.848−482→ 3.6The averages of all 3,125 resamples−4−202468sd 1.79formula: 2.0
Figure 1Three of the 3,125 resamples of the five months, and the averages of all of them. Their spread, 1.79, is the bootstrap standard error. The orange bars at each end fall outside the middle 95%.

The bootstrap

Estimating how much a number would vary by recomputing it on many resamples: datasets the same size as yours, drawn from it with replacement, so each pick goes back before the next. The spread of the results is the bootstrap standard error.

average of n picks: √(Σ(x − x̄)² / n) / √n = 4 / √5 = 1.79

Two rules make it work. Each resample has as many points as your data, because an average's wobble depends on n. And each pick goes back: without that, every resample is your data reshuffled, and its average never moves.

Your turn

Four days returned 1%, 3%, 5% and 7%. With every possible resample drawn, what bootstrap standard error does their average get?

The average is 4%, and the squared distances add to 9 + 1 + 1 + 9 = 20. One pick has a spread of √(20 / 4) = 2.24, and an average of four picks moves √4 = 2 times less: 1.12. 1.29 is the formula's s / √n, 1.25 forgets a square root, and 2.24 is a single pick.

Part 2. Intervals with no formula

Read a percentile bootstrap interval for a Sharpe ratio.

Keep going with Pro

You've done the first part. Pro opens the rest of this lesson, and every other one.

Still to come
  1. Intervals with no formula
  2. When resampling breaks

Statistics and Regression overviewSpotted a mistake? Tell us.