Backtesting Libraries Compared
Compare popular Python backtesting tools: vectorbt, Backtrader, backtesting.py, Zipline Reloaded, NautilusTrader and LEAN. Learn their styles, strengths and limits.
You can write a simple backtest yourself in pandas, but as strategies grow, a framework saves time: it handles order simulation, position tracking, commissions and reporting. Python has many open source backtesting libraries, and they differ mainly in style. Vectorized tools run fast over whole arrays and suit research across many parameters. Event driven tools process one bar or tick at a time, which is slower but closer to how a live system behaves. Choosing the right one depends on your strategy, data and whether you plan to trade live from the same code.
Two styles of backtesting#
| Vectorized | Event driven | |
|---|---|---|
| How it works | Computes signals and returns on whole arrays at once | Steps through time, reacting to each bar or tick |
| Speed | Very fast | Slower |
| Realism | Simplified fills and path effects | Models orders, fills and state more closely |
| Best for | Research, parameter sweeps | Complex logic, live trading parity |
| Lesson | Event-Driven vs Vectorized Backtesting | Backtesting Methodology |
The main libraries#
| Library | Style | Notes |
|---|---|---|
| vectorbt | Vectorized | Very fast parameter sweeps on NumPy and pandas; a paid PRO version adds features |
| backtesting.py | Event driven, simple | Small, easy API and interactive charts; single asset focus |
| Backtrader | Event driven | Mature and flexible with many indicators and broker integrations; development has slowed, so check maintenance status |
| Zipline Reloaded | Event driven | Community fork of Quantopian's Zipline; daily equity portfolios with a data bundle system |
| NautilusTrader | Event driven | High performance core written in Rust with a Python API; designed for research and live trading with the same code |
| LEAN (QuantConnect) | Event driven | Open source engine in C# with Python support; runs locally or on QuantConnect's cloud with bundled data |
| freqtrade | Event driven | Focused on crypto bots, with backtesting, optimisation and live trading |
Projects change over time. Before committing, check recent releases, open issues and documentation quality.
Choosing a library#
| If you want to | Consider |
|---|---|
| Test thousands of parameter combinations quickly | vectorbt or your own pandas code |
| Learn backtesting with a small, clear API | backtesting.py |
| Run multi asset daily equity portfolios | Zipline Reloaded or LEAN |
| Use the same code for backtest and live trading | NautilusTrader, LEAN, freqtrade or Backtrader |
| Trade crypto on centralised exchanges | freqtrade or NautilusTrader |
What every framework still needs from you#
A library does not make a backtest honest. You still need to supply:
- Clean, point in time data. See Point-in-Time and Survivorship-Free Data and Survivorship and Selection Bias.
- Realistic costs and slippage. See Costs and Slippage in Backtests.
- Sensible fill assumptions, especially for limit orders. See Fill Models, Partial Fills and Order Queues.
- Out of sample discipline. See In-Sample vs Out-of-Sample Testing.
Writing your own#
Many experienced traders eventually write a small custom engine, because it fits their data and instruments exactly and has no hidden assumptions. The trade off is time and the risk of subtle bugs. A good middle path is using a framework for research and writing a thin, well tested live layer. See Building Trading Bots.
Frequently asked questions#
What is the best Python backtesting library?#
There is no single best. vectorbt suits fast research, backtesting.py suits beginners, and NautilusTrader, LEAN or freqtrade suit traders who want the same code live.
Is vectorized or event driven backtesting better?#
Vectorized is faster for research; event driven is more realistic for complex order logic and live trading parity. Many traders use both.
Do backtesting libraries include data?#
Most do not. LEAN on QuantConnect's cloud includes data; with most other libraries you supply your own. See Historical Data for Backtesting.
Next, learn how programs talk to brokers in Working With Exchange and Broker APIs.
3 quick questions on this lesson. Get them all right to finish it.
Turn on JavaScript to take the quiz.
Mentioned in
- Plotting Market Data with MatplotlibProgramming and Data