PluginBench
Skill
Pass
Audit score 90

backtest

marketcalls/vectorbt-backtesting-skills

Generate complete backtesting scripts for trading strategies with data fetch, signals, stats, and plots.

What is backtest?

Creates a full Python backtesting script using VectorBT for a specified strategy, symbol, and timeframe. Includes data fetching from OpenAlgo or DuckDB, indicator calculations, portfolio analysis, benchmark comparison, and interactive dashboards. Use this to quickly validate trading strategy performance on historical data.

  • Generates complete .py backtesting scripts with data fetch, signal generation, and portfolio analysis
  • Supports 10+ built-in strategies (EMA Crossover, RSI, Donchian, Supertrend, MACD, SDA2, Momentum, and more)
  • Fetches data from OpenAlgo API or local DuckDB databases with automatic format detection
  • Calculates 90+ technical indicators via OpenAlgo ta library (or TA-Lib if explicitly requested)
  • Compares strategy performance against NIFTY 50 benchmark with key metrics (Sharpe, Sortino, Max DD, Win Rate)
  • Generates interactive OpenStatz dashboards and Plotly equity curve visualizations

How to install backtest

npx skills add https://github.com/marketcalls/vectorbt-backtesting-skills --skill backtest
Prerequisites
  • VectorBT library installed
  • OpenAlgo API credentials (for live data fetch) or local DuckDB file (for offline backtesting)
  • Python 3.7+ with pandas, numpy, plotly
  • Optional: TA-Lib for specialty indicators; OpenStatz for interactive dashboards
Claude Code
Cursor
Windsurf
Cline

How to use backtest

  1. 1.Run the skill with strategy name, symbol, exchange, and interval (e.g., `/backtest ema-crossover SBIN NSE D`)
  2. 2.The skill generates a complete .py script in `backtesting/{strategy}/` directory
  3. 3.Execute the generated script to fetch data, calculate signals, run backtest, and generate reports
  4. 4.Review the console output for strategy stats, benchmark comparison, and trade summary
  5. 5.Open the generated HTML dashboard (if OpenStatz available) for interactive performance analysis
  6. 6.Check the exported CSV file for detailed trade-by-trade breakdown

Use cases

Good for
  • Backtest an EMA crossover strategy on RELIANCE daily data to evaluate entry/exit logic
  • Validate a Supertrend strategy on NIFTY futures with proper lot-size constraints and F&O fees
  • Compare RSI strategy performance across multiple symbols and timeframes (5m, 1h, daily)
  • Analyze strategy drawdown and recovery patterns using interactive HTML dashboards
  • Export trade history for manual review and optimization of signal parameters
Who it's for
  • Retail traders validating strategy ideas before live trading
  • Quantitative analysts comparing strategy performance metrics
  • Trading system developers building automated strategy libraries
  • Financial engineers backtesting multi-timeframe or multi-symbol strategies

backtest FAQ

Which data sources are supported?

OpenAlgo API (live/historical) and local DuckDB databases. The script auto-detects DuckDB format (Historify vs custom) and falls back to inline indicators if openalgo.ta is unavailable.

Can I use TA-Lib instead of OpenAlgo ta?

Only if you explicitly request it. OpenAlgo ta is the default and includes 90+ indicators. TA-Lib is used only on explicit user request; specialty indicators (Supertrend, Donchian, Ichimoku) always use OpenAlgo ta.

How are Indian equity and futures fees handled?

Delivery equity: 0.111% + ₹20 fixed. Futures (NIFTY/BANKNIFTY): 0.018% + ₹20 fixed. Lot sizes are enforced (NIFTY: 65, BANKNIFTY: 30).

What benchmark is used for comparison?

NIFTY 50 by default via OpenAlgo. You can specify a different benchmark; yfinance symbols like ^NSEI (India) or ^GSPC (US) are also supported.

What outputs does the script generate?

Console stats table, strategy vs benchmark comparison, interactive OpenStatz HTML dashboard, Plotly equity/drawdown charts, and CSV trade export.

Full instructions (SKILL.md)

Source of truth, from marketcalls/vectorbt-backtesting-skills.


name: backtest description: Quick backtest a strategy on a symbol. Creates a complete .py script with data fetch, signals, backtest, stats, and plots. argument-hint: "[strategy] [symbol] [exchange] [interval]" allowed-tools: Read, Write, Edit, Bash, Glob, Grep

Create a complete VectorBT backtest script for the user.

Arguments

