Why Backtest.py's Loop-Based Design Kills Multi-Strategy Testing
Running 50 variations of a moving average crossover strategy in Backtest.py takes about 12 minutes on my M1 MacBook. The same test in vectorbt finishes in under 4 minutes.
The gap isn't about code quality — it's architectural. Backtest.py runs each strategy sequentially in a Python loop, recalculating indicators and event handling for every parameter combination. Vectorbt precomputes everything as NumPy arrays and broadcasts operations across all parameter sets simultaneously. When you're testing hundreds of hyperparameter combinations (different MA windows, stop-loss levels, position sizing rules), that difference compounds fast.
I migrated a pairs trading system from Backtest.py to vectorbt last month. The migration itself took maybe 3 hours, but the real payoff came when I started running parameter sweeps — what used to be overnight grid searches now finish during lunch.
This isn't a hit piece on Backtest.py. It's a fantastic library for beginners: clean API, great documentation, easy to reason about. But if you're moving from "test one strategy" to "test 100 variations in parallel," you'll hit its performance ceiling hard.
Continue reading the full article on TildAlice

Top comments (0)