Registry / data / vectorbt

vectorbt

JSON →
library1.0.0pypypi✓ verified 86d ago

VectorBT is a Python library for backtesting and analyzing trading strategies at scale. It leverages NumPy and Numba for high-performance vectorized computations, enabling rapid testing of numerous strategy configurations and assets. The library integrates with pandas for data handling and Plotly for interactive visualizations. It is currently at version 0.28.5 and receives active development and maintenance.

pip install vectorbt
INSTALL
IMPORT
SIG · VECTORBT
V
vectorbt
datapythonv1.0.0
Install
40.4s avg
Import
14765ms
Disk
803MB
Pass rate
4/ 10
Env Coverage4 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.0.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
glibc
py 3.10
✕ build_error
✓ 41.54s
py 3.11
✕ build_error
✓ 40.83s
py 3.12
✕ build_error
✓ 39.94s
py 3.13
✕ build_error
✓ 39.34s
py 3.9
✕ build_error
4/8 runs
803MB installed
● package 803MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

vbt
import vectorbt as vbt
Standard alias for the library.
YFData
vbt.YFData
Used for downloading historical data from Yahoo Finance.
Portfolio
vbt.Portfolio
Core class for creating and analyzing trading portfolios from signals or orders.
MA
vbt.MA
Provides moving average indicators.
RSI
vbt.RSI
Provides Relative Strength Index indicator.

This quickstart demonstrates how to download historical price data, simulate a basic buy-and-hold strategy, and then implement a simple moving average crossover strategy with entry/exit signals using `vectorbt`.

import vectorbt as vbt import pandas as pd # Download historical daily price data for Bitcoin (BTC-USD) # Use a specific date range for reproducibility price = vbt.YFData.download( 'BTC-USD', start=pd.Timestamp('2020-01-01', tz='UTC'), end=pd.Timestamp('2021-01-01', tz='UTC') ).get('Close') # Simulate a simple buy-and-hold portfolio with $100 initial cash pf = vbt.Portfolio.from_holding(price, init_cash=100) # Calculate total profit profit = pf.total_profit() print(f"Total profit from buy-and-hold: ${profit:.2f}") # Calculate a simple moving average crossover strategy fast_ma = vbt.MA.run(price, 10) slow_ma = vbt.MA.run(price, 50) # Generate entry and exit signals entries = fast_ma.ma_crossed_above(slow_ma) exits = slow_ma.ma_crossed_above(fast_ma) # Backtest the MA crossover strategy pf_ma_crossover = vbt.Portfolio.from_signals( price, entries, exits, init_cash=100, fees=0.001 ) # Print strategy statistics print("\nMA Crossover Strategy Statistics:") print(pf_ma_crossover.stats())
Debug
Known issues
gotchaOlder versions of vectorbt (prior to 0.28.5) had compatibility issues with pandas 2.x, specifically an `AttributeError` when using `Styler.render()`. While fixed in 0.28.5, users on older `vectorbt` versions with pandas 2.x may encounter this.
fix
Upgrade to vectorbt version 0.28.5 or newer: `pip install --upgrade vectorbt`.
affects: <0.28.5
gotchaEarly documentation and tutorials (e.g., from March 2022) incorrectly stated that vectorbt did not support Python 3.10. The library now officially supports and requires Python >=3.10 as per PyPI metadata. Relying on outdated information may lead to incorrect assumptions about compatibility.
fix
Ensure you are using Python 3.10 or newer and `vectorbt` version 0.28.0 or later. Always check the official PyPI or GitHub for current Python requirements.
affects: Prior to official 3.10 support (pre-0.28.x)
gotchaWhen combining `vbt` accessor methods with other arrays or pandas objects, ensure the `vbt` accessor operand is on the left-hand side (e.g., `df.vbt * 2` rather than `2 * df.vbt`) for consistent behavior and performance benefits.
fix
Always place the `.vbt` accessor on the left side of binary operations.
affects: All versions
Errors
Common errors & fixes
AttributeError: 'Function' object has no attribute '_Function__info' when using vbt.IndicatorFactory.from_talib()
This error has been reported in older versions when attempting to dynamically create indicators from TA-Lib functions using `IndicatorFactory`. It indicates an incompatibility or internal API change.
fix
Ensure `vectorbt` and `TA-Lib` are up-to-date. If the issue persists, consider manually defining indicators or using `vectorbt`'s built-in indicator wrappers if available, instead of `IndicatorFactory.from_talib` for the specific indicator.
vectorbt heatmap displays wrong values or not all values when using a Pandas Series directly.
The heatmap plotting functionality might have unexpected behavior or require specific data structures (like DataFrames) for correct visualization, especially when dealing with multi-parameter results which are typically structured as DataFrames.
fix
Transform your Pandas Series into a Pandas DataFrame, even if it's a single column, before passing it to the `vbt.heatmap` method. This ensures proper indexing and value mapping.
Backtesting runs very slowly with large datasets or many strategy permutations.
While VectorBT is designed for speed, users might inadvertently write non-vectorized Python loops or perform operations that prevent Numba from optimizing. Incorrect data structuring (e.g., not leveraging MultiIndex for parameter sweeps) can also lead to performance bottlenecks.
fix
Ensure your strategy logic is vectorized as much as possible, leveraging pandas and NumPy operations. For custom complex logic, use Numba's `njit` decorator. Structure hyperparameter sweeps into MultiIndex DataFrames for `vectorbt` to process efficiently in a vectorized manner.
Upgrade
Version history
1.0.0latest on PyPI · released Apr 22, 2026
Audit
Dependencies
pythonrequiredRequired Python version.
ta-liboptionalProvides additional technical analysis indicators, included with '[full]' install.
plotlyoptionalUsed for interactive charting and dashboards, included with '[full]' install.
ipywidgetsoptionalUsed for interactive charting and dashboards in Jupyter environments, included with '[full]' install.
Agent activity
60 hits · last 30 days
node
54
OpenAI (training)
1
Resources