Skills

Vectorbt

High-performance vectorized backtesting with parameter optimization, portfolio...

Install

npx skills add agiprolabs/claude-trading-skills --skill vectorbt -g -a claude-code -y
Category
Engineering
Updated
2mo ago
License
MIT
Context cost
Mediumabout 2,523 tokens
Runs scripts
Yes, review before use

What it does

High-performance vectorized backtesting with parameter optimization, portfolio simulation, and rich performance metrics

Vectorized Backtesting with vectorbt

Overview

vectorbt is a Python library for vectorized backtesting, running strategy simulations using NumPy/pandas array operations instead of bar-by-bar loops. This makes it 100, 1000x faster than event-driven frameworks (backtrader, zipline), enabling parameter optimization across thousands of combinations in seconds.

Key strengths:

  • Blazing speed via NumPy vectorization
  • Built-in parameter grid search and optimization
  • 50+ built-in performance metrics (Sharpe, Sortino, Calmar, max drawdown, profit factor)
  • Rich plotting (equity curves, drawdowns, trade markers, heatmaps)
  • Native pandas integration, your data stays in DataFrames throughout

Installation

uv pip install vectorbt pandas numpy

vectorbt pulls in pandas, NumPy, and Plotly automatically. For technical indicators, also install pandas-ta:

uv pip install vectorbt pandas-ta

Core Concepts

1. Signals, Boolean Entry/Exit Arrays

Strategies in vectorbt are expressed as boolean pandas Series (or arrays) indicating where to enter and exit positions:

import vectorbt as vbt
import pandas as pd

# Entry: buy when fast EMA crosses above slow EMA
entries = fast_ema > slow_ema
# Exit: sell when fast EMA crosses below slow EMA
exits = fast_ema < slow_ema

vectorbt resolves conflicting signals automatically (you can't enter while already in a position).

2. Portfolio, The Backtesting Engine

vbt.Portfolio.from_signals() is the primary backtesting function. It takes price data and entry/exit signals, simulates trades, and computes performance:

pf = vbt.Portfolio.from_signals(
    close=close_prices,
    entries=entries,
    exits=exits,
    init_cash=10_000,
    fees=0.003,       # 0.3% per trade
    slippage=0.005,   # 0.5% slippage
    freq="1h",        # hourly data
)

3. Metrics, Built-in Performance Analysis

# Full stats summary
print(pf.stats())
Read the whole SKILL.md on GitHub

More in Engineering