PluginBench
Skill
Pass
Audit score 90

backtest

marketcalls/vectorbt-backtesting-skills

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

What is backtest?

Backtest creates a full Python script that fetches historical data, applies a trading strategy, runs a vectorized backtest, and generates performance statistics and plots. Use it to validate strategy ideas on Indian equities and futures with realistic fees and benchmark comparison.

  • Generates complete .py backtest scripts from strategy templates (EMA, RSI, MACD, Supertrend, Donchian, etc.)
  • Fetches data via OpenAlgo API or loads from DuckDB for offline analysis
  • Applies TA-Lib and OpenAlgo indicators with automatic signal cleaning via exrem()
  • Runs vectorized portfolio backtest with Indian delivery/futures fees and lot-size constraints
  • Compares strategy performance vs NIFTY benchmark (Total Return, Sharpe, Sortino, Max DD, Win Rate)
  • Generates Plotly equity curves, drawdown plots, QuantStats tearsheets, and CSV trade exports

How to install backtest

npx skills add https://github.com/marketcalls/vectorbt-backtesting-skills --skill backtest
Prerequisites
  • VectorBT library installed
  • TA-Lib installed for technical indicators
  • OpenAlgo API credentials in .env (or DuckDB file path for offline backtesting)
  • Python 3.7+
Claude Code
Cursor
Windsurf
Cline

How to use backtest

  1. 1.Call the skill with strategy name, symbol, exchange, and interval (e.g., `/backtest ema-crossover RELIANCE NSE D`)
  2. 2.The skill generates a .py script in `backtesting/{strategy_name}/` directory
  3. 3.Run the generated script: `python backtesting/{strategy_name}/{symbol}_{strategy}_backtest.py`
  4. 4.Review the printed stats table comparing strategy vs NIFTY benchmark
  5. 5.Check the generated Plotly HTML plot and QuantStats tearsheet for detailed analysis
  6. 6.Export trades CSV for further review or optimization

Use cases

Good for
  • Validate an EMA crossover strategy on RELIANCE equity before live trading
  • Backtest a Supertrend strategy on NIFTY futures with correct lot sizing (65 contracts minimum)
  • Compare RSI strategy performance across multiple timeframes (daily, hourly, 5-minute)
  • Export backtest trades to CSV for manual review and optimization
  • Generate benchmark comparison to see if strategy beats NIFTY 50 on risk-adjusted returns
Who it's for
  • Retail traders testing strategy ideas on Indian markets
  • Quantitative analysts validating trading signals before deployment
  • Day traders evaluating intraday strategies on futures
  • Portfolio managers comparing strategy performance to benchmarks

backtest FAQ

What data sources does backtest support?

OpenAlgo API (default, requires .env credentials) or DuckDB files (offline). Auto-detects Historify format (market_data table) or custom format (ohlcv table).

How are Indian trading fees handled?

Equity delivery: 0.111% + ₹20 fixed. Futures (NIFTY/BANKNIFTY): 0.018% + ₹20 fixed. Lot sizes enforced (NIFTY min 65, BANKNIFTY min 30).

Can I backtest intraday strategies?

Yes. Specify interval as 1h, 5m, 15m, etc. The script handles any timeframe supported by your data source.

What strategies are available?

EMA Crossover, RSI, Donchian, Supertrend, MACD, SDA2, Momentum, Dual Momentum, Buy & Hold, RSI Accumulation.

How is the benchmark comparison calculated?

Fetches NIFTY 50 data (symbol=NIFTY, exchange=NSE_INDEX) and compares Total Return, Sharpe Ratio, Sortino Ratio, Max Drawdown, Win Rate, Trade Count, and Profit Factor.

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 TA-Lib for ALL indicators (EMA, SMA, RSI, MACD, BBands, ATR, ADX, STDDEV, MOM)
    • Use OpenAlgo ta for specialty indicators (Supertrend, Donchian, Ichimoku, HMA, KAMA, ALMA)
    • 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 QuantStats HTML tearsheet if quantstats is available
    • 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