Skip to Academy content

Quantitative Trading · Level II · Elective

Python for Trading II

Intermediate Python for systematic trading: an event-driven backtester, performance at scale, broker and data APIs, asynchronous feeds, testing trading code and packaging a strategy so it can run unattended.

What you will be able to do
  • Build an event-driven backtester with separate data, strategy, execution and accounting.
  • Make research code fast enough for large universes.
  • Test, package and run strategy code against live APIs.

Section 1 of 2

An event-driven backtester

An event-driven backtester processes events in time order: market data, signals, orders and fills. A simple design has four classes: a data handler that emits bars, a strategy that turns bars into target positions, an execution handler that turns orders into fills under a fill model, and a portfolio that updates positions, cash and the ledger.

A queue connects them: each component reads events, acts and puts new events on the queue. Because each component only sees past events, the design makes look-ahead hard.

The same strategy class can run live by swapping the data handler for a live feed and the execution handler for a broker client.

Keep this in mind: Separate data, strategy, execution and accounting and connect them through an event queue.

Make the idea stick

Quick checks before you move on.

Quick check 1 of 2 · An event-driven backtester

Why does an event-driven design make look-ahead hard?

Quick check 2 of 2 · An event-driven backtester

What changes when the strategy goes live?

Quantitative Trading · Level II · Enrolled students

The rest of Python for Trading II

This is included with Quantitative Trading Level II. The orientation and Module 1 of every level remain free to read.