Project P01

Quantitative backtesting engine

How can we build a backtesting engine that avoids misleading itself and distinguishes a genuine edge from an artifact of data, costs, or search?

stages
9
duration
16 h 10 min
concepts
34
available in English
9 / 9
completed by you
0 of 9

Where it fits

Overview

A quantitative engineering project that builds a Python backtesting engine from scratch with free data. It starts with a vectorized engine and then adds an event-driven engine, portfolio accounting, transaction costs and impact, metrics with uncertainty, portfolio construction, walk-forward validation, and purged cross-validation. The project concludes with tools for distinguishing discoveries from overfitting, including the deflated Sharpe ratio, probability of backtest overfitting, and data-snooping tests, followed by a machine-learning signal evaluated through the full pipeline and a reproducible report.

Why it matters

This is the test bench for your quantitative work: future statistical, ML, and LLM signals can pass through the engine. Building it makes its assumptions about timing, execution, and costs explicit and helps you audit others' results. Overfitting controls also apply to empirical research with many experiments.

Stages 9

  1. 01Point-in-time data and engine architectureBuild the engine's data layer with free daily prices, dividends, and Kenneth French factors stored in Parquet. Reconstruct total returns from prices, dividends, and splits, compare historical and end-of-period universes, and define the engine's modular interfaces and tests. GPUAdvanced110 min
  2. 02Vectorized engine and a first strategyImplement a vectorized engine over date-by-asset panels: signal, explicitly lagged positions, returns, turnover, and linear costs. Validate with a shift test for lookahead and reproduce cross-sectional momentum as a reference strategy. GPUAdvanced100 min
  3. 03Event-driven engine, orders and accountingBuild an event-driven engine with a priority queue of market, signal, order, and execution events, a bar-based order simulator, and portfolio accounting with invariants. Compare it with the vectorized engine under ideal conditions and explore conditional orders and partial execution. GPUAdvanced120 min
  4. 04Transaction costs, market impact and capacityAdd a cost model with commission, half-spread estimated from daily data, slippage, and square-root impact as a function of volume participation. Calculate each strategy's break-even cost and capacity, and examine how costs affect gross Sharpe. GPUAdvanced100 min
  5. 05Metrics with uncertainty and factor attributionBuild the analysis module: Sharpe and its standard error under non-normality and autocorrelation, drawdowns, historical VaR and Expected Shortfall, and Fama-French factor regression with HAC errors. Combine the results in an automatically generated performance report with block-bootstrap confidence intervals. GPUAdvanced100 min
  6. 06Portfolio constructionAdd a portfolio construction layer with volatility targeting, minimum variance using Ledoit-Wolf covariance, risk parity, and constrained optimization with turnover penalty. Compare the layers out of sample against an equal-weight portfolio. GPUAdvanced110 min
  7. 07Walk-forward and purged cross-validationImplement the engine's validation protocol with walk-forward retraining and nested parameter selection, purged cross-validation with embargo for overlapping labels, and its combinatorial version for multiple backtest paths. Measure the performance inflation caused by standard cross-validation in a controlled experiment. GPUAdvanced100 min
  8. 08Backtest overfitting and multiple testingAdd a registry of evaluated configurations and tools that account for search: the deflated Sharpe ratio, probability of backtest overfitting, and White and Hansen data-snooping tests with stationary bootstrap. Explore a thousand noise strategies in a controlled experiment. GPUResearch110 min
  9. 09Machine learning signal and final reportFollow the complete ML signal pipeline: point-in-time features, volatility-adjusted triple-barrier labels, boosting with purged validation, meta-labeling for position sizing, a backtest with costs and impact, and adjustment for registered trials. Produce a reproducible research report that honestly assesses the evidence for an edge. GPUResearch120 min

Final deliverable

Investigate an anomaly of your own

Choose an economic hypothesis, register it before looking at the data, implement it in the engine, and publish a report with costs, capacity, attribution, deflated Sharpe ratio, and PBO regardless of the outcome.

Check what you already know

  • Build a point-in-time dataset with prices adjusted for dividends and splits and without survivorship bias.
  • Write a vectorized backtest without lookahead and demonstrate it with a shift test.
  • Implement an event-driven engine with orders, fills, and consistent portfolio accounting.
  • Calculate the Sharpe ratio standard error and factor alpha with HAC errors.
  • Apply purged cross-validation with embargo and explain why standard k-fold overestimates performance.
  • Calculate the deflated Sharpe ratio and probability of backtest overfitting for a strategy search.

References

  • Advances in Financial Machine LearningMarcos López de Prado, 2018
  • Active Portfolio ManagementRichard C. Grinold, Ronald N. Kahn, 1999