Chapter 23. Vectorized and Event-Based Backtesting
Vectorized backtests in numpy and pandas are powerful tools for evaluating trading
ideas quickly, but professional evaluation also requires an event-based view that
mirrors how markets and brokers actually process orders and trades. This chapter
develops both layers side by side, using a simple machine learning baseline strategy to
connect signals, positions, trades, and performance metrics.
This chapter builds a bridge from EMH-style hypotheses to concrete backtests. It starts from a buy-and-hold baseline for a single liquid instrument, adds a simple logistic-regression strategy for daily direction, and implements both a vectorized and a minimal event-based backtest. The event-based layer deliberately reuses the same notions of prices, returns, signals, orders, and account state as the market and broker engine in Chapter 24, reinforcing the idea that serious backtests must closely resemble the execution environment they stand in for. The ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access