Parse $ARGUMENTS as: strategy symbol exchange interval

  • $0 = strategy name (e.g., ema-crossover, rsi, donchian, supertrend, macd, sda2, momentum)
  • $1 = symbol (e.g., SBIN, RELIANCE, NIFTY). Default: SBIN
  • $2 = exchange (e.g., NSE, NFO). Default: NSE
  • $3 = interval (e.g., D, 1h, 5m). Default: D

If no arguments, ask the user which strategy they want.

Instructions

  1. Read the vectorbt-expert skill rules for reference patterns
  2. Create backtesting/{strategy_name}/ directory if it doesn't exist (on-demand)
  3. Create a .py file in backtesting/{strategy_name}/ named {symbol}_{strategy}_backtest.py
  4. Use the matching template from rules/assets/{strategy}/backtest.py as the starting point
  5. The script must:
    • Load .env from the project root using find_dotenv() (walks up from script dir automatically)
    • Fetch data via client.history() from OpenAlgo
    • If user provides a DuckDB path, load data directly via duckdb.connect(path, read_only=True) instead of OpenAlgo API. Auto-detect format: Historify (market_data table, epoch timestamps) vs custom (ohlcv table, date+time). See vectorbt-expert rules/duckdb-data.md.
    • If openalgo.ta is not importable (standalone DuckDB), use inline exrem() fallback.
    • Use OpenAlgo ta for ALL indicators by default (EMA, SMA, RSI, MACD, BBands, ATR, ADX, STDDEV, MOM, and 90+ more) - from openalgo import ta
    • Only use TA-Lib if the user explicitly says "talib"/"TA-Lib" in their request; specialty indicators (Supertrend, Donchian, Ichimoku, HMA, KAMA, ALMA, ZLEMA, VWMA) always come from OpenAlgo ta regardless, since TA-Lib has no equivalent
    • Use ta.exrem() to clean duplicate signals (always .fillna(False) before exrem)
    • Run vbt.Portfolio.from_signals() with min_size=1, size_granularity=1
    • Indian delivery fees: fees=0.00111, fixed_fees=20 for delivery equity
    • Fetch NIFTY benchmark via OpenAlgo (symbol="NIFTY", exchange="NSE_INDEX")
    • Print full pf.stats()
    • Print Strategy vs Benchmark comparison table (Total Return, Sharpe, Sortino, Max DD, Win Rate, Trades, Profit Factor)
    • Explain the backtest report in plain language for normal traders
    • Generate the OpenStatz interactive dashboard tearsheet via ostz.dashboard(...) if openstatz is available - a self-contained offline HTML file, no server needed (always use OpenStatz, never QuantStats; never the legacy ostz.reports.html static report). Set strategy_returns.name (e.g. "EMA 20/50 Crossover - SBIN") and benchmark.name before calling dashboard() - that name, not the title= argument, is what the tearsheet shows as the strategy header/column/legend (see the openstatz-tearsheet rule)
    • Plot equity curve + drawdown using Plotly (template="plotly_dark")
    • Export trades to CSV
  6. Never use icons/emojis in code or logger output
  7. For futures symbols (NIFTY, BANKNIFTY), use lot-size-aware sizing:
    • NIFTY: min_size=65, size_granularity=65 (effective 31 Dec 2025)
    • BANKNIFTY: min_size=30, size_granularity=30
    • Use fees=0.00018, fixed_fees=20 for F&O futures

Available Strategies

StrategyKeywordTemplate
EMA Crossoverema-crossoverassets/ema_crossover/backtest.py
RSIrsiassets/rsi/backtest.py
Donchian Channeldonchianassets/donchian/backtest.py
Supertrendsupertrendassets/supertrend/backtest.py
MACD Breakoutmacdassets/macd/backtest.py
SDA2sda2assets/sda2/backtest.py
Momentummomentumassets/momentum/backtest.py
Dual Momentumdual-momentumassets/dual_momentum/backtest.py
Buy & Holdbuy-holdassets/buy_hold/backtest.py
RSI Accumulationrsi-accumulationassets/rsi_accumulation/backtest.py

Benchmark Rules

  • Default: NIFTY 50 via OpenAlgo (symbol="NIFTY", exchange="NSE_INDEX")
  • If user specifies a different benchmark, use that instead
  • For yfinance: use ^NSEI for India, ^GSPC (S&P 500) for US markets
  • Always compare: Total Return, Sharpe, Sortino, Max Drawdown

Example Usage

/backtest ema-crossover RELIANCE NSE D /backtest rsi SBIN /backtest supertrend NIFTY NFO 5m