wassname / rl-portfolio-management

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)
551 stars 180 forks source link

Max Draw Down incorrect #15

Closed nicktids closed 6 years ago

nicktids commented 6 years ago

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

def MDD(returns):
    """Max drawdown."""
    peak = returns.max()
    i = returns.argmax()
    trough = returns[i:].min()
    return (trough - peak) / trough

I found this


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
wassname commented 6 years ago

That sounds right, I added your function. Cheers for picking that up.