Quant Memo
Coding/●●●●●

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:

MDD=maxijEiEjEi\text{MDD} = \max_{i \le j} \frac{E_i - E_j}{E_i}

where EiE_i is the equity at time ii (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 O(n)O(n) time and O(1)O(1) space. The naive all-pairs scan is O(n2)O(n^2).

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.

More Coding questions