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.
Maximum Drawdown (MDD) in Python
get_maximum_drawdown is part of 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 initialized 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.