The backtesting engine that gives you an unfair advantage. Run thousands of trading ideas before others finish one.
The backtesting engine that gives you an unfair advantage. Run thousands of trading ideas before others finish one.
VectorBT takes a radically different approach to backtesting: instead of looping through bars one strategy at a time, it packs thousands of configurations into NumPy arrays, accelerates the hot path with Numba and Rust, and runs them all at once, turning hours of grid search into seconds.
Explore thousands of trading ideas across assets and timeframes, analyze portfolio performance down to individual trades, and visualize results interactively, all in a few lines of code. Built for both human researchers and AI agents, VectorBT combines large-scale experimentation with a mature, battle-tested backtesting stack refined through years of community use.
VectorBT is the open-source community edition of VectorBT PRO, a state-of-the-art hybrid backtesting library.
pip install -U vectorbtTo install the optional Rust engine:
pip install -U "vectorbt[rust]"To install all optional integrations (TA-Lib, Pandas TA, etc.):
pip install -U "vectorbt[full]"To install all optional integrations together with the Rust engine:
pip install -U "vectorbt[full,rust]"import vectorbt as vbt
data = vbt.YFData.download("BTC-USD")
price = data.get("Close")
pf = vbt.Portfolio.from_holding(price, init_cash=100)
print(pf.total_profit())19501.10906763755fast_ma = vbt.MA.run(price, 10)
slow_ma = vbt.MA.run(price, 50)
entries = fast_ma.ma_crossed_above(slow_ma)
exits = fast_ma.ma_crossed_below(slow_ma)
pf = vbt.Portfolio.from_signals(price, entries, exits, init_cash=100)
print(pf.total_profit())34417.80960086067import numpy as np
symbols = ["BTC-USD", "ETH-USD"]
data = vbt.YFData.download(symbols, missing_index="drop")
price = data.get("Close")
n = np.random.randint(10, 101, size=1000).tolist()
pf = vbt.Portfolio.from_random_signals(price, n=n, init_cash=100, seed=42)
mean_expectancy = pf.trades.expectancy().groupby(["randnx_n", "symbol"]).mean()
fig = mean_expectancy.unstack().vbt.scatterplot(xaxis_title="randnx_n", yaxis_title="mean_expectancy")
fig.show()…print(pf[(10, 20, "ETH-USD")].stats())…pf[(10, 20, "ETH-USD")].plot().show()VectorBT goes beyond backtesting, with tools for financial data analysis and visualization:
…100%|██████████| 31/31 [00:21<00:00, 1.21it/s]Visit the website for more examples, documentation, and guides.
Explore candlestick patterns interactively and backtest their signals with VectorBT.
This work is fair-code distributed under the Apache 2.0 with Commons Clause license.
The source code is publicly available, and everyone (individuals and organizations) may use it for free. However, you may not sell products or services that are primarily this software.
If you have questions or want to request a license exception, please contact the author.
Installing optional dependencies may be subject to a more restrictive license.
This software is for educational purposes only. Do not risk money you cannot afford to lose.
Use the software at your own risk. The authors and affiliates assume no responsibility for your trading results.
FX Convertion
Feature idea: Pattern similarity signals as vectorbt indicators
Feature request: Margin trades
3.14 support request
Negative prices for spreads / pairs?
VectorBT - Telegram - Issue: ImportError: cannot import Unauthorized, ChatMigrated
Lightweight Charts as alternative plotting backend
Leverage implementation
Metric shows incorrect value in portfolio statistics
Can it support Python 3.13 version?