Bootstrap Statistics
Calculate how much the performance statistics of the history could have differed by chance: the distribution of the cumulative and annualized return, the volatility, the Sharpe ratio and the maximum drawdown over simulated histories drawn from the daily returns (a bootstrap).
Every simulation draws a history of as many daily returns as the date range holds:
- Resampling draws the returns with replacement (Efron’s bootstrap), so a day can appear several times or not at all and every statistic varies across resamples, as pyfolio does.
- Shuffling puts the same returns in a random order (a permutation), as quantstats’ Monte Carlo does: the cumulative return, the volatility and the Sharpe ratio stay those of the history and only the path, so the maximum drawdown, varies. It shows how much of a drawdown was the order of the returns rather than their size.
For every simulation:
\[\text{Cumulative Return} = \operatorname{PRODUCT}(1 + \text{Return}) - 1\] \[\text{Annualized Return} = (1 + \text{Cumulative Return})^{\frac{P}{N}} - 1\] \[\text{Annualized Volatility} = \operatorname{STDEV}(\text{Return}) \cdot \sqrt{P}\] \[\text{Sharpe Ratio} = \frac{\operatorname{MEAN}(\text{Excess Return})}{\operatorname{STDEV}(\text{Excess Return})} \cdot \sqrt{P}\] \[\text{Maximum Drawdown} = \min\left(\frac{\text{Wealth}}{\text{Running Peak}} - 1\right),\;\; \text{the wealth starting at 1}\]Where N is the number of daily returns and P the daily returns in a year (252, or 365 for a ticker that trades on weekends such as a cryptocurrency). The excess return of each day (the return minus the daily risk-free rate) is drawn together with the return. Each statistic is summarized by the mean, the median, the standard deviation and the 5th, 25th, 75th and 95th percentiles over the resamples; the 5th to 95th percentile is a 90% bootstrap interval.
Also known as: Monte Carlo simulation, bootstrapped performance statistics, resampled returns.
Example · AAPL, MSFT · 2021 to 2025
Install the Finance Toolkit with pip install financetoolkit -U, then call get_bootstrap_statistics:
from financetoolkit import Toolkit
toolkit = Toolkit(
["AAPL", "MSFT"],
api_key="FINANCIAL_MODELING_PREP_KEY",
start_date="2021-01-01",
end_date="2025-12-31",
)
toolkit.performance.get_bootstrap_statistics()["AAPL"]
Or, with the Finance Toolkit MCP set up, ask an AI assistant such as Claude or ChatGPT:
Across bootstrapped resamples of Apple's daily returns from 2021 to 2025, what range of cumulative and annualized returns, volatility, Sharpe ratio and maximum drawdown came out?
Which returns:
| Item | Mean | Median | Std | 5% | 25% | 75% | 95% |
|---|---|---|---|---|---|---|---|
| Cumulative Return | 1.5276 | 1.1649 | 1.5579 | -0.1818 | 0.4564 | 2.1463 | 4.4302 |
| Annualized Return | 0.1738 | 0.1679 | 0.1350 | -0.0395 | 0.0785 | 0.2590 | 0.4050 |
| Annualized Volatility | 0.2780 | 0.2777 | 0.0113 | 0.2603 | 0.2703 | 0.2857 | 0.2961 |
| Sharpe Ratio | 0.5710 | 0.5736 | 0.4096 | -0.1303 | 0.2915 | 0.8507 | 1.2197 |
| Maximum Drawdown | -0.3857 | -0.3730 | 0.1035 | -0.5737 | -0.4507 | -0.3084 | -0.2412 |
5 rows
Parameters
get_bootstrap_statistics accepts the following parameters.
| Parameter | Type | Description | Example |
|---|---|---|---|
n_bootstrap | int | The number of bootstrap resamples (simulated histories). Defaults to 1000. | 1000 |
method | str | The bootstrap. Options are: “resample” (draws with replacement), “shuffle” (a random order without replacement). Defaults to “resample”. | "resample" |
seed | int | None | The seed of the random numbers, so that results can be reproduced; None draws new ones every time. Defaults to 0. | 42 |
rounding | int | None | The number of decimals to round the results to. Defaults to None, which uses the rounding of the Toolkit (4 unless set otherwise). | 2 |
show_columns | str | list[str] | None | The columns to keep, a name or a list of names, matched on every column level, or the rows when no column has those names (such as the line items of a financial statement). Names that do not exist are logged, and when none exist the result is returned in full. Defaults to None, which keeps every column. | None, which keeps every column |
References
- Paper Efron, B. (1979). “Bootstrap Methods: Another Look at the Jackknife.” The Annals of Statistics, 7(1), 1-26.
- Library Shares similar logic as pyfolio’s perf_stats_bootstrap
- Library Shares similar logic as quantstats’ montecarlo
- Library Shares similar logic as ffn’s resample_returns