Lesson 15 of 15

Bootstrapping Returns

Bootstrapping Returns

Bootstrapping is a resampling technique to estimate the sampling distribution of a statistic without making distributional assumptions. It is essential in finance for constructing confidence intervals on Sharpe ratios, means, and other metrics.

The procedure:

  1. From a sample of nn values, draw nn values with replacement → bootstrap sample
  2. Compute the statistic of interest on this bootstrap sample
  3. Repeat BB times to get a bootstrap distribution
  4. Use percentiles of this distribution for confidence intervals

Bootstrap confidence interval at level α\alpha (e.g., 0.05 for 95% CI):

  • Lower bound: α/2\alpha/2 percentile of bootstrap distribution
  • Upper bound: (1α/2)(1 - \alpha/2) percentile

Use random.choices(xs, k=len(xs)) for sampling with replacement.

Your Task

Implement:

  • bootstrap_mean(xs, n_boot, seed) — list of bootstrap sample means
  • bootstrap_ci(xs, n_boot, seed, alpha=0.05)(lower, upper) confidence interval
Python runtime loading...
Loading...
Click "Run" to execute your code.