ML4T Backtest
ML4T Backtest Documentation
Event-driven backtesting with realistic execution
Skip to content

User Guide

Use this guide to build a backtest from prepared market data and strategy decisions, then inspect what the engine actually executed. The quickstart gives you a complete first run. The topic pages below explain the choices you make when adapting that run to your own data and strategy.

The code in the Getting Started tutorials runs from the installed package against bundled synthetic data. The topic pages describe individual interfaces and settings. When a topic page shows only a method call, use its linked tutorial for a complete program and expected output. The API reference gives the signatures and source docstrings for the released package.

Find the task you need

Task Guide and runnable example API contract and book notebook
Prepare bars, signals, context, and timestamps Data Feed
Run: Bundled example data
DataFeed
Book: Futures feed
Write decisions and carry state between callbacks Strategies and Stateful Strategies
Run: First backtest and Risk and State
Strategy.on_data
Book: Stateful strategies
Choose order types and determine when fills can occur Order Types and Execution Semantics
Run: Orders and Timing
Broker.submit_order
Book: Single asset backtest
Allocate across assets and deal with different daily close times Rebalancing
Run: Multi-asset Rebalancing
Broker.rebalance_to_weights
Book: Allocator comparison
Set cash, margin, contract, and sizing rules Account Policies and Configuration
Run: Accounts and Constraints
BacktestConfig
Book: Conformal sizing
Model commission, slippage, impact, and funding Market Impact and Execution Costs
Run: Costs and Funding
BacktestConfig
Book: Gross versus net
Add position exits and portfolio limits Risk Management
Run: Risk and State
StopLoss
Book: Library risk demo
Compare explicit execution settings Profiles
Run: Profiles and Parity
BacktestConfig.from_preset
Book: Engine divergence
Export fills, trades, equity, and portfolio state Results and Analysis
Run: Results and Analysis
BacktestResult
Book: Performance reporting
Move an existing Zipline strategy to prepared bars and explicit settings Migrate from Zipline
Run: Complete migration example
Engine.run
Book: Engine divergence

Choose an asset example

All five bundled panels are synthetic. They test the library workflow offline; they do not estimate a strategy's live performance or reproduce a book case study. The data page runs a round trip for each panel and states its price and volume assumptions.

Asset setting Example Setting to check before using your own data
Equity Equity round trip Share precision, trading calendar, and corporate-action handling in the input
ETF ETF round trip Weight targets, rebalance timing, and cash available for the next fill
Futures Futures round trip Contract multiplier, margin, and the timestamp of each market close
FX FX round trip Pair quotation and the account currency used for valuation
Crypto perpetual Perpetual round trip Funding timestamps, rate sign, and the position held before each event

The examples use declared settings rather than implied market defaults. Start with the configuration guide when you replace a bundled panel with another instrument or venue.

From a book notebook to a library run

The Book Guide maps checked companion notebooks to the matching library workflows. Begin with the library quickstart, then compare the notebook's data, decision time, fill time, account rules, and costs with the settings in your run. Keep the original notebook's research question separate from the engine configuration. The book links point to a pinned companion revision, and each linked tutorial states what its notebook adds.

Check a result

Inspect fills, trades, and equity before interpreting summary metrics. A missing fill can mean that an order was rejected, an order type did not trigger, the next eligible bar was absent, or buying power was insufficient. The result tutorial exports these records and joins event timestamps back to the input data. The diagnostic handoff shows the optional analysis package used for downstream metrics.