Python backtesting libraries

All three tools run strategies on historical data. The choice depends on the data you have, the execution details you need to model and where you want your strategy to run.

Tool How it runs a strategy When it fits Documentation
Backtrader Python strategies run in Cerebro. You attach a historical data feed, a simulated broker and any analyzers you need. You want a local backtest using your own CSV or pandas data and a straightforward strategy loop. Backtrader quick start
NautilusTrader An event-driven engine processes historical market events through core components shared with live trading. Your strategy responds to quotes, trades or order-book updates and needs a more detailed execution simulation. NautilusTrader backtesting
QuantConnect / LEAN LEAN executes Python or C# algorithms in QuantConnect or as a local backtest through the LEAN CLI. You need the engine’s data integrations and configurable fill, fee and slippage models. LEAN engine

For a fair comparison, use the same instruments, period and bar interval and check how each framework timestamps bars. Match commissions, slippage and fill assumptions before comparing results. An order filled at a bar’s close can produce different results from the same order filled at the next bar’s open.

Browse all trading software