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