Stress Test
Calculate how a portfolio would have fared in historical market crises: the return of every asset and of the buy-and-hold portfolio from the start to the end of each scenario, next to the benchmark. The default scenarios run from the peak to the trough of the S&P 500: the Dot-com Crash, the Global Financial Crisis, the Euro Area Debt Crisis, the 2015-2016 and 2018 Q4 sell-offs, the COVID-19 Crash and the 2022 Rate Shock.
The prices are retrieved for each scenario, so the scenarios do not have to fall within the Toolkit’s date range.
Also known as: historical scenario analysis, crisis replay, what-if analysis.
Stress Test in Python or via the MCP
Install the Finance Toolkit with:
pip install financetoolkit -U
Then call get_stress_test as shown below.
from financetoolkit import Toolkit
toolkit = Toolkit(
["AAPL", "MSFT", "JNJ", "XOM"],
api_key="FINANCIAL_MODELING_PREP_KEY",
start_date="2021-01-01",
end_date="2025-12-31",
)
toolkit.portfolio.get_stress_test()
Or, after setting up the Finance Toolkit MCP, ask:
How would an equal-weight portfolio of Apple, Microsoft, Johnson & Johnson and ExxonMobil have done in the Dot-com Crash, the Global Financial Crisis, the COVID-19 crash and the other major sell-offs, compared with the S&P 500?
Which returns:
| Scenario | Start Date | End Date | Portfolio Return | Benchmark Return | Coverage | AAPL | MSFT | JNJ | XOM |
|---|---|---|---|---|---|---|---|---|---|
| Dot-com Crash | 2000-03-24 | 2002-10-09 | -0.22 | -0.4751 | 1 | -0.8044 | -0.6061 | 0.6314 | -0.1009 |
| Global Financial Crisis | 2007-10-09 | 2009-03-09 | -0.3836 | -0.5519 | 1 | -0.504 | -0.4817 | -0.2658 | -0.2829 |
| Euro Area Debt Crisis | 2011-04-29 | 2011-10-03 | -0.0479 | -0.1861 | 1 | 0.0697 | -0.0415 | -0.0386 | -0.1812 |
| 2015-2016 Sell-off | 2015-05-21 | 2016-02-11 | -0.0673 | -0.1298 | 1 | -0.2769 | 0.0619 | 0.008 | -0.0624 |
| 2018 Q4 Sell-off | 2018-09-20 | 2018-12-24 | -0.2118 | -0.1935 | 1 | -0.3303 | -0.1676 | -0.1292 | -0.2199 |
| COVID-19 Crash | 2020-02-19 | 2020-03-23 | -0.3271 | -0.3372 | 1 | -0.3067 | -0.2739 | -0.2491 | -0.4789 |
| 2022 Rate Shock | 2022-01-03 | 2022-10-12 | 0.0017 | -0.245 | 1 | -0.2368 | -0.3212 | -0.0329 | 0.5976 |
Parameters
get_stress_test accepts the following parameters.
| Parameter | Type | Description | Example |
|---|---|---|---|
weights | dict[str, float] | None | The weight per asset. Defaults to None, which uses the latest weights of the Portfolio the Toolkit came from, or equal weights. | None, which uses the latest weights of the Portfolio the Toolkit came from, or equal weights |
scenarios | dict[str, tuple[str, str]] | None | Custom scenarios as {“name”: (“start date”, “end date”)}. Defaults to None, the scenarios above. | True |
rounding | int | None | The number of decimals to round the results to. Defaults to None, which uses the Toolkit’s rounding. | 2 |