Calculating Drawdown with Python

Felipe Cezar
1 min readJan 24, 2021

--

This is a simple and compelling metric for downside risk, especially during times of high market volatility

Drawdown measures how much an investment is down from the its past peak. They are typically quoted as a percentage drop.

Even though drawdown is not a robust metric to describe the distribution of returns of a given asset, it has a strong psychological appeal. Just like Historical VaR, it provides good insight into downside risk by indicating the magnitude of a historical price drop, from peak to trough.

Here is how you can calculate it using Python:

import pandas as pddef drawdown(return_series: pd.Series):
"""Takes a time series of asset returns.
returns a DataFrame with columns for
the wealth index,
the previous peaks, and
the percentage drawdown
"""
wealth_index = 1000*(1+return_series).cumprod()
previous_peaks = wealth_index.cummax()
drawdowns = (wealth_index - previous_peaks)/previous_peaks
return pd.DataFrame({"Wealth": wealth_index,
"Previous Peak": previous_peaks,
"Drawdown": drawdowns})

The time it takes to recover a drawdown should always be considered when assessing drawdowns.

--

--

Felipe Cezar
Felipe Cezar

Written by Felipe Cezar

Data Scientist, Economist with a background in Banking www.linkedin.com/in/felipecezar1

Responses (1)