Compute maximum drawdown in one pass
Asked at Millennium, Citadel
Maximum drawdown is the largest percentage drop from a running peak to a subsequent trough of an equity curve:
where is the equity at time (assume all values positive).
equity = [100, 120, 90, 105, 60, 80]
-> 0.5 # peak 120 down to trough 60
Return the maximum drawdown as a fraction, in time and space. The naive all-pairs scan is .
Show a hint
This is the mirror image of "max profit from a single trade": there you buy at the low before selling; here you peak before the trough.
Your answer
This one is open-ended. Work it through, then check your reasoning against the full solution.