Vectorbt-backtesting-skills backtest
Quick backtest a strategy on a symbol. Creates a complete .py script with data fetch, signals, backtest, stats, and plots.
install
source · Clone the upstream repo
git clone https://github.com/marketcalls/vectorbt-backtesting-skills
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/marketcalls/vectorbt-backtesting-skills "$T" && mkdir -p ~/.claude/skills && cp -r "$T/.claude/skills/backtest" ~/.claude/skills/marketcalls-vectorbt-backtesting-skills-backtest && rm -rf "$T"
manifest:
.claude/skills/backtest/SKILL.mdsource content
Create a complete VectorBT backtest script for the user.
Arguments
Parse
$ARGUMENTS as: strategy symbol exchange interval
= strategy name (e.g., ema-crossover, rsi, donchian, supertrend, macd, sda2, momentum)$0
= symbol (e.g., SBIN, RELIANCE, NIFTY). Default: SBIN$1
= exchange (e.g., NSE, NFO). Default: NSE$2
= interval (e.g., D, 1h, 5m). Default: D$3
If no arguments, ask the user which strategy they want.
Instructions
- Read the vectorbt-expert skill rules for reference patterns
- Create
directory if it doesn't exist (on-demand)backtesting/{strategy_name}/ - Create a
file in.py
namedbacktesting/{strategy_name}/{symbol}_{strategy}_backtest.py - Use the matching template from
as the starting pointrules/assets/{strategy}/backtest.py - The script must:
- Load
from the project root using.env
(walks up from script dir automatically)find_dotenv() - Fetch data via
from OpenAlgoclient.history() - If user provides a DuckDB path, load data directly via
instead of OpenAlgo API. Auto-detect format: Historify (duckdb.connect(path, read_only=True)
table, epoch timestamps) vs custom (market_data
table, date+time). See vectorbt-expertohlcv
.rules/duckdb-data.md - If
is not importable (standalone DuckDB), use inlineopenalgo.ta
fallback.exrem() - 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
to clean duplicate signals (alwaysta.exrem()
before exrem).fillna(False) - Run
withvbt.Portfolio.from_signals()min_size=1, size_granularity=1 - Indian delivery fees:
for delivery equityfees=0.00111, fixed_fees=20 - 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
is availablequantstats - 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:
(effective 31 Dec 2025)min_size=65, size_granularity=65 - BANKNIFTY:
min_size=30, size_granularity=30 - Use
for F&O futuresfees=0.00018, fixed_fees=20
- NIFTY:
Available Strategies
| Strategy | Keyword | Template |
|---|---|---|
| EMA Crossover | | |
| RSI | | |
| Donchian Channel | | |
| Supertrend | | |
| MACD Breakout | | |
| SDA2 | | |
| Momentum | | |
| Dual Momentum | | |
| Buy & Hold | | |
| RSI Accumulation | | |
Benchmark Rules
- Default: NIFTY 50 via OpenAlgo (
)symbol="NIFTY", exchange="NSE_INDEX" - If user specifies a different benchmark, use that instead
- For yfinance: use
for India,^NSEI
(S&P 500) for US markets^GSPC - Always compare: Total Return, Sharpe, Sortino, Max Drawdown
Example Usage
/backtest ema-crossover RELIANCE NSE D
/backtest rsi SBIN
/backtest supertrend NIFTY NFO 5m