Session Ready
Exercise

Historical drawdown

The stock market tends to rise over time, but that doesn't mean that you won't have periods of drawdown.

Drawdown can be measured as the percentage loss from the highest cumulative historical point.

In Python, you can use the .accumulate() and .maximum() functions to calculate the running maximum, and the simple formula below to calculate drawdown:

$$ \text{Drawdown} = \frac{r_t}{RM} - 1$$

  • \(r_t\): Cumulative return at time t
  • \(RM\): Running maximum

The cumulative returns of USO, an ETF that tracks oil prices, is available in the variable cum_rets.

Instructions
100 XP
  • Calculate the running maximum of the cumulative returns of the USO oil ETF (cum_rets) using np.maximum.accumulate().
  • Where the running maximum (running_max) drops below 1, set the running maximum equal to 1.
  • Calculate drawdown using the simple formula above with the cum_rets and running_max.
  • Review the plot.