MCPInstall

vectorbt-expert

VectorBT backtesting expert. Use when user asks to backtest strategies, create entry/exit signals, analyze portfolio performance, optimize parameters, fetch historical data, use VectorBT/vectorbt, compare strategies, position sizing, equity curves, drawdown charts, or trade analysis. Also triggers for openalgo.ta helpers (exrem, crossover, crossunder, flip, donchian, supertrend).

Installs
3K
Last 24h
—
Trending rank
—
Security
Not audited

Install

Works with every agent the skills CLI supports.

npx skills add https://github.com/marketcalls/vectorbt-backtesting-skills --skill vectorbt-expert
  1. 01

    Install

    Run the command in your project. The CLI asks which agents to install for.

  2. 02

    Describe the task

    Ask your agent for something this skill covers. It loads vectorbt-expert automatically when relevant.

  3. 03

    Review the result

    The agent follows the SKILL.md steps, scripts and references bundled with the skill.

SKILL.md

The instructions your agent reads when the skill is triggered.

VectorBT Backtesting Expert Skill

Environment

  • Python with vectorbt, pandas, numpy, plotly
  • Data sources: OpenAlgo (Indian markets), DuckDB (direct database), yfinance (US/Global), CCXT (Crypto), custom providers
  • DuckDB support: supports both custom DuckDB and OpenAlgo Historify format
  • API keys loaded from single root .env via python-dotenv + find_dotenv() — never hardcode keys
  • Technical indicators: OpenAlgo ta (DEFAULT - from openalgo import ta, 100+ indicators covering trend/momentum/volatility/volume/oscillators/statistical/hybrid). Use TA-Lib only if the user explicitly asks for TA-Lib/talib. NEVER use VectorBT built-in indicators either way.
  • Specialty indicators (no TA-Lib equivalent, always openalgo.ta): Supertrend, Donchian, Ichimoku, HMA, KAMA, ALMA, ZLEMA, VWMA
  • Signal cleaning: openalgo.ta for exrem, crossover, crossunder, flip (always, regardless of indicator library)
  • Fee model: Indian market standard (STT + statutory charges + Rs 20/order)
  • Benchmark: NIFTY 50 via OpenAlgo (NSE_INDEX) by default
  • Charts: Plotly with template="plotly_dark"
  • Environment variables loaded from single .env at project root via find_dotenv() (walks up from script dir)
  • Scripts go in backtesting/{strategy_name}/ directories (created on-demand, not pre-created)
  • Never use icons/emojis in code or logger output

Critical Rules

  1. Default to OpenAlgo ta (from openalgo import ta) for ALL technical indicators (EMA, SMA, RSI, MACD, BBANDS, ATR, ADX, STDDEV, MOM, and 90+ more). Only use TA-Lib if the user explicitly requests "talib"/"TA-Lib" in their prompt. NEVER use vbt.MA.run(), vbt.RSI.run(), or any VectorBT built-in indicator with either library.
  2. Always use OpenAlgo ta for indicators not in TA-Lib at all: Supertrend, Donchian, Ichimoku, HMA, KAMA, ALMA, ZLEMA, VWMA - these have no TA-Lib equivalent, so they're openalgo.ta even in a TA-Lib-opt-in script.
  3. Use OpenAlgo ta for signal utilities: ta.exrem(), ta.crossover(), ta.crossunder(), ta.flip(). If openalgo.ta is not importable (standalone DuckDB), use inline exrem() fallback. See duckdb-data.
  4. Always clean signals with ta.exrem() after generating raw buy/sell signals. Always .fillna(False) before exrem.
  5. Market-specific fees: India (indian-market-costs), US (us-market-costs), Crypto (crypto-market-costs). Auto-select based on user's market.
  6. Default benchmarks: India=NIFTY via OpenAlgo, US=S&P 500 (^GSPC), Crypto=Bitcoin (BTC-USD). See data-fetching Market Selection Guide.
  7. Always produce a Strategy vs Benchmark comparison table after every backtest.
  8. Always explain the backtest report in plain language so even normal traders understand risk and strength.
  9. Plotly candlestick charts must use xaxis type="category" to avoid weekend gaps.
  10. Whole shares: Always set min_size=1, size_granularity=1 for equities.
  11. DuckDB data loading: When user provides a DuckDB path, load data directly using duckdb.connect() with read_only=True. Auto-detect format: OpenAlgo Historify (table market_data, epoch timestamps) vs custom (table ohlcv, date+time columns). See duckdb-data.

Modular Rule Files

