Attempting to replicate "A Deep Reinforcement Learning Framework for the Financial Portfolio Management Problem" https://arxiv.org/abs/1706.10059 (and an openai gym environment)
def max_drawdown(X):
mdd = 0
peak = X[0]
for x in X:
if x > peak:
peak = x
dd = (peak - x) / peak
if dd > mdd:
mdd = dd
return mdd ```
From https://stackoverflow.com/questions/22607324/start-end-and-duration-of-maximum-drawdown-in-python
Your MDD function is incorrect.
It only finds the Max return and then the trough after that.
You might be up 10% lose 50% and then gain 1000% to lose 20%. I believe its written that it would only find that last 20% loss.
Also as per https://www.investopedia.com/terms/m/maximum-drawdown-mdd.asp
you need to divide by the peak value not the Trough
MDD = (Trough Value – Peak Value) ÷ Peak Value
I found this