Best Python backtesting libraries in 2026

A short notebook, a 256-setting search and a replay of level-two quote updates call for different tools. The shortlist below is ordered by workflow. Start by making two engines produce the same fills on a small fixture. Then scale the version whose execution and data model matches your strategy.

Library Start here when Check early
Backtesting.py A bar-based strategy needs a compact, readable single-instrument experiment trade_on_close, warm-up and the treatment of fees and open positions at the end.
Backtrader You need callbacks, several data feeds or detailed simulated orders Market orders use the next open under the usual historical model. Log the first eligible bar and any custom broker behavior.
vectorbt You want to scan many aligned signals and parameters with array operations Signal and execution prices must be aligned. Check cash grouping, order conflicts and the shape of broadcast inputs.
NautilusTrader Quotes, trades or depth updates affect what was available to fill Select the correct book type and historical event input. Verify event ordering, adapter behavior and configured fill model.

Backtesting.py reference · Backtrader order execution · vectorbt portfolios · NautilusTrader backtest data and venues

Verify execution before optimizing for speed

Start with one unit, four fills and a fee on each side. The site’s equivalent three-engine example reports 990.587 in final equity from 1,000. Use the complete native example to run those three libraries. Check the ordered fill list as well as the aggregate. A sweep comparing only terminal P&L can hide a wrong entry offset, duplicated fees or an inconsistent holding period.

Once the fixture passes, partition by an axis that preserves strategy semantics. Independent parameter settings can be batched. Positions that compete for the same cash cannot be split into independent runs if the intended portfolio shares a balance. Record whether each setting uses the same fees, data and warm-up.

Screenshots and examples

Backtest plot with price and trades
Backtrader · Backtest plot with price and trades Source
Report from a simulated BTC/USD backtest in NautilusTrader
NautilusTrader · Report from a simulated BTC/USD backtest in NautilusTrader Source

Estimate the size of a parameter sweep

Minimum memory for three float64 arrays per configuration

Estimated array bytes = bars × configurations × number of float64 arrays × eight bytes.
Results from the example
ConfigurationsBarsArraysConfigs per 512 MiBArrays, MiB
1 200000 3 1 4.58
16 200000 3 16 73.24
64 200000 3 64 292.97
128 200000 3 111 585.94
256 200000 3 111 1171.88
Array memory by grid size StockSharp JS-Charts

Assume 200,000 bars and three dense float64 arrays per configuration. A grid of 64 consumes about 293 MiB for those arrays. A grid of 256 consumes about 1,172 MiB. At a 512 MiB array budget, at most 111 configurations fit in a batch. This is a byte count for the specified arrays. Peak process memory also includes the Python runtime, signals, data frames, intermediate copies and the ledger.

Measure a representative pilot

On the intended machine, time compilation or warm-up separately from a repeated run and measure peak resident memory. Save the input shape and software versions. Then compare fills and peak memory over at least two grid sizes. Fast vector operations can help with search, while event-level fidelity needs the right market data and fill model.

Reproduce the result in Python

import json
from array import array


MIB = 1024 ** 2
BYTES_PER_VALUE = array("d").itemsize
assert BYTES_PER_VALUE == 8


def bytes_for(bars, configs, arrays):
    return bars * configs * arrays * BYTES_PER_VALUE


def run():
    bars, arrays, budget_mib = 200_000, 3, 512
    budget_bytes = budget_mib * MIB
    rows = []
    for configs in (1, 16, 64, 128, 256):
        size = bytes_for(bars, configs, arrays)
        batch = min(configs, budget_bytes // bytes_for(bars, 1, arrays))
        rows.append([configs, bars, arrays, batch, round(size / MIB, 2)])

    sample = array("d", (0.0 for _ in range(100)))
    assert len(sample) * sample.itemsize == bytes_for(100, 1, 1)
    assert rows[2][3] == 64 and rows[3][3] == 111
    assert bytes_for(bars, 111, arrays) <= budget_bytes < bytes_for(bars, 112, arrays)
    return rows


if __name__ == "__main__":
    print(json.dumps(run()))

Use the generated batch size as a bound for the stated arrays. Leave room for other allocations and recheck if you enable more indicators or change precision. Parameter sensitivity on a fixed dataset.