# vectorbt — High-Performance Quantitative Backtesting in Python > A Python library for fast backtesting, analysis, and visualization of trading strategies using vectorized operations on NumPy and pandas. ## Install Save as a script file and run: # vectorbt — High-Performance Quantitative Backtesting in Python ## Quick Use ```bash pip install vectorbt ``` ```python import vectorbt as vbt price = vbt.YFData.download("AAPL").get("Close") fast_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) print(pf.stats()) ``` ## Introduction vectorbt is a Python library designed for quantitative traders and researchers who need to test thousands of strategy variations quickly. By leveraging NumPy broadcasting and vectorized operations instead of row-by-row iteration, it achieves orders-of-magnitude speedups over traditional event-driven backtesting frameworks, making exhaustive parameter sweeps practical. ## What vectorbt Does - Runs vectorized backtests on trading strategies with minimal code - Computes portfolio performance metrics (Sharpe, Sortino, max drawdown, etc.) across parameter grids - Provides technical indicator wrappers (MA, RSI, BBANDS, etc.) with broadcasting support - Generates interactive Plotly-based visualizations of equity curves, drawdowns, and trade analysis - Supports multi-asset portfolio simulation with position sizing and fees ## Architecture Overview vectorbt represents data as multi-dimensional NumPy arrays where extra dimensions encode parameter combinations. Indicators, signals, and portfolio logic operate on these arrays using broadcasting, so a single backtest call can evaluate thousands of parameter sets simultaneously. The `Portfolio` class simulates order execution, tracks positions, and computes statistics. Numba JIT compilation accelerates custom logic where pure NumPy is insufficient. ## Self-Hosting & Configuration - Install via `pip install vectorbt` with optional extras for data downloads - Use `vbt.settings` to configure global defaults for plotting, data caching, and computation - Set `freq` parameter on time series to ensure correct annualization of metrics - Enable Numba acceleration with `@njit` decorators for custom signal logic - Configure data sources via `vbt.YFData`, `vbt.BinanceData`, or custom data feeds ## Key Features - Vectorized execution enables testing millions of parameter combinations in seconds - Built-in technical indicators that natively support parameter arrays - Interactive Plotly visualizations for equity curves, trade scatter plots, and heatmaps - Flexible portfolio simulation with configurable fees, slippage, and position sizing - Numba-accelerated custom indicators and signals ## Comparison with Similar Tools - **Backtrader** — Event-driven, easier to understand but much slower for parameter sweeps - **Zipline** — Quantopian legacy framework; vectorbt is more flexible and actively maintained - **bt** — Tree-based strategy composition; vectorbt excels at brute-force parameter optimization - **QuantStats** — Analytics and reporting only; vectorbt includes the full backtest loop - **pandas-ta** — Indicator library only; vectorbt adds backtesting and portfolio simulation ## FAQ **Q: How fast is vectorbt compared to event-driven frameworks?** A: Depending on the strategy, vectorbt can be 100x to 1000x faster than row-by-row backtesters because it processes entire arrays at once. **Q: Can I use vectorbt for live trading?** A: vectorbt is primarily a research and backtesting tool. For live trading, use its signal generation with a separate execution layer. **Q: Does vectorbt support cryptocurrency data?** A: Yes. It includes built-in data downloaders for Yahoo Finance and Binance, and accepts any pandas DataFrame. **Q: What license does vectorbt use?** A: vectorbt is released under a custom source-available license. Check the repository for details. ## Sources - https://github.com/polakowo/vectorbt - https://vectorbt.dev/ --- Source: https://tokrepo.com/en/workflows/asset-d92390ad Author: Script Depot