Detailed reference for each topic is in rules/:

Rule FileTopic
data-fetchingOpenAlgo (India), yfinance (US), CCXT (Crypto), custom providers, .env setup
simulation-modesfrom_signals, from_orders, from_holding, direction types
position-sizingAmount/Value/Percent/TargetPercent sizing
indicators-signalsOpenAlgo ta indicator reference (default), TA-Lib opt-in, signal generation
openalgo-ta-helpersComplete OpenAlgo ta catalog (100+ indicators): exrem, crossover, Supertrend, Donchian, Ichimoku, MAs
stop-loss-take-profitFixed SL, TP, trailing stop
parameter-optimizationBroadcasting and loop-based optimization
performance-analysisStats, metrics, benchmark comparison, CAGR
plottingCandlestick (category x-axis), VectorBT plots, custom Plotly
indian-market-costsIndian market fee model by segment
us-market-costsUS market fee model (stocks, options, futures)
crypto-market-costsCrypto fee model (spot, USDT-M, COIN-M futures)
futures-backtestingLot sizes (SEBI revised Dec 2025), value sizing
long-short-tradingSimultaneous long/short, direction comparison
duckdb-dataDuckDB direct loading, Historify format, auto-detect, resampling, multi-symbol
csv-data-resamplingLoading CSV, resampling with Indian market alignment
walk-forwardWalk-forward analysis, WFE ratio
robustness-testingMonte Carlo, noise test, parameter sensitivity, delay test
pitfallsCommon mistakes and checklist before going live
strategy-catalogStrategy reference with code snippets
openstatz-tearsheetOpenStatz interactive offline dashboard, metrics, Monte Carlo (replaces QuantStats)

Strategy Templates (in rules/assets/)

Production-ready scripts with realistic fees, NIFTY benchmark, comparison table, and plain-language report:

TemplatePathDescription
EMA Crossoverassets/ema_crossover/backtest.pyEMA 10/20 crossover
RSIassets/rsi/backtest.pyRSI(14) oversold/overbought
Donchianassets/donchian/backtest.pyDonchian channel breakout
Supertrendassets/supertrend/backtest.pySupertrend with intraday sessions
MACDassets/macd/backtest.pyMACD signal-candle breakout
SDA2assets/sda2/backtest.pySDA2 trend following
Momentumassets/momentum/backtest.pyDouble momentum (MOM + MOM-of-MOM)
Dual Momentumassets/dual_momentum/backtest.pyQuarterly ETF rotation
Buy & Holdassets/buy_hold/backtest.pyStatic multi-asset allocation
RSI Accumulationassets/rsi_accumulation/backtest.pyWeekly RSI slab-wise accumulation
Walk-Forwardassets/walk_forward/template.pyWalk-forward analysis template
Realistic Costsassets/realistic_costs/template.pyTransaction cost impact comparison

Quick Template: Standard Backtest Script

import os
from datetime import datetime, timedelta
from pathlib import Path

import numpy as np
import pandas as pd
import vectorbt as vbt
from dotenv import find_dotenv, load_dotenv
from openalgo import api, ta

# --- Config ---
script_dir = Path(__file__).resolve().parent
load_dotenv(find_dotenv(), override=False)

SYMBOL = "SBIN"
EXCHANGE = "NSE"
INTERVAL = "D"
INIT_CASH = 1_000_000
FEES = 0.00111              # Indian delivery equity (STT + statutory)
FIXED_FEES = 20             # Rs 20 per order
ALLOCATION = 0.75
BENCHMARK_SYMBOL = "NIFTY"
BENCHMARK_EXCHANGE = "NSE_INDEX"

# --- Fetch Data ---
client = api(
    api_key=os.getenv("OPENALGO_API_KEY"),
    host=os.getenv("OPENALGO_HOST", "http://127.0.0.1:5000"),
)

end_date = datetime.now().date()
start_date = end_date - timedelta(days=365 * 3)

df = client.history(
    symbol=SYMBOL, exchange=EXCHANGE, interval=INTERVAL,
    start_date=start_date.strftime("%Y-%m-%d"),
    end_date=end_date.strftime("%Y-%m-%d"),
)
if "timestamp" in df.columns:
    df["timestamp"] = pd.to_datetime(df["timestamp"])
    df = df.set_index("timestamp")
else:
    df.index = pd.to_datetime(df.index)
df = df.sort_index()
if df.index.tz is not None:
    df.index = df.index.tz_convert(None)

close = df["close"]

