Maximum Active Drawdown in python

前端 未结 3 803
孤街浪徒
孤街浪徒 2021-02-01 09:10

I recently asked a question about calculating maximum drawdown where Alexander gave a very succinct and efficient way of calculating it with DataFrame methods in pandas.

3条回答
  •  情歌与酒
    2021-02-01 09:46

    My cheap two pennies in pure Python:

    def find_drawdown(lista):
        peak = 0
        trough = 0
        drawdown = 0
        for n in lista:
            if n > peak:
                peak = n
                trough = peak
            if n < trough:
                trough = n
            temp_dd = peak - trough
            if temp_dd > drawdown:
                drawdown = temp_dd
        return -drawdown
    

提交回复
热议问题