LIVE
connecting to the live quote stream…
--:--:--UTC
easyFinance○
#10

Max drawdown

easyFinanceacceptance —~10 min

Implement max_drawdown(equity) — the largest peak-to-trough decline of an equity curve as a positive fraction of the peak: the maximum over time of (running_peak - value) / running_peak.

It is the number that ends careers before the Sharpe ratio gets a chance to. Note the running peak: a new high resets where the fall is measured from. Return the fraction rounded to 4 decimal places.

example 1
input
equity=[100.0, 95.0, 90.0, 97.0, 99.0]
output
0.1
example 2
input
equity=[100.0, 110.0, 120.0, 96.0, 105.0]
output
0.2
note

The peak is 120, not 100 — the fall to 96 is 20%.

constraints
  • 2 ≤ len(equity) ≤ 10_000
  • every value > 0
teacher · 2 hints · the first is free
↗ read the theory
the chapter this problem is cut from
●solution.py· utf-8 · spaces:4
ln 1, col 1tab indent · esc leave editor
python 3.13 · pyodide
+ 6 hidden on submit
input · keyword arguments to max_drawdown()
equity=[100.0, 95.0, 90.0, 97.0, 99.0]
expected
0.1

the judge calls max_drawdown() with exactly these inputs · outputs are compared to 6 decimal places

● standing bypython 3.13 in your browser · pyodide 0.28.3 · judged on the server to 6 dp⌘↵ run · ⌘⇧↵ submit
paper only · educational · not advice