con un clic
backtest
// Quick backtest a strategy on a symbol. Creates a complete .py script with data fetch, signals, backtest, stats, and plots.
// Quick backtest a strategy on a symbol. Creates a complete .py script with data fetch, signals, backtest, stats, and plots.
Optimize strategy parameters using VectorBT. Tests parameter combinations and generates heatmaps.
Quickly fetch data and print key backtest stats for a symbol with a default EMA crossover strategy. No file creation needed - runs inline in a notebook cell or prints to console.
Set up the Python backtesting environment. Detects OS, creates virtual environment, installs dependencies (openalgo, ta-lib, vectorbt, plotly), and creates the backtesting folder structure.
Compare multiple strategies or directions (long vs short vs both) on the same symbol. Generates side-by-side stats table.
VectorBT backtesting expert. Use when user asks to backtest strategies, create entry/exit signals, analyze portfolio performance, optimize parameters, fetch historical data, use VectorBT/vectorbt, compare strategies, position sizing, equity curves, drawdown charts, or trade analysis. Also triggers for openalgo.ta helpers (exrem, crossover, crossunder, flip, donchian, supertrend).
| 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.
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: DIf no arguments, ask the user which strategy they want.
backtesting/{strategy_name}/ directory if it doesn't exist (on-demand).py file in backtesting/{strategy_name}/ named {symbol}_{strategy}_backtest.pyrules/assets/{strategy}/backtest.py as the starting point.env from the project root using find_dotenv() (walks up from script dir automatically)client.history() from OpenAlgoduckdb.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.openalgo.ta is not importable (standalone DuckDB), use inline exrem() fallback.ta.exrem() to clean duplicate signals (always .fillna(False) before exrem)vbt.Portfolio.from_signals() with min_size=1, size_granularity=1fees=0.00111, fixed_fees=20 for delivery equitysymbol="NIFTY", exchange="NSE_INDEX")pf.stats()quantstats is availabletemplate="plotly_dark")min_size=65, size_granularity=65 (effective 31 Dec 2025)min_size=30, size_granularity=30fees=0.00018, fixed_fees=20 for F&O futures| 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 |
symbol="NIFTY", exchange="NSE_INDEX")^NSEI for India, ^GSPC (S&P 500) for US markets/backtest ema-crossover RELIANCE NSE D
/backtest rsi SBIN
/backtest supertrend NIFTY NFO 5m