Development of Maximum Drawdown Control System
Maximum Drawdown (MDD) is the largest decline from peak to trough of a portfolio over a period. This is a key risk metric: a trader can survive many bad periods, but catastrophic drawdown is psychologically and financially devastating.
Drawdown Calculation
import numpy as np
def calculate_max_drawdown(equity_curve):
equity = np.array(equity_curve)
peak = np.maximum.accumulate(equity)
drawdown = (equity - peak) / peak
max_drawdown = drawdown.min()
# Find period of maximum drawdown
end_idx = drawdown.argmin()
start_idx = equity[:end_idx].argmax()
return {
'max_drawdown': max_drawdown,
'start_date_idx': start_idx,
'end_date_idx': end_idx,
'drawdown_duration': end_idx - start_idx
}
def calculate_current_drawdown(equity_history):
peak = max(equity_history)
current = equity_history[-1]
return (current - peak) / peak
System Response Levels
System works on traffic light principle:
Green (drawdown < 50% of limit): normal trading.
Yellow (50–75% of limit): warning. Reduce position size by 25%.
Orange (75–90% of limit): serious warning. Reduce size by 50%. Only high-quality signals.
Red (> 90% of limit): almost reached limit. Close half of open positions.
Stop (= 100% of limit): automatic closure of all positions. Complete trading halt until manual confirmation.
class DrawdownController:
LEVELS = [
(0.50, 'yellow', 0.75), # at 50% of limit: trade at 75% size
(0.75, 'orange', 0.50),
(0.90, 'red', 0.25),
(1.00, 'halt', 0.00)
]
def __init__(self, max_drawdown_limit=0.15):
self.limit = max_drawdown_limit
self.peak_equity = None
def update_and_check(self, current_equity):
if self.peak_equity is None or current_equity > self.peak_equity:
self.peak_equity = current_equity
current_dd = (self.peak_equity - current_equity) / self.peak_equity
dd_ratio = current_dd / self.limit # as fraction of limit
for threshold, level, size_mult in reversed(self.LEVELS):
if dd_ratio >= threshold:
return {
'level': level,
'current_dd': current_dd,
'dd_ratio': dd_ratio,
'size_multiplier': size_mult,
'halt': level == 'halt'
}
return {'level': 'green', 'size_multiplier': 1.0, 'halt': False}
Drawdown Recovery Tracking
Time to recovery: how long it took to recover from previous drawdowns. Helps assess strategy quality.
Recovery factor: total profit / maximum drawdown. Shows how much system "pays for" the risk.
Underwater chart: graph of time portfolio spent in drawdown. Important tool for trader psychological assessment.
Limit Calibration
Typical max drawdown limits by strategy type:
| Strategy Type | Recommended MDD Limit |
|---|---|
| Conservative (trend following) | 15–20% |
| Moderate (mean reversion) | 10–15% |
| Aggressive (HFT, scalping) | 5–8% |
| Market-making | 3–5% |
We develop drawdown control system with multi-level response, automatic position reduction, circuit breaker halt and recovery time reporting.







