""" given a list of returns, returns the maximum drawdown of the returns drawdown is calculated by taking the highest cumulative return so far, and calculating the difference of the current cumulative return from the peak the minimum of the drawdowns is max drawdown """ def max_dd(returns_list): #returns are in the form of % ex: 1.5%, 2% etc. without the % sign cumulative_returns=[] drawdown=[] cum_ret=0 for i in returns_list: cum_ret=cum_ret+i cumulative_returns.append(cum_ret) dd=cum_ret-max(cumulative_returns) drawdown.append(dd) return cumulative_returns,min(drawdown) if __name__=='__main__': test_dd=max_dd([1.1,1.1,-2,-7,25,34,-4,-3,-3,-5,1.2,-6]) print(test_dd)