Inferensys

Glossary

Event-Driven Backtesting

A simulation architecture where strategy logic is executed only when a market event, such as a new trade or quote, occurs, replicating real-time trading engine behavior.
Architect reviewing LLM integration architecture on laptop, system diagrams visible, modern technical office setup.
SIMULATION ARCHITECTURE

What is Event-Driven Backtesting?

Event-driven backtesting is a simulation architecture where strategy logic is executed only when a market event, such as a new trade or quote, occurs, replicating real-time trading engine behavior.

Event-driven backtesting is a simulation architecture that replicates the asynchronous, reactive nature of a live trading engine. Unlike vectorized backtesting, which operates on entire arrays of historical data at once, this paradigm processes data sequentially. The strategy's core logic is triggered exclusively by discrete market events—such as a new trade print, a quote update, or an order fill confirmation—ensuring the simulation accurately models the temporal flow of information.

This architecture relies on a central event loop and a priority queue to manage the chronological processing of MarketEvent, SignalEvent, and OrderEvent objects. By decoupling components like the data handler, portfolio manager, and execution simulator, it prevents look-ahead bias and accurately captures path dependency. This makes it the definitive method for testing latency-sensitive, high-frequency, or order-book-dependent strategies where the sequence of operations critically impacts the final equity curve.

ARCHITECTURAL PRINCIPLES

Key Characteristics of Event-Driven Engines

Event-driven backtesting engines replicate the asynchronous, reactive nature of live trading by advancing simulation time only when a market event occurs. This architecture provides superior fidelity for modeling latency-sensitive and order-book-dependent strategies.

01

Discrete Event Simulation Core

The computational backbone relies on a priority queue that processes events in strict chronological order. Unlike vectorized backtests that iterate through uniform time bars, the engine jumps directly from one market event to the next.

  • Event types include: MARKET_DATA, SIGNAL, ORDER, FILL, and CANCEL
  • The event loop pops the earliest timestamped event and dispatches it to the appropriate handler
  • Idle periods with no market activity consume zero compute cycles, making the architecture highly efficient for sparse data
02

State Machine Order Management

Every simulated order transitions through a deterministic finite state machine that mirrors production order management systems. This prevents impossible states like a cancelled order receiving a fill.

  • Valid states: PENDING_NEW, NEW, PARTIALLY_FILLED, FILLED, PENDING_CANCEL, CANCELLED, REJECTED
  • Transitions are triggered by exchange acknowledgment events, not instantaneous assumptions
  • Enforces realistic queueing behavior where cancellation requests can race against fills
03

Callback-Driven Strategy Logic

Strategies are implemented as event handlers rather than loop iterations. The engine invokes specific callbacks only when relevant events occur, replicating how a live strategy receives streaming market data.

  • on_bar(Bar bar): Triggered when a new OHLC bar completes
  • on_tick(Tick tick): Fires on every trade or quote update for tick-level granularity
  • on_fill(Fill fill): Called when an order is executed, enabling dynamic position sizing
  • on_signal(Signal signal): Dispatched when an alpha model generates a prediction

This pattern enforces path dependency naturally, as strategy state evolves strictly through event sequences.

04

Clock Synchronization & Temporal Integrity

Multi-asset strategies consuming feeds from disparate exchanges require rigorous timestamp alignment to prevent look-ahead bias. The engine maintains a single authoritative simulation clock.

  • All incoming events are stamped with the simulation's reference time, not the local arrival time
  • NTP-style synchronization logic resolves sub-millisecond ordering ambiguities between co-located feeds
  • Events with identical timestamps are processed in a deterministic order (e.g., signals before orders before fills)
  • This guarantees that a strategy never peeks at a correlated asset's price before making a decision
05

Fill Simulation & Liquidity Modeling

Rather than assuming execution at the mid-price, the engine simulates fills against a reconstructed limit order book or volume-at-price distribution. This captures the adverse selection cost of aggressive orders.

  • Volume-weighted average price calculation across multiple price levels for large orders
  • Queue position modeling: limit orders are filled only when sufficient opposing volume trades through that price level
  • Slippage models apply temporary impact based on order size relative to historical volume at that timestamp
  • Partial fills are generated when available liquidity is insufficient to satisfy the full order quantity
06

Deterministic Replay & Auditability

Every simulation run is bit-for-bit reproducible when initialized with the same random seed and event stream. This is critical for debugging, regulatory compliance, and strategy comparison.

  • All pseudo-random number generators are seeded explicitly and logged
  • The event queue serialization order is fixed for identical timestamps
  • Checkpointing allows the simulation state to be saved and resumed from any point in time
  • Discrepancies between two runs indicate either a code change or a non-deterministic data dependency that must be eliminated
EVENT-DRIVEN BACKTESTING

Frequently Asked Questions

Explore the core concepts of event-driven simulation architecture, the gold standard for replicating live trading engine behavior in historical testing environments.

Event-driven backtesting is a simulation architecture where strategy logic executes only in response to a market event, such as a new trade, quote, or order fill confirmation. Unlike vectorized backtesting that operates on completed bar arrays, an event-driven engine uses a discrete event simulation loop. The engine maintains a priority queue of timestamped events. When an event is popped, the engine updates the market state and notifies subscribed components. The strategy callback receives the event, evaluates the new state, and may generate an order signal. This order becomes a new event in the queue, processed only when its timestamp is reached, faithfully replicating the path dependency and latency of live trading.

Prasad Kumkar

About the author

Prasad Kumkar

CEO & MD, Inference Systems

Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.

His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.