Book
Python for Algorithmic Trading Cookbook
What this book is
A practitioner's manual for building a complete quantitative-trading stack in Python — not the math behind alpha, not a treatise on market microstructure, but the working engineering pipeline: how you get the data, what you do with it, how you test a strategy properly, how you ship it to a live broker, and how you keep it running.
Jason Strimpel writes from inside the toolchain. The book is a cookbook in the literal sense: each topic is a runnable recipe with a specific library focus — yfinance and pandas for ingest, VectorBT and Zipline Reloaded for backtesting, Alphalens and Pyfolio for evaluation, the Interactive Brokers Python API for execution. It assumes you already know Python and basic finance; it teaches you to bolt the parts together.
The shape of the pipeline
Executive summary
Systematic trading is mostly a data-engineering problem with a finance hat on. The math behind most factor strategies is undergraduate-level statistics; the difficulty lies in plumbing — getting clean data fast, structuring it for both vectorised and event-based experiments, producing comparable performance metrics across runs, and shipping a strategy to a broker without it doing something catastrophic on the first tick.
Three architectural distinctions that shape the whole book
-
Vector vs. event-based backtesting. Topic 6 (VectorBT) tests a strategy by computing signals across the full history at once — fast, ideal for parameter sweeps, but bad at modeling realistic order fills and intra-day events. Topic 7 (Zipline) simulates the strategy one bar at a time, calling your
handle_datafunction on each — slower but closer to what live trading actually looks like. Most serious researchers use both: VectorBT for exploration, Zipline for the final go/no-go test. -
Alpha generation vs. risk evaluation. Topic 5 builds factors that predict returns. Topics 8 and 9 evaluate the behaviour of those factors — Alphalens looks at factor quality (information coefficient, quantile spreads), Pyfolio looks at portfolio outcomes (drawdown, Sharpe, return decomposition). Conflating these is the most common mistake: a "good" factor in Alphalens can produce a poor portfolio if turnover or sizing rules eat the edge.
-
Research and live as separate environments. Topics 10-13 confront the gap between backtest and live execution — slippage you didn't model, orders that partially fill, market data that disconnects, and your strategy logic that needs to be reentrant across restarts. The IB API is the canonical Python broker integration; what the book teaches generalises to any broker that exposes an async callback model.
What this stack lets you actually do
The book's payoff is a reproducible loop: hypothesise an alpha (price/volume, fundamental, alt-data), test it vector-style for fast feedback, validate it event-style for realistic conditions, package the validated rules as production code, run it against an IB paper account, then promote to live. The full cycle — from a new hypothesis to a paper-trading deploy — should take days, not months, once the stack is in place.
Who this is for
Topic index
How to read these summaries
The topics depend on each other. Topic 2 (pandas) is referenced by every topic that follows; without it, the rest read as code without context. Topic 5 (alpha factors) is the conceptual centre; topics 6-9 are all evaluating something topic 5 produced. Topics 10-12 are an integrated thread — the IB API is one library, split across three topics for digestibility.
Concept companions
Topics
- 01Acquire Free Financial Market Data with Cutting-Edge Python Libraries
- 02Analyze and Transform Financial Market Data with pandas
- 03Visualize Financial Market Data with Matplotlib, Seaborn, and Plotly Dash
- 04Store Financial Market Data for Easy Retrieval
- 05Build Alpha Factors for Stock Portfolios
- 06Vector-Based Backtesting with VectorBT
- 07Event-Based Backtesting Factor Portfolios with Zipline Reloaded
- 08Evaluate Factor Risk and Performance with Alphalens Reloaded
- 09Assess Backtest Risk and Performance Metrics with Pyfolio
- 10Set Up the Interactive Brokers Python API
- 11Manage Orders, Positions, and Portfolios with the IB API
- 12Deploy Strategies to a Live Environment
- 13Advanced Recipes for Market Data and Strategy Management