Maintained AlgoGP bridge

vectorbt guide

vectorbt is the fastest way to explore a parameter space in Python, which makes it a research favourite.

Last reviewed · Also known as vectorbt PRO, vbt

Quick answer

vectorbt is a Python library that backtests by operating on whole arrays at once with pandas and Numba instead of looping bar by bar. You build entry and exit signal arrays (or orders) and call Portfolio.from_signals, which simulates fees, slippage and sizing across thousands of parameter combinations in seconds. A commercial successor, vectorbt PRO, adds more features.

vectorbt at a glance

Category
Research & vectorized backtesting
Language
Python
License
Apache-2.0 with Commons Clause
Does
Backtesting, Optimization, Performance analytics, Indicators
Markets
Stocks, ETFs, Crypto, Forex, Futures
Best for
Parameter sweeps and research over many symbols or settings, before committing to an event-driven engine.
In AlgoGP
Built-in bridge: add it to any project

Pick it if

Parameter sweeps and research over many symbols or settings, before committing to an event-driven engine.

Watch out for

Path-dependent logic (trailing stops, complex state) is awkward to vectorize.

vectorbt strengths and limitations

Strengths

  • Orders of magnitude faster than loop-based backtesters for sweeps.
  • Broadcasting: test a grid of parameters across many assets in one call.
  • Interactive Plotly charts and rich statistics.

Limitations

  • Path-dependent logic (trailing stops, complex state) is awkward to vectorize.
  • Open-source version is in maintenance; new features go to vectorbt PRO.
  • Commons Clause license restricts selling it as a service.

vectorbt example

pip install vectorbt
Install
import vectorbt as vbt
close = vbt.YFData.download("BTC-USD").get("Close")
fast = vbt.MA.run(close, [10, 20, 50], short_name="fast")
slow = vbt.MA.run(close, [100, 200], short_name="slow")
entries, exits = fast.ma_crossed_above(slow), fast.ma_crossed_below(slow)
pf = vbt.Portfolio.from_signals(close, entries, exits, fees=0.001)
print(pf.total_return().sort_values().tail())
SMA crossover sweep on BTC.

Use vectorbt with AlgoGP

AlgoGP has a built-in vectorbt bridge. Describe the strategy to the copilot and backtest it in AlgoGP, then open the project’s APIs & keys tab and add vectorbt under Frameworks. The project gains these files, saved as a new version and included in every export:

  • frameworks/algogp_bridge.py
  • frameworks/tests/test_bridge.py
  • frameworks/vectorbt_signals.py
  • requirements.txt gains: vectorbt
python frameworks/vectorbt_signals.py
Run the AlgoGP strategy with vectorbt.

vectorbt connects to Yahoo Finance, Binance, Alpaca. Each guide shows how to create the API key, which you can store in the project’s Keys & secrets.

vectorbt: frequently asked questions

Is vectorbt free?

The open-source version is free under Apache-2.0 with Commons Clause; vectorbt PRO is a paid subscription.

vectorbt vs Backtrader?

vectorbt is far faster for sweeps; Backtrader is easier for path-dependent, event-driven logic and live trading.

vectorbt alternatives

Independent guide. AlgoGP is not affiliated with vectorbt. Features, licenses and maintenance change; check the official documentation. Nothing here is investment advice.

Build a strategy