🎯 Architectural Philosophy: Why Autonomous Algorithmic Systems Fail in Production
Algorithmic option execution engines rarely fail due to obvious syntax mistakes; they fail at the temporal, calendar, and regulatory boundaries. When an algorithm transitions from synthetic backtests to live exchange feeds, three critical vulnerability vectors emerge:
Brokers stream ticks with variable timestamp formats (some UTC aware, some IST naive, some Unix epochs). A single unhandled subtraction between a naive and an aware timestamp throws a fatal TypeError that crashes the process mid-trade.
Hardcoding legacy assumptions (e.g. Thursday expiry or 50 lot size) causes catastrophic option mispricing, wrong strike resolution, zero gamma participation, and broker order rejections when regulatory rules change.
If an expiry falls on an exchange holiday (e.g. Dussehra or Diwali on Tuesday), contracts expire on Monday. Algorithms that do not prepone will look for non-existent contracts on Tuesday and fail to exit 0-DTE gamma positions.
📋 Complete Forensic Bug Audit & Resolution Matrix
| Subsystem | Vulnerability / Bug | Root Cause | Forensic Impact | Engineering Remedy | Status |
|---|---|---|---|---|---|
| Data Feed Watchdog | Timestamp subtraction crash | feed_watchdog.py | TypeError: can't subtract offset-naive and offset-aware datetimes. Feed watchdog crashes on live tick. | Normalize all feed timestamps using UTC-aware conversion before delta computation. | FIXED |
| Symbol Resolver | Weekly Expiry Day & Rollover | symbol_resolver.py | Legacy Thursday assumptions caused 2-day stale option selection and missed 0-DTE gamma squeeze opportunities. | Rebuilt to use ExchangeCalendar with Tuesday weekly default (1), holiday preponement, and env overrides. | FIXED |
| Risk & Sizing Engine | Lot Size Hardcoding | position_sizer.py | Hardcoding 50 caused order rejections at the broker exchange boundary for NIFTY lot size (65). | Enforced default lot size of 65 shares with dynamic configuration via config/risk.yaml and LOT_SIZE env var. | FIXED |
| Trade Management | Scaling Profile Resolution | trade_manager.py | 0-DTE Expiry Gamma profile failed to activate on Tuesday afternoons; treated Tuesday as normal 5-DTE day. | Integrated ExchangeCalendar.is_expiry_day() to trigger EXPIRY_GAMMA scaling on effective expiry days. | FIXED |
| Calendar Engine | Holiday on Expiry Day | calendar.py | If Tuesday is an exchange holiday, contracts expire on Monday. System had no holiday preponement logic. | Created ExchangeCalendar with 2025-2027 NSE holidays, preponing expiry to the previous active trading day. | FIXED |
| Trade Copier Gateway | Child Multiplier Sizing | replicator.py | Replicator used hardcoded lot size in child fan-out calculations causing fractional shares. | Integrated configurable lot_size fallback to LOT_SIZE env var and rounded strictly to nearest lot. | FIXED |