Quant Python: Architecting Autonomous Trading Systems

Quant Python: Architecting Autonomous Trading Systems

Day 62 — Market Friction Modeling: Complete ExecutionDelaySimulator Workspace

Python Quant's avatar
Python Quant
Jun 24, 2026
∙ Paid

This workspace delivers a production-grade ExecutionDelaySimulator that measures real execution latency in Decimal, tracks P95/P99 percentiles without float contamination, and integrates directly with SlippageMonitor from Day 33 via a typed friction_report() contract. It makes the gap between backtest fill assumptions and live execution visible and alertable.


What You’re Building

ExecutionDelaySimulator — the measurement and simulation layer for network-induced execution delay. It sits between SignalCombiner (Day 3–5) and OrderBuilder (Day 31), intercepting the signal price and fill price to compute latency_ms and slippage_bps as exact Decimal values.

Supporting types: DelayRecord (frozen dataclass — immutable audit record), LatencyStats (Decimal accumulator for percentile tracking), DelayStatus (enum: PENDING / MEASURING / RECORDED / ANOMALY), DelayAnomalyError (exception with attached record for alerting pipelines).

This workspace extends the friction surface started in Day 33 (SlippageMonitor) and feeds directly into the reconciliation pass from Day 34 (FillAuditLog).


Complete Implementation

See day62/src/execution_delay.py in the GitHub workspace. Key design decisions:

capture_time_ms() uses Decimal(str(time.time() * 1000)) — never Decimal(time.time() * 1000). The str() path captures display precision; the direct path captures the full IEEE 754 binary encoding including sub-microsecond noise.

LatencyStats.record() rejects float input with a TypeError. This is a hard boundary. If you’re passing float latencies into stats, you have a bug upstream — the error should surface there, not silently contaminate your P95.

friction_report() returns dict[str, Decimal | int] — all values typed, no floats. Designed to drop directly into SlippageMonitor.ingest_delay_report() without transformation.

User's avatar

Continue reading this post for free, courtesy of Python Quant.

Or purchase a paid subscription.
© 2026 Python Quant · Privacy ∙ Terms ∙ Collection notice
Start your SubstackGet the app
Substack is the home for great culture