VectorBT: The Fastest Backtesting Framework for Python

If you have ever been involved in algotrading and backtesting trading strategies on Python, you have probably encountered the same problem: speed. Classical libraries (e.g., Backtrader or Zipline) use an object-oriented approach, iterating through historical data event by event (event-driven). This is convenient for writing logic, but when it comes to parameter optimization on thousands of combinations, hours of waiting become unbearable.
And this is where VectorBT comes in — a quantitative analysis library that applies a fundamentally different approach to backtesting.
What is VectorBT?

VectorBT works exclusively with pandas and NumPy objects, and uses the Numba compiler to accelerate calculations. This allows for analyzing any data with incredible speed and scalability, testing tens of thousands of strategies in literally seconds.
Instead of processing each bar or tick in turn (as traditional backtesters do), VectorBT represents complex data as structured arrays. Vectorization of operations in conjunction with Numba (which solves the path dependency problem by allowing Python loops to be compiled into machine code) provides performance at the level of the C language.
Key Features

- Vectorized Backtesting: Testing strategies in a few lines of code. No slow Python loops.
- Large-scale Optimization: Optimize your trading strategy simultaneously across many parameters, timeframes, and assets in one go.
- Interactive Visualization: Built-in integration with Plotly and Jupyter Widgets allows for creating extremely complex charts and dashboards (like Tableau) directly in Jupyter Notebook without noticeable rendering delays.
- No Loss of Control: Unlike cloud platforms like TradingView, your data and algorithms stay only with you. At the same time, calculation performance is comparable to, and often exceeds, ready-made platforms.
- Data Preparation: Excellent toolkit for time series analysis and feature engineering for machine learning models.
How It Works (Example)

Let's say we want to test a classic Dual Moving Average Crossover (DMAC) strategy on Bitcoin (BTC).
In a classic OOP framework, you would have to create a strategy class, describe the next() logic that triggers on each bar, and iterate through all the bars. In VectorBT, everything is much more elegant and faster:
import vectorbt as vbt
btc_price = vbt.YFData.download('BTC-USD', start='2019-01-01 UTC', end='2020-01-01 UTC').get('Close')
fast_ma = vbt.MA.run(btc_price, [10, 20], short_name='fast')
slow_ma = vbt.MA.run(btc_price, [30, 30], short_name='slow')
entries = fast_ma.ma_crossed_above(slow_ma)
exits = fast_ma.ma_crossed_below(slow_ma)
pf = vbt.Portfolio.from_signals(btc_price, entries, exits)
print(pf.total_return())
В этом примере мы за одно мгновение протестировали сразу несколько вариаций стратегии DMAC: комбинации (10, 30) и (20, 30). Результатом (в виде колонки) будет доходность для каждого варианта параметров:
fast_window slow_window
10 30 0.848840
20 30 0.543411
Name: total_return, dtype: float64
Want to add Ethereum, Solana, and a dozen more coins? Just combine their prices into one DataFrame. Want to test different time ranges? Use the range_split function. The vector representation allows you to multiply dimensions almost limitlessly (as long as there is enough RAM).
VectorBT PRO

There is also a commercial version of the library — VectorBT PRO, which adds even more powerful tools. It features parallel processing, advanced portfolio optimization, price pattern recognition, event projection, margin trading and limit order calculation, and over a hundred other metrics important for real trading.
Why Use VectorBT?
If you just need to "run" one strategy on one instrument, standard frameworks might be enough. But if your goal is exploratory analysis, finding statistical patterns (alpha), testing hypotheses on thousands of instruments simultaneously, then VectorBT will be a real discovery for you.
It is a tool of data scientists brought to trading. It gives a competitive information advantage by being able to check ideas tens and hundreds of times faster than other market participants do on Python.
MarketMaker.cc Team
Investigación Cuantitativa y Estrategia