Rajandran R Creator of OpenAlgo - OpenSource Algo Trading framework for Indian Traders. Building GenAI Applications. Telecom Engineer turned Full-time Derivative Trader. Mostly Trading Nifty, Banknifty, High Liquid Stock Derivatives. Trading the Markets Since 2006 onwards. Using Market Profile and Orderflow for more than a decade. Designed and published 100+ open source trading systems on various trading tools. Strongly believe that market understanding and robust trading frameworks are the key to the trading success. Building Algo Platforms, Writing about Markets, Trading System Design, Market Sentiment, Trading Softwares & Trading Nuances since 2007 onwards. Author of Marketcalls.in

Event Driven Backtesting and Event Loops for Traders

2 min read

If you have ever built or tested a trading strategy, you have probably come across two approaches. Vectorized backtesting and event driven backtesting.

At first, they may seem similar. Both aim to test strategies on historical data. But under the hood, they work very differently.

This article simplifies event driven backtesting and explains why it matters for traders.


What is an Event Loop in Trading

An event loop is a system that processes things one at a time in sequence.

In trading, the system reacts to events such as:

New market data arrives
A signal is generated
An order is placed
An order gets filled

Each of these is an event.

The loop continuously waits for the next event and processes it step by step.

This mirrors how real markets operate. Everything happens in a sequence, not all at once.


Types of Events in Event Driven Backtesting

Event driven systems are built around different categories of events.

Market Data Events

New tick or candle data arrives

Signal Events

Your strategy generates buy or sell decisions

Order Events

Orders are created and sent to the broker

Execution Events

Orders get filled, partially filled, or rejected

Order Update Events

Orders are modified, cancelled, or updated after partial fills

Portfolio Events

Positions, cash, and profit and loss are updated


How Event Driven Backtesting Works

Event driven backtesting simulates real world flow step by step.

Simple loop:

  1. Market data event
  2. Signal event
  3. Order event
  4. Execution event
  5. Portfolio update

Then repeat.


Does Event Driven Mean Tick Data Only

No.

Event driven backtesting works with:

Tick data
One minute data
Hourly data
Daily data

Each data point becomes an event.

Tick data is not mandatory. It only becomes important for very high precision strategies.


Why This Matters

Real trading is not instant.

Orders can be:

Partially filled
Delayed
Modified
Cancelled

Event driven systems capture all of this.


Coming from Vectorized Tools like Amibroker and TradingView

If you are used to tools like AmiBroker or TradingView, this shift can feel very different.

Here are the key things to understand:

1. Bar by Bar Execution

You no longer compute on full arrays. Each bar is processed one at a time. The system only knows the past and present.


2. No Look Ahead Bias by Design

Future data does not exist yet. This makes your backtest naturally safer from accidental mistakes.


3. The Core Loop is an Event Queue

Everything flows through a sequence:

MarketEvent → SignalEvent → OrderEvent → FillEvent

Each event triggers the next.


4. Realistic Order Simulation

You can model:

Slippage
Partial fills
Different order types
Latency

Vectorized tools often assume perfect fills.


5. Portfolio State is Always Live

At every step, your system tracks:

Equity
Open positions
Available capital

This allows dynamic position sizing.


6. It is Much Slower

Vectorized backtests run extremely fast.

Event driven systems process each step, so they take more time, especially in Python.


7. Costs are Easier to Model

You can inject costs at execution level:

Brokerage
Taxes
Exchange fees
Impact cost

This gives more control than global settings.


8. Multi Asset Logic is Natural

Since state is updated continuously, you can easily implement:

Pairs trading
Hedging
Cross asset signals


9. Easier Transition to Live Trading

The same system can be connected to live data.

You replace historical data with live feed, and the logic stays the same.


10. Libraries to Explore

Good starting points:

Backtrader
Mature and widely used

bt
Simple and useful for learning

Nautilus Trader
High performance and modern

You can also explore QuantConnect LEAN for a production grade engine.


Why Event Driven Backtesting is Slower

Event driven systems simulate each step in time.

For every time step:

State is updated
Events are processed
Orders are simulated

This creates many small operations.

Vectorized systems process everything at once using optimized math libraries.

So:

Vectorized backtesting is fast because it simplifies reality
Event driven backtesting is slower because it simulates reality


When Should You Use Event Driven Backtesting

Use event driven when:

Execution matters
Strategy depends on timing
You want realistic results

Use vectorized when:

You need speed
You are exploring ideas

Most traders use both.


Final Thoughts

Event driven backtesting is about simulating the full trading lifecycle.

From data to signal to order to execution.

It is not about tick data. It is about sequence and realism.

If you want to move closer to real trading conditions, this approach is essential.

Rajandran R Creator of OpenAlgo - OpenSource Algo Trading framework for Indian Traders. Building GenAI Applications. Telecom Engineer turned Full-time Derivative Trader. Mostly Trading Nifty, Banknifty, High Liquid Stock Derivatives. Trading the Markets Since 2006 onwards. Using Market Profile and Orderflow for more than a decade. Designed and published 100+ open source trading systems on various trading tools. Strongly believe that market understanding and robust trading frameworks are the key to the trading success. Building Algo Platforms, Writing about Markets, Trading System Design, Market Sentiment, Trading Softwares & Trading Nuances since 2007 onwards. Author of Marketcalls.in

Leave a Reply

Get Notifications, Alerts on Market Updates, Trading Tools, Automation & More