Skip to content

Vault · Construct

Daily Drawdown Protection

Added
2026-01-20
Category
Construct
  • Trading
  • Risk Management
  • Python

A circuit breaker for a trading system. Once the configured daily loss threshold is reached, this class flips a flag and refuses new trades until the next UTC date. The threshold is an input, not a universal recommendation.

When to Use

  • Any automated or semi-automated trading system that needs hard risk limits
  • Enforcing daily drawdown discipline when manual willpower isn't enough
  • Position sizing pipelines where you need a kill switch before order submission

The Code

from datetime import datetime, timezone

class DailyRiskMonitor:
    """
    Halt trading if losses reach the configured threshold.
    Resets at midnight UTC.
    """
    def __init__(self, starting_equity: float, limit_percent: float):
        if starting_equity <= 0:
            raise ValueError("starting_equity must be positive")
        if not 0 < limit_percent < 100:
            raise ValueError("limit_percent must be between 0 and 100")
        self.starting_equity = starting_equity
        self.limit = limit_percent
        self.last_reset = datetime.now(timezone.utc).date()
        self.is_halted = False

    def check_drawdown(self, current_equity: float) -> bool:
        # Reset when the UTC calendar date changes.
        current_day = datetime.now(timezone.utc).date()
        if current_day > self.last_reset:
            self.starting_equity = current_equity
            self.last_reset = current_day
            self.is_halted = False

        drawdown = (self.starting_equity - current_equity) / self.starting_equity * 100
        
        if drawdown >= self.limit:
            self.is_halted = True
            
        return not self.is_halted  # True = safe to trade

Notes

Set the threshold from a written risk policy and test the behavior in a paper environment before connecting it to an order path. The timezone-aware date keeps the reset boundary in UTC instead of silently using the server's local timezone.