Maximum Drawdown (MDD)
Calculate the Maximum Drawdown (MDD) of an investment portfolio or asset’s returns.
Maximum Drawdown (MDD) is a risk management metric that quantifies the largest historical loss of an investment portfolio or asset experienced over a specified time horizon. It provides insights into the downside risk associated with an investment and helps investors make informed decisions about risk tolerance.
Also known as: max drawdown, peak-to-trough decline.
No programming experience? With the Finance Toolkit MCP server, AI assistants such as Claude and ChatGPT can calculate the Maximum Drawdown (MDD) for you. Just ask in plain English.
Calculate the Maximum Drawdown (MDD) in Python
The Maximum Drawdown (MDD) is available in the Risk module of the open-source Finance Toolkit. Install it with:
pip install financetoolkit -U
Then call get_maximum_drawdown as shown below.
from financetoolkit import Toolkit
toolkit = Toolkit(["AMZN", "TSLA"], api_key="FINANCIAL_MODELING_PREP_KEY")
toolkit.risk.get_maximum_drawdown()
Which returns:
| AMZN | TSLA | |
|---|---|---|
| 2012 | -0.1570 | -0.1601 |
| 2013 | -0.1259 | -0.3768 |
| 2014 | -0.2948 | -0.3085 |
| 2015 | -0.1371 | -0.2669 |
| 2016 | -0.2432 | -0.357 |
| 2017 | -0.1085 | -0.2227 |
| 2018 | -0.3410 | -0.3399 |
| 2019 | -0.1561 | -0.4847 |
| 2020 | -0.2274 | -0.6063 |
| 2021 | -0.1457 | -0.3625 |
| 2022 | -0.5198 | -0.7272 |
| 2023 | -0.1964 | -0.2823 |
Parameters
get_maximum_drawdown accepts the following parameters:
- period (str, optional): The data frequency for returns (daily, weekly, monthly, quarterly, or yearly). Defaults to “quarterly” if the Toolkit is initialised with quarterly=True, otherwise “yearly”.
- within_period (bool, optional): Whether to calculate the Maximum Drawdown within the specified period or for the entire period. Thus whether to look at the Maximum Drawdown within a specific year (if period = ‘yearly’) or look at the entirety of all years. Defaults to True.
- rounding (int | None, optional): The number of decimals to round the results to. Defaults to 4.
- growth (bool, optional): Whether to calculate the growth of the Maximum Drawdown values over time. Defaults to False.
- lag (int | list[int], optional): The lag to use for the growth calculation. Defaults to 1.
- standardize (bool, optional): Whether to standardize (Z-Score) the result. When combined with growth=True, standardizes the growth values instead of the raw values. Defaults to False.
Related Risk Metrics
The Risk module page introduces the module, and the sidebar lists all of its functions.