Calculate the Maximum Drawdown Duration of an investment portfolio or asset’s returns.

The Maximum Drawdown Duration is the number of periods between the peak and the lowest point of the largest drawdown, giving insight into how long the worst loss of value took to unfold.

Also known as: drawdown length.

Maximum Drawdown Duration in Python

Install the Finance Toolkit with:

pip install financetoolkit -U

Then call get_maximum_drawdown_duration as shown below.

from financetoolkit import Toolkit

toolkit = Toolkit(["AMZN", "TSLA"], api_key="FINANCIAL_MODELING_PREP_KEY")

toolkit.risk.get_maximum_drawdown_duration()

Which returns:

  AMZN TSLA Benchmark
2021 30 28 21
2022 248 247 195
2023 25 73 63
2024 23 76 14
2025 52 57 34
2026 24 64 43

Parameters

The function 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 duration within the specified period or for the entire period. Thus whether to look at the duration 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 duration 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.
Share