All problems
Rolling Max Drawdown
Problem
Compute the rolling maximum drawdown with window size k: for each window, the largest peak-to-trough decline (peak - price) / peak seen in chronological order.
Return an empty list if k is not positive or exceeds the series. A window that only makes new highs produces 0.0.
Hint
Track the running peak inside each window, not the window maximum.
Test cases
case 1
in: [[1,2,3],3]
expected: [0]
case 2
in: [[3,2,1],3]
expected: [0.6666666666666666]
case 3
in: [[1,5,2,6],3]
expected: [0.6,0.6]
case 4
in: [[2,1,2,1],2]
expected: [0.5,0,0.5]
Starter codePython
def rolling_max_drawdown(prices, k):
# Your code here
pass4 test cases · run your code against them in the editor