$npx -y skills add marketcalls/vectorbt-backtesting-skills --skill vectorbt-expertVectorBT 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 analy
| 1 | # VectorBT Backtesting Expert Skill |
| 2 | |
| 3 | ## Environment |
| 4 | |
| 5 | - Python with vectorbt, pandas, numpy, plotly |
| 6 | - Data sources: OpenAlgo (Indian markets), DuckDB (direct database), yfinance (US/Global), CCXT (Crypto), custom providers |
| 7 | - DuckDB support: supports both custom DuckDB and OpenAlgo Historify format |
| 8 | - API keys loaded from single root `.env` via `python-dotenv` + `find_dotenv()` — never hardcode keys |
| 9 | - Technical indicators: **OpenAlgo ta** (DEFAULT - `from openalgo import ta`, 100+ indicators covering trend/momentum/volatility/volume/oscillators/statistical/hybrid). Use **TA-Lib** only if the user explicitly asks for TA-Lib/talib. NEVER use VectorBT built-in indicators either way. |
| 10 | - Specialty indicators (no TA-Lib equivalent, always `openalgo.ta`): Supertrend, Donchian, Ichimoku, HMA, KAMA, ALMA, ZLEMA, VWMA |
| 11 | - Signal cleaning: `openalgo.ta` for exrem, crossover, crossunder, flip (always, regardless of indicator library) |
| 12 | - Fee model: Indian market standard (STT + statutory charges + Rs 20/order) |
| 13 | - Benchmark: NIFTY 50 via OpenAlgo (`NSE_INDEX`) by default |
| 14 | - Charts: Plotly with `template="plotly_dark"` |
| 15 | - Environment variables loaded from single `.env` at project root via `find_dotenv()` (walks up from script dir) |
| 16 | - Scripts go in `backtesting/{strategy_name}/` directories (created on-demand, not pre-created) |
| 17 | - Never use icons/emojis in code or logger output |
| 18 | |
| 19 | ## Critical Rules |
| 20 | |
| 21 | 1. **Default to OpenAlgo ta** (`from openalgo import ta`) for ALL technical indicators (EMA, SMA, RSI, MACD, BBANDS, ATR, ADX, STDDEV, MOM, and 90+ more). **Only use TA-Lib if the user explicitly requests "talib"/"TA-Lib"** in their prompt. NEVER use `vbt.MA.run()`, `vbt.RSI.run()`, or any VectorBT built-in indicator with either library. |
| 22 | 2. **Always use OpenAlgo ta** for indicators not in TA-Lib at all: Supertrend, Donchian, Ichimoku, HMA, KAMA, ALMA, ZLEMA, VWMA - these have no TA-Lib equivalent, so they're openalgo.ta even in a TA-Lib-opt-in script. |
| 23 | 3. **Use OpenAlgo ta** for signal utilities: `ta.exrem()`, `ta.crossover()`, `ta.crossunder()`, `ta.flip()`. If `openalgo.ta` is not importable (standalone DuckDB), use inline `exrem()` fallback. See [duckdb-data](rules/duckdb-data.md). |
| 24 | 4. **Always clean signals** with `ta.exrem()` after generating raw buy/sell signals. Always `.fillna(False)` before exrem. |
| 25 | 5. **Market-specific fees**: India ([indian-market-costs](rules/indian-market-costs.md)), US ([us-market-costs](rules/us-market-costs.md)), Crypto ([crypto-market-costs](rules/crypto-market-costs.md)). Auto-select based on user's market. |
| 26 | 6. **Default benchmarks**: India=NIFTY via OpenAlgo, US=S&P 500 (`^GSPC`), Crypto=Bitcoin (`BTC-USD`). See [data-fetching](rules/data-fetching.md) Market Selection Guide. |
| 27 | 7. **Always produce** a Strategy vs Benchmark comparison table after every backtest. |
| 28 | 8. **Always explain** the backtest report in plain language so even normal traders understand risk and strength. |
| 29 | 9. **Plotly candlestick charts** must use `xaxis type="category"` to avoid weekend gaps. |
| 30 | 10. **Whole shares**: Always set `min_size=1, size_granularity=1` for equities. |
| 31 | 11. **DuckDB data loading**: When user provides a DuckDB path, load data directly using `duckdb.connect()` with `read_only=True`. Auto-detect format: OpenAlgo Historify (table `market_data`, epoch timestamps) vs custom (table `ohlcv`, date+time columns). See [duckdb-data](rules/duckdb-data.md). |
| 32 | |
| 33 | ## Modular Rule Files |
| 34 | |
| 35 | Detailed reference for each topic is in `rules/`: |
| 36 | |
| 37 | | Rule File | Topic | |
| 38 | |-----------|-------| |
| 39 | | [data-fetching](rules/data-fetching.md) | OpenAlgo (India), yfinance (US), CCXT (Crypto), custom providers, .env setup | |
| 40 | | [simulation-modes](rules/simulation-modes.md) | from_signals, from_orders, from_holding, direction types | |
| 41 | | [position-sizing](rules/position-sizing.md) | Amount/Value/Percent/TargetPercent sizing | |
| 42 | | [indicators-signals](rules/indicators-signals.md) | OpenAlgo ta indicator reference (default), TA-Lib opt-in, signal generation | |
| 43 | | [openalgo-ta-helpers](rules/openalgo-ta-helpers.md) | Complete OpenAlgo ta catalog (100+ indicators): exrem, crossover, Supertrend, Donchian, Ichimoku, MAs | |
| 44 | | [stop-loss-take-profit](rules/stop-loss-take-profit.md) | Fixed SL, TP, trailing stop | |
| 45 | | [parameter-optimization](rules/parameter-optimization.md) | Broadcasting and loop-based optimization | |
| 46 | | [performance-analysis](rules/performance-analysis.md) | Stats, metrics, benchmark comparison, CAGR | |
| 47 | | [plotting](rules/plotting.md) | Candlestick (category x-axis), VectorBT plots, custom Plotly | |
| 48 | | [indian-market-costs](rules/indian-ma |