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- 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
How to use backtest
- 1.Run the skill with strategy name, symbol, exchange, and interval (e.g., `/backtest ema-crossover SBIN NSE D`)
- 2.The skill generates a complete .py script in `backtesting/{strategy}/` directory
- 3.Execute the generated script to fetch data, calculate signals, run backtest, and generate reports
- 4.Review the console output for strategy stats, benchmark comparison, and trade summary
- 5.Open the generated HTML dashboard (if OpenStatz available) for interactive performance analysis
- 6.Check the exported CSV file for detailed trade-by-trade breakdown
Use cases
- 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
- 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
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.
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.
Delivery equity: 0.111% + ₹20 fixed. Futures (NIFTY/BANKNIFTY): 0.018% + ₹20 fixed. Lot sizes are enforced (NIFTY: 65, BANKNIFTY: 30).
NIFTY 50 by default via OpenAlgo. You can specify a different benchmark; yfinance symbols like ^NSEI (India) or ^GSPC (US) are also supported.
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
- Read the vectorbt-expert skill rules for reference patterns
- Create
backtesting/{strategy_name}/directory if it doesn't exist (on-demand) - Create a
.pyfile inbacktesting/{strategy_name}/named{symbol}_{strategy}_backtest.py - Use the matching template from
rules/assets/{strategy}/backtest.pyas the starting point - The script must:
- Load
.envfrom the project root usingfind_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_datatable, epoch timestamps) vs custom (ohlcvtable, date+time). See vectorbt-expertrules/duckdb-data.md. - If
openalgo.tais not importable (standalone DuckDB), use inlineexrem()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()withmin_size=1, size_granularity=1 - Indian delivery fees:
fees=0.00111, fixed_fees=20for 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(...)ifopenstatzis available - a self-contained offline HTML file, no server needed (always use OpenStatz, never QuantStats; never the legacyostz.reports.htmlstatic report). Setstrategy_returns.name(e.g."EMA 20/50 Crossover - SBIN") andbenchmark.namebefore callingdashboard()- that name, not thetitle=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
- Load
- Never use icons/emojis in code or logger output
- 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=20for F&O futures
- NIFTY:
Available Strategies
| Strategy | Keyword | Template |
|---|---|---|
| EMA Crossover | ema-crossover | assets/ema_crossover/backtest.py |
| RSI | rsi | assets/rsi/backtest.py |
| Donchian Channel | donchian | assets/donchian/backtest.py |
| Supertrend | supertrend | assets/supertrend/backtest.py |
| MACD Breakout | macd | assets/macd/backtest.py |
| SDA2 | sda2 | assets/sda2/backtest.py |
| Momentum | momentum | assets/momentum/backtest.py |
| Dual Momentum | dual-momentum | assets/dual_momentum/backtest.py |
| Buy & Hold | buy-hold | assets/buy_hold/backtest.py |
| RSI Accumulation | rsi-accumulation | assets/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
^NSEIfor 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
Related skills
More from marketcalls/vectorbt-backtesting-skills and the wider catalog.

optimize
Optimize trading strategy parameters using VectorBT with heatmap visualization and benchmark comparison.

quick-stats
Quickly backtest a symbol with EMA crossover strategy and print key stats inline—no file creation.

setup
Set up a complete Python backtesting environment with VectorBT, OpenAlgo, and market data sources.

strategy-compare
Compare multiple trading strategies side-by-side with performance metrics and equity curves.

vectorbt-expert
VectorBT backtesting expert for strategy testing, signal generation, and portfolio optimization.

claude-brainrot
Always-on meme dropper that fires image+sound combos and sound-only hits automatically on every user message.