# --- Strategy: EMA Crossover (OpenAlgo ta - default indicator library) ---
ema_fast = ta.ema(close, 10)
ema_slow = ta.ema(close, 20)

buy_raw = (ema_fast > ema_slow) & (ema_fast.shift(1) <= ema_slow.shift(1))
sell_raw = (ema_fast < ema_slow) & (ema_fast.shift(1) >= ema_slow.shift(1))

entries = ta.exrem(buy_raw.fillna(False), sell_raw.fillna(False))
exits = ta.exrem(sell_raw.fillna(False), buy_raw.fillna(False))

# --- Backtest ---
pf = vbt.Portfolio.from_signals(
    close, entries, exits,
    init_cash=INIT_CASH, size=ALLOCATION, size_type="percent",
    fees=FEES, fixed_fees=FIXED_FEES, direction="longonly",
    min_size=1, size_granularity=1, freq="1D",
)

# --- Benchmark ---
df_bench = client.history(
    symbol=BENCHMARK_SYMBOL, exchange=BENCHMARK_EXCHANGE, interval=INTERVAL,
    start_date=start_date.strftime("%Y-%m-%d"),
    end_date=end_date.strftime("%Y-%m-%d"),
)
if "timestamp" in df_bench.columns:
    df_bench["timestamp"] = pd.to_datetime(df_bench["timestamp"])
    df_bench = df_bench.set_index("timestamp")
else:
    df_bench.index = pd.to_datetime(df_bench.index)
df_bench = df_bench.sort_index()
if df_bench.index.tz is not None:
    df_bench.index = df_bench.index.tz_convert(None)
bench_close = df_bench["close"].reindex(close.index).ffill().bfill()
pf_bench = vbt.Portfolio.from_holding(bench_close, init_cash=INIT_CASH, fees=FEES, freq="1D")

# --- Results ---
print(pf.stats())

# --- Strategy vs Benchmark ---
comparison = pd.DataFrame({
    "Strategy": [
        f"{pf.total_return() * 100:.2f}%", f"{pf.sharpe_ratio():.2f}",
        f"{pf.sortino_ratio():.2f}", f"{pf.max_drawdown() * 100:.2f}%",
        f"{pf.trades.win_rate() * 100:.1f}%", f"{pf.trades.count()}",
        f"{pf.trades.profit_factor():.2f}",
    ],
    f"Benchmark ({BENCHMARK_SYMBOL})": [
        f"{pf_bench.total_return() * 100:.2f}%", f"{pf_bench.sharpe_ratio():.2f}",
        f"{pf_bench.sortino_ratio():.2f}", f"{pf_bench.max_drawdown() * 100:.2f}%",
        "-", "-", "-",
    ],
}, index=["Total Return", "Sharpe Ratio", "Sortino Ratio", "Max Drawdown",
          "Win Rate", "Total Trades", "Profit Factor"])
print(comparison.to_string())

# --- Explain ---
print(f"* Total Return: {pf.total_return() * 100:.2f}% vs NIFTY {pf_bench.total_return() * 100:.2f}%")
print(f"* Max Drawdown: {pf.max_drawdown() * 100:.2f}%")
print(f"  -> On Rs {INIT_CASH:,}, worst temporary loss = Rs {abs(pf.max_drawdown()) * INIT_CASH:,.0f}")

# --- Plot ---
fig = pf.plot(subplots=['value', 'underwater', 'cum_returns'], template="plotly_dark")
fig.show()

# --- Export ---
pf.positions.records_readable.to_csv(script_dir / f"{SYMBOL}_trades.csv", index=False)

Quick Template: DuckDB Backtest Script

import datetime as dt
from pathlib import Path

import duckdb
import numpy as np
import pandas as pd
import vectorbt as vbt

try:
    # Default: OpenAlgo ta for both indicators and signal cleaning
    from openalgo import ta
    exrem = ta.exrem
    ema = ta.ema
except ImportError:
    # Fallback ONLY when the openalgo package itself is not installed
    # (standalone DuckDB with no OpenAlgo). Use TA-Lib for indicators
    # and this inline exrem() replacement for signal cleaning.
    import talib as tl

    def ema(data, period):
        return pd.Series(tl.EMA(data.values, timeperiod=period), index=data.index)

    def exrem(signal1, signal2):
        result = signal1.copy()
        active = False
        for i in range(len(signal1)):
            if active:
                result.iloc[i] = False
            if signal1.iloc[i] and not active:
                active = True
            if signal2.iloc[i]:
                active = False
        return result

