1

I wish to work out the top 5 drawdowns of an equity curve. Max drawdown is the measure of the largest negative return.

please see Start, End and Duration of Maximum Drawdown in Python

drawdown is defined by drawdown = cummax - cummax.cummax()

Now, im going to use the code from the above, (because I don't know how to follow up on a post), and so lets derive a series, xs

n = 1000
xs = np.random.randn(n).cumsum()

Now we can calculate the period at which we have a peak to trough

i = np.argmax(np.maximum.accumulate(xs) - xs) # end of the period
j = np.argmax(xs[:i]) # start of period

And plot the reults

plt.plot(xs)
plt.plot([i, j], [xs[i], xs[j]], 'o', color='Red', markersize=10)

This is the code from the link. Not my own, but it is suitable for now.

Now, this code will show us the max drawdown only, but I wanted to do the same for the top 5 drawdowns; is this possible? i.e. I not only wanted to locate the arg max, but the top 5 argmax's

Whilst this link is relevant, it only focus' on the single largest drawdown, not the largest five Calculate max draw down with a vectorized solution in python

Mad Physicist
  • 107,652
  • 25
  • 181
  • 264
Junaid Mohammad
  • 457
  • 1
  • 6
  • 18
  • This may be useful: https://stackoverflow.com/questions/36750571/calculate-max-draw-down-with-a-vectorized-solution-in-python/36750741#36750741 – Alexander Sep 21 '18 at 17:24
  • are you looking for `np.argpartition`? – Mad Physicist Sep 21 '18 at 18:00
  • After calculating the maximum drawdown of the current time series as well as the start date and end date, drop this drawdown period and connect the two endpoints into a new time series. Then recalculate the drawdown of this new time series, and so on. Remember to use return time series to make sure the two endpoints can be connected. Otherwise the drawdown will be miscalculated if you use level price. – Jason Cui Feb 28 '19 at 21:15

0 Answers0