
Backtest
Generate a complete VectorBT backtest Python script for a named strategy and symbol, with data fetch, signals, stats, and plots—ready to run in your repo.
Overview
backtest is an agent skill most often used in Validate (also Build integrations) that creates a complete VectorBT backtest script with data fetch, signals, statistics, and plots for a given strategy and symbol.
Install
npx skills add https://github.com/marketcalls/vectorbt-backtesting-skills --skill backtestWhat is this skill?
- Parses strategy, symbol, exchange, and interval from skill arguments
- Creates `backtesting/{strategy_name}/{symbol}_{strategy}_backtest.py` on demand
- Pulls OHLCV via OpenAlgo `client.history()` or optional DuckDB read-only path
- Starts from `rules/assets/{strategy}/backtest.py` templates in the vectorbt-expert ruleset
- Loads project `.env` with `find_dotenv()` walking up from the script directory
- Four CLI arguments: strategy, symbol, exchange, interval
- Default symbol SBIN, exchange NSE, interval D when omitted
Adoption & trust: 1.8k installs on skills.sh; 150 GitHub stars; 3/3 security scanners passed (skills.sh audits).
What problem does it solve?
You have a strategy name and ticker in mind but no standardized script that fetches data, runs VectorBT, and outputs stats and charts in your repo layout.
Who is it for?
Solo traders and builders already using OpenAlgo or local DuckDB who want repeatable VectorBT backtest files per strategy and symbol.
Skip if: Live order execution, compliance-reviewed production trading, or users who need backtests without Python, Bash, or market data credentials.
When should I use this skill?
User wants a quick VectorBT backtest for a strategy and symbol, or passes strategy/symbol/exchange/interval as skill arguments.
What do I get? / Deliverables
You receive a named `.py` backtest under `backtesting/{strategy}/` that runs against OpenAlgo or DuckDB and follows vectorbt-expert template patterns.
- Runnable `{symbol}_{strategy}_backtest.py` with plots and performance stats
- On-demand `backtesting/{strategy_name}/` directory structure
Recommended Skills
Journey fit
Spans multiple journey phases - primary shelf plus alternate fits below.
Validate is the canonical shelf because the skill’s purpose is proving a trading hypothesis with historical simulation before you productionize execution. Prototype matches on-demand script generation under `backtesting/{strategy}/` rather than shipping a live trading system.
Where it fits
Run a daily SBIN ema-crossover backtest to see if the idea merits further parameter tuning.
Compare strategy hit rates across symbols before committing to a paid data or brokerage integration tier.
Wire OpenAlgo `client.history()` and `.env` loading into a new strategy directory matching repo conventions.
How it compares
Use instead of ad-hoc notebook cells that omit env loading, exchange defaults, and shared strategy templates.
Common Questions / FAQ
Who is backtest for?
Developers and indie quants automating VectorBT strategy tests with OpenAlgo or DuckDB in a consistent `backtesting/` folder structure.
When should I use backtest?
Use it in Validate to prototype signal performance on a symbol, and in Build when you are adding a new strategy folder and script alongside vectorbt-expert rules.
Is backtest safe to install?
See the Security Audits panel on this Prism page; the skill uses Bash and writes files and may call external market data APIs using your `.env` secrets.
Workflow Chain
Requires first: vectorbt expert
SKILL.md
READMESKILL.md - Backtest
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 5. Never use icons/emojis in code or logger output 6. 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 | 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 `^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`