Writing your own backtest in pandas works but takes a week. vectorbt does the same thing in 30 lines and runs orders of magnitude faster. For anyone backtesting strategies on crypto data, it's the right tool.
This article walks through why vectorbt is worth learning, how to set up a strategy, how to run parameter sweeps, and the limitations that matter.
A standard pandas backtest loops over candles, simulating fills one at a time. For 10,000 candles and 100 parameter combinations, you're running 1 million iterations. Pure Python: 30+ minutes. Numpy-optimised: a few minutes. Still slow.
vectorbt vectorises the entire simulation. Same task in vectorbt: 5-10 seconds. The speedup comes from running all parameter combinations as parallel numpy operations rather than sequential loops.
For a single strategy with one set of parameters, both approaches work. For walk-forward analysis, parameter sweeps, or comparing multiple strategies, vectorbt is essentially mandatory. The 100x speedup means you can actually iterate.
Other reasons to prefer vectorbt:
Installation:
Fetching crypto data via CCXT:
For longer histories, you'll need to paginate further. Most crypto exchanges return at most 1000 candles per call.
A simple EMA crossover strategy in vectorbt:
This produces a complete backtest with realistic transaction costs. The output includes total return, Sharpe ratio, max drawdown, win rate, and dozens of other metrics.
The key advantage: changing parameters or strategies requires modifying signal calculations, not loop logic. The simulation engine handles execution mechanics.
The real power of vectorbt shows up when sweeping parameters. Test all combinations of fast/slow EMA periods:
This runs ~80 backtests in under a minute. The top-10 Sharpe ratios show which parameter combinations actually worked.
But ranking by Sharpe alone is dangerous — those top results may be overfit. Better evaluation:
If only 2-3 parameter combinations pass these filters, the strategy is overfit. A robust strategy has 10-20+ parameter combinations that produce reasonable Sharpe and drawdown profiles.
vectorbt's `pf.stats()` returns a comprehensive dictionary:
Useful metrics for crypto strategies:
If a strategy shows Sharpe 3.0 with 80% win rate, it's almost certainly overfit. Real strategies aren't that good.
A few limitations worth knowing:
**Multi-leg strategies** — vectorbt is designed for single-instrument strategies. Pairs trading or basket strategies require manual portfolio construction outside vectorbt.
**Order book microstructure** — vectorbt simulates fills based on close prices. It doesn't model order book depth, queue position, or adverse selection. For market-making strategies, you need a different tool.
**Funding rates** — vectorbt doesn't natively handle perpetual funding rates. You can approximate by adjusting commissions, but proper funding modelling requires custom code.
**Real-time switching to live trading** — vectorbt is research-focused. Going from a backtested strategy to a live bot requires rewriting the strategy logic in your bot framework. The signals generated in vectorbt aren't directly executable.
For these cases, you might need to combine vectorbt for research with a separate execution framework (CCXT, native exchange APIs).
Q: How much historical data do I need?
Minimum 1 year for hourly data, 3 years for daily. Less data means less reliable parameters. Crypto's regime changes are dramatic; longer histories help identify what works across regimes.
Q: Should I trust vectorbt's results?
The mechanics are accurate. Your trust should depend on whether you've avoided lookahead bias, used realistic costs, and tested out-of-sample. vectorbt makes the simulation easy; it doesn't fix bad methodology.
Q: How do I do walk-forward analysis in vectorbt?
Split data into windows, optimize on each window's first half, test on the second half. There's no built-in helper — you write a loop over time windows manually. Tedious but essential for honest backtesting.
Q: Is vectorbt free?
There's a free open-source version with most features. A paid Pro version adds some optimizations and convenience functions. For most retail use, free is sufficient.