# --- Config ---
SYMBOL = "SBIN"
DB_PATH = r"path/to/market_data.duckdb"
INIT_CASH = 1_000_000
FEES = 0.000225              # Intraday equity
FIXED_FEES = 20

# --- Load from DuckDB ---
con = duckdb.connect(DB_PATH, read_only=True)
df = con.execute("""
    SELECT date, time, open, high, low, close, volume
    FROM ohlcv WHERE symbol = ? ORDER BY date, time
""", [SYMBOL]).fetchdf()
con.close()

df["datetime"] = pd.to_datetime(df["date"].astype(str) + " " + df["time"].astype(str))
df = df.set_index("datetime").sort_index()
df = df.drop(columns=["date", "time"])

# --- Resample to 5min ---
df_5m = df.resample("5min", origin="start_day", offset="9h15min",
                     label="right", closed="right").agg({
    "open": "first", "high": "max", "low": "min", "close": "last", "volume": "sum"
}).dropna()
close = df_5m["close"]

# --- Strategy + Backtest (same as OpenAlgo template, but use the ema()/exrem() resolved above) ---

If the user explicitly asks for TA-Lib, skip the try/except above and import talib as tl directly instead - the exrem fallback is only for when openalgo itself is unavailable.

FAQ

What does the vectorbt-expert skill do?

VectorBT backtesting expert. Use when user asks to backtest strategies, create entry/exit signals, analyze portfolio performance, optimize parameters, fetch historical data, use VectorBT/vectorbt, compare strategies, position sizing, equity curves, drawdown charts, or trade analysis. Also triggers for openalgo.ta helpers (exrem, crossover, crossunder, flip, donchian, supertrend).

How do I install vectorbt-expert?

Run npx skills add https://github.com/marketcalls/vectorbt-backtesting-skills --skill vectorbt-expert in your project. The skills CLI detects the agents you use and copies the skill into the right folder. For Claude Code you can also place the skill folder at ~/.claude/skills/vectorbt-expert/ (personal) or .claude/skills/vectorbt-expert/ (project).

Which AI agents can use vectorbt-expert?

Any agent that supports the open Agent Skills format (a folder with a SKILL.md file), including Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, Windsurf, Cline, OpenCode and more.

Is vectorbt-expert safe to install?

No partner security audit is available yet. Skills can run commands and scripts, so read the SKILL.md and any bundled files before installing.

Who maintains vectorbt-expert?

It is published by marketcalls in marketcalls/vectorbt-backtesting-skills. It has 2,964 recorded installs.

More from marketcalls/vectorbt-backtesting-skills

View all →

backtest

marketcalls/vectorbt-backtesting-skills

Quick backtest a strategy on a symbol. Creates a complete .py script with data fetch, signals, backtest, stats, and plots.

3.4K installs

optimize

marketcalls/vectorbt-backtesting-skills

Optimize strategy parameters using VectorBT. Tests parameter combinations and generates heatmaps.

Testing & QA2.4K installs

strategy-compare

marketcalls/vectorbt-backtesting-skills

Compare multiple strategies or directions (long vs short vs both) on the same symbol. Generates side-by-side stats table.

2.3K installs

quick-stats

marketcalls/vectorbt-backtesting-skills

Quickly fetch data and print key backtest stats for a symbol with a default EMA crossover strategy. No file creation needed - runs inline in a notebook cell or prints to console.

2K installs

setup

marketcalls/vectorbt-backtesting-skills

Set up the Python backtesting environment. Detects OS, creates virtual environment, installs dependencies (openalgo, ta-lib, vectorbt, plotly), and creates the backtesting folder structure.

2K installs

Popular code quality & workflow skills

View category →

grill-me

mattpocock/skills

A relentless interview to sharpen a plan or design.

Scan a codebase for deepening opportunities, present them as a visual HTML report, then grill through whichever one you pick.

handoff

mattpocock/skills

Compact the current conversation into a handoff document for another agent to pick up.

domain-modeling

mattpocock/skills

Build and sharpen a project's domain model. Use when discussing codebase terminology, writing or editing a GLOSSARY.md, or recording or editing an ADR.

codebase-design

mattpocock/skills

Shared vocabulary for designing deep modules. Use when the user wants to design or improve a module's interface, find deepening opportunities, decide where a seam goes, make code more testable or AI-navigable, or when another skill needs the deep-module vocabulary.

diagnosing-bugs

mattpocock/skills

Diagnosis loop for hard bugs and performance regressions. Use when the user says "diagnose"/"debug this", or reports something broken/throwing/failing/slow.