Medium · Algorithms & Data Structures · Coding · ~12 min · #40
Maximum Drawdown
The maximum drawdown of a price series is the largest peak-to-trough decline, measured as a fraction of the peak:
Implement max_drawdown(prices: list[float]) -> float in a single pass. Return 0.0 for a series that never declines.
Examples
Input: max_drawdown([100, 120, 90, 130, 65])
Output: 0.5
Peak 130 falls to 65.
Input: max_drawdown([100, 110, 120])
Output: 0.0
Constraints
- •
1 ≤ len(prices) ≤ 10⁵
- •
All prices are positive.
Hints · 0 of 1 shown
Worked solution
Give the problem an honest attempt first, then reveal the full explanation.
Related questions
Concepts
Running maximumDrawdown as a risk measure
Relevant for
Quant DeveloperQuant ResearcherQuant Trader