{
  "markdown": "# VectorBT Backtesting Skills for Agentic Coding Tools\n\nA comprehensive collection of backtesting skills for trading strategies using VectorBT. Works with **40+ AI coding agents** via [skills.sh](https://github.com/vercel-labs/skills) — including Claude Code, Cursor, Codex, OpenCode, Cline, Windsurf, GitHub Copilot, Gemini CLI, Roo Code, and more.\n\nSupports **Indian markets**, **US markets**, and **Crypto markets** with realistic transaction cost modeling, OpenAlgo indicators (100+, TA-Lib available on request), market-specific benchmarking, OpenStatz tearsheets, and robustness testing. Broker-neutral by design — fee models use industry-standard references that can be customized for any broker.\n\n## Quick Install\n\nInstall the skills into your project using [npx skills](https://github.com/vercel-labs/skills). The CLI auto-detects your AI coding agent and installs skills to the correct directory.\n\n```bash\n# GitHub shorthand\nnpx skills add marketcalls/vectorbt-backtesting-skills\n\n# Full GitHub URL\nnpx skills add https://github.com/marketcalls/vectorbt-backtesting-skills\n```\n\nInstall a specific skill only:\n\n```bash\nnpx skills add marketcalls/vectorbt-backtesting-skills -s backtest\nnpx skills add marketcalls/vectorbt-backtesting-skills -s optimize\nnpx skills add marketcalls/vectorbt-backtesting-skills -s vectorbt-expert\nnpx skills add marketcalls/vectorbt-backtesting-skills -s setup\n```\n\nList available skills before installing:\n\n```bash\nnpx skills add marketcalls/vectorbt-backtesting-skills -l\n```\n\nInstall globally (available across all projects):\n\n```bash\nnpx skills add marketcalls/vectorbt-backtesting-skills -g\n```\n\n### Supported AI Coding Agents\n\nSkills are installed via [skills.sh](https://github.com/vercel-labs/skills) which supports 40+ agents. Each agent reads skills from its own directory:\n\n| Agent | Skills Directory |\n|-------|-----------------|\n| Claude Code | `.claude/skills/` |\n| Cursor | `.agents/skills/` |\n| Codex | `.agents/skills/` |\n| OpenCode | `.agents/skills/` |\n| Cline | `.agents/skills/` |\n| Windsurf | `.agents/skills/` |\n| GitHub Copilot | `.agents/skills/` |\n| Gemini CLI | `.agents/skills/` |\n| Roo Code | `.agents/skills/` |\n| + 30 more | Auto-detected by `npx skills` |\n\nThe `npx skills add` command detects which agents you have installed and places the skill files in the correct paths automatically.\n\n## Supported Markets\n\n| Market | Data Source | Fee Reference | Default Benchmark |\n|--------|------------|---------------|-------------------|\n| **India** | OpenAlgo (NSE, BSE, NFO, MCX) | Delivery, Intraday, F&O (4-segment) | NIFTY 50 |\n| **US** | yfinance (NYSE, NASDAQ) | Stocks, Options, Futures (per-share + per-contract) | S&P 500 |\n| **Crypto** | yfinance / CCXT | Spot, Perpetual Futures (maker/taker) | Bitcoin |\n| **Custom** | Any provider via extensible pattern | User-defined | User-defined |\n\n> **Broker-neutral**: Fee models use realistic industry-standard defaults and can be adjusted for any broker by changing the `fees` and `fixed_fees` constants.\n\n## Capabilities\n\n### Skills (User-Invocable Commands)\n\n| Command | What It Does |\n|---------|-------------|\n| `/setup` | Detects OS, creates venv, installs OpenAlgo + all packages (TA-Lib optional), creates `backtesting/` folders, configures `.env` with API keys |\n| `/backtest` | Generates a complete backtest script with signals, market-specific fees, benchmark comparison, plain-language report, OpenStatz tearsheet |\n| `/optimize` | Parameter grid search with OpenAlgo ta indicators, tqdm progress bars, Plotly heatmaps, best params vs benchmark |\n| `/quick-stats` | Inline code block (no file) — fetch data, run EMA crossover, print compact stats + benchmark alpha |\n| `/strategy-compare` | Side-by-side comparison of multiple strategies on same symbol, overlaid equity curves |\n\n### Pre-Built Strategy Templates (12)\n\n| Strategy | Type | Description |\n|----------|------|-------------|\n| EMA Crossover | Trend | EMA 10/20 crossover |\n| RSI | Mean-reversion | RSI(14) oversold/overbought |\n| Donchian Channel | Breakout | Channel breakout with shifted levels (no lookahead) |\n| Supertrend | Trend | Supertrend with intraday session windows (9:30-15:00, exit 15:15) |\n| MACD | Trend + Breakout | MACD zero-line regime + signal-candle breakout |\n| SDA2 | Trend | WMA + STDDEV + ATR band system |\n| Double Momentum | Momentum | MOM + MOM-of-MOM with next-bar fill |\n| Dual Momentum | Rotation | Quarterly ETF rotation (NIFTYBEES vs GOLDBEES) |\n| Buy & Hold | Passive | Static multi-asset allocation with FD benchmark |\n| RSI Accumulation | Accumulation | Weekly RSI slab-wise buying (5%/10%/20% by RSI level) |\n| Walk-Forward | Validation | Rolling train/test optimization with WFE scoring |\n| Realistic Costs | Analysis | Same strategy across 5 fee tiers (zero to full delivery) |\n\n### Knowledge Base (20 Rule Files)\n\n| Category | What's Covered |\n|----------|---------------|\n| **Data** | OpenAlgo (India), yfinance (US/Global), CCXT (Crypto), custom providers, `.env` + `python-dotenv`, CSV loading, resampling |\n| **Indicators** | OpenAlgo ta by default - 100+ indicators (EMA, SMA, RSI, MACD, BBands, ATR, ADX, STDDEV, MOM, Supertrend, Donchian, Ichimoku, HMA, KAMA, ALMA, ZLEMA, VWMA, oscillators, statistical, hybrid). TA-Lib only if explicitly requested |\n| **Signals** | `ta.exrem()` signal cleaning, `ta.crossover()`, `ta.crossunder()`, `ta.flip()` regime detection |\n| **Simulation** | `from_signals`, `from_orders`, `from_holding`, long/short/both directions |\n| **Sizing** | Percent, Value, TargetPercent, whole shares (`min_size=1`), futures lot sizes, fractional crypto |\n| **Costs** | **India**: 4-segment model (Delivery 0.111%, Intraday 0.0225%, Futures 0.018%, Options 0.098%). **US**: Per-share + per-contract model (Stocks ~0.01%, Options ~0.2%, Futures ~0.001%). **Crypto**: Maker/taker model (Spot 0.1%, Futures 0.02%/0.05%, funding rates). All customizable. |\n| **Futures** | SEBI revised lot sizes (Dec 2025): NIFTY=65, BANKNIFTY=30, FINNIFTY=60. US: E-mini/Micro contract specs |\n| **Risk** | Stop loss, take profit, trailing stop (`sl_trail`) |\n| **Optimization** | Loop-based (OpenAlgo ta / TA-Lib compliant) + broadcasting (vbt.MA exception for parameter sweeps) |\n| **Benchmarking** | India: NIFTY 50 via OpenAlgo. US: S&P 500 (`^GSPC`). Crypto: Bitcoin (`BTC-USD`). Strategy vs Benchmark table always produced |\n| **Reporting** | Plain-language backtest explanation for normal traders. OpenStatz HTML tearsheets with 30+ metrics, Monte Carlo simulations |\n| **Plotting** | Plotly dark theme, candlestick with `xaxis type=\"category\"` (no weekend gaps), VectorBT 7-panel plot pack |\n| **Validation** | Walk-forward analysis (WFE ratio), robustness testing (Monte Carlo trade shuffle, noise injection, parameter sensitivity, entry/exit delay, cross-symbol validation) |\n| **Safety** | 10 common pitfalls with prevention, checklist before going live |\n\n## Prerequisites\n\n### 1. AI Coding Agent\n\nInstall any supported AI coding agent. For example:\n\n- [Claude Code](https://docs.anthropic.com/en/docs/claude-code) — `npm install -g @anthropic-ai/claude-code`\n- [Cursor](https://cursor.com) — Desktop IDE with built-in AI\n- [Codex](https://github.com/openai/codex) — `npm install -g @openai/codex`\n- [OpenCode](https://github.com/opencode-ai/opencode) — `go install github.com/opencode-ai/opencode@latest`\n- [Cline](https://github.com/cline/cline) — VS Code extension\n- [Windsurf](https://windsurf.com) — Desktop IDE with AI\n- Or any of the [40+ supported agents](https://github.com/vercel-labs/skills)\n\nThen install the skills:\n\n```bash\nnpx skills add marketcalls/vectorbt-backtesting-skills\n```\n\n### 2. Data Source Setup\n\n**Indian Markets** — requires [OpenAlgo](https://github.com/marketcalls/openalgo):\n\n```bash\ngit clone https://github.com/marketcalls/openalgo.git\ncd openalgo\npip install -r requirements.txt\npython app.py\n```\n\nOpenAlgo runs locally at `http://127.0.0.1:5000`. You need a broker account connected via OpenAlgo and an API key from the dashboard. See [OpenAlgo documentation](https://docs.openalgo.in/).\n\n**US Markets** — no setup needed. Uses yfinance (public Yahoo Finance data).\n\n**Crypto Markets** — no setup needed for public data (yfinance or CCXT). Exchange API keys are optional (only for private endpoints).\n\n### 3. Python Environment Setup\n\nUse the `/setup` skill for automated setup, or manually:\n\n```bash\npython -m venv venv\nsource venv/bin/activate   # Linux/Mac\n# venv\\Scripts\\activate    # Windows\n\n# Install Python packages (OpenAlgo ta is the default indicator library - no C library needed)\npip install openalgo vectorbt plotly anywidget nbformat pandas numpy yfinance python-dotenv tqdm scipy numba ipywidgets openstatz ccxt\n\n# Optional: only if you want to be able to request TA-Lib explicitly in a backtest\nbrew install ta-lib         # macOS\n# sudo apt install libta-lib-dev  # Linux\npip install ta-lib\n```\n\n### 4. Configure API Keys\n\n```bash\ncp .env.sample .env\n# Edit .env with your API keys\n```\n\n## Usage Examples\n\n### `/setup` - Environment Setup\n\nDetects OS, creates venv, installs dependencies, creates folder structure, and collects API keys into `.env`.\n\n```\n/setup\n/setup python3.12\n```\n\n### `/backtest` - Quick Backtest\n\nCreate a complete backtest script with market-specific fees, benchmark comparison, plain-language report, and OpenStatz tearsheet.\n\n```\n# Indian Markets\n/backtest ema-crossover SBIN NSE D\n/backtest rsi RELIANCE NSE D\n/backtest supertrend NIFTY NFO 5m\n\n# US Markets\n/backtest ema-crossover AAPL\n/backtest rsi MSFT\n\n# Crypto Markets\n/backtest ema-crossover BTC-USD\n```\n\n### `/optimize` - Parameter Optimization\n\nOptimize strategy parameters, generate Plotly heatmaps, and compare best parameters vs benchmark.\n\n```\n/optimize ema-crossover SBIN NSE D\n/optimize rsi AAPL\n```\n\n### `/quick-stats` - Inline Stats\n\nPrint key backtest stats with benchmark comparison without creating a file.\n\n```\n/quick-stats RELIANCE\n/quick-stats AAPL\n/quick-stats BTC-USD\n```\n\n### `/strategy-compare` - Compare Strategies\n\nCompare multiple strategies side-by-side with benchmark.\n\n```\n/strategy-compare RELIANCE ema-crossover rsi donchian\n/strategy-compare AAPL ema-crossover rsi macd\n```\n\n## Key Features\n\n### Multi-Market Transaction Costs\n\nRealistic fee models for each market, auto-selected based on the asset. All fee constants are configurable — adjust for your broker by changing the `fees` and `fixed_fees` values.\n\n#### Indian Market Fees\n\n| Segment | `fees` | `fixed_fees` |\n|---------|--------|-------------|\n| Delivery Equity | 0.00111 (0.111%) | Rs 20/order |\n| Intraday Equity | 0.000225 (0.0225%) | Rs 20/order |\n| F&O Futures | 0.00018 (0.018%) | Rs 20/order |\n| F&O Options | 0.00098 (0.098%) | Rs 20/order |\n\n#### US Market Fees\n\n| Segment | `fees` | `fixed_fees` |\n|---------|--------|-------------|\n| Stocks (Pro/Fixed) | 0.0001 (0.01%) | $1.00/order |\n| Stocks (Commission-Free) | 0.00001 (~0.001%) | $0 |\n| Options | 0.002 (0.2%) | $0.65/contract |\n| E-mini Futures (ES, NQ) | 0.000009 (~0.001%) | $2.25/contract |\n| Micro Futures (MES, MNQ) | 0.00002 (~0.002%) | $0.55/contract |\n\n#### Crypto Market Fees\n\n| Segment | `fees` | `fixed_fees` |\n|---------|--------|-------------|\n| Spot (Base) | 0.001 (0.1%) | $0 |\n| Spot (Discounted) | 0.00075 (0.075%) | $0 |\n| USDT-M Futures (Taker) | 0.0005 (0.05%) | $0 |\n| USDT-M Futures (Maker) | 0.0002 (0.02%) | $0 |\n| COIN-M Futures (Taker) | 0.0005 (0.05%) | $0 |\n\n> **Using a different broker?** Simply override the fee constants in your backtest script. The rule files include detailed breakdowns (STT, exchange fees, regulatory fees, clearing fees) so you can recalculate for any broker.\n\n### OpenAlgo ta Indicators (Default)\n\nAll strategies use `openalgo.ta` for technical indicators by default - 100+ indicators across trend, momentum, volatility, volume, oscillators, statistical, and hybrid categories. VectorBT built-in indicators are never used.\n\n```python\nfrom openalgo import ta\nema_fast = ta.ema(close, 10)\nst_line, st_direction = ta.supertrend(high, low, close, period=10, multiplier=3.0)\nentries = ta.exrem(buy_raw.fillna(False), sell_raw.fillna(False))\n```\n\nSpecialty indicators with no TA-Lib equivalent (Supertrend, Donchian, Ichimoku, HMA, KAMA, ALMA, ZLEMA, VWMA) plus signal utilities (`exrem`, `crossover`, `crossunder`, `flip`) always come from `openalgo.ta`.\n\n### TA-Lib (Opt-In Only)\n\nOnly used when the user explicitly asks for \"talib\"/\"TA-Lib\" in their request:\n\n```python\nimport talib as tl\nema_fast = pd.Series(tl.EMA(close.values, timeperiod=10), index=close.index)\n```\n\n### Market-Specific Benchmarks\n\n| Market | Default Benchmark | Source |\n|--------|-------------------|--------|\n| India | NIFTY 50 | OpenAlgo (`NSE_INDEX`) |\n| US | S&P 500 | yfinance (`^GSPC` or `SPY`) |\n| Crypto | Bitcoin | yfinance (`BTC-USD`) |\n\nEvery backtest produces a Strategy vs Benchmark comparison table.\n\n### OpenStatz Tearsheets\n\nA modern interactive tearsheet with 30+ metrics, drawdown analysis, rolling statistics, monthly heatmaps, and Monte Carlo simulations. `ostz.dashboard(...)` renders the same interactive dashboard as `openstatz serve` into a single self-contained offline HTML file - no server, no `[app]` extra, no network. OpenStatz replaces QuantStats project-wide and keeps a numerical-parity contract on its metrics.\n\n```python\nimport openstatz as ostz  # alias as ostz, not os - avoids shadowing the stdlib os module\n\n# dashboard() needs the benchmark as a returns Series (not a ticker string)\nbenchmark = ostz.providers.download_returns(\"^NSEI\").reindex(pf.returns().index).fillna(0)\nostz.dashboard(pf.returns(), benchmark=benchmark, output=\"tearsheet.html\")\n```\n\n### Plain-Language Report Explanation\n\nEvery backtest explains results so normal traders can understand:\n\n```\n* Total Return: Your strategy made 45.23% while NIFTY 50 made 32.10%\n  -> BEAT the market by 13.13%\n* Max Drawdown: -12.34% - the biggest drop from peak\n  -> On Rs 10,00,000 capital, worst temporary loss = Rs 1,23,400\n* Sharpe Ratio: 1.45 (return per unit of risk, >1 decent, >2 excellent)\n```\n\n### Extensible Data Providers\n\nBuilt-in support for OpenAlgo, yfinance, and CCXT. Add custom providers (Alpaca, Twelve Data, etc.) following the pattern in `data-fetching.md`. All API keys stored in `.env` via `python-dotenv`.\n\n### SEBI Revised Lot Sizes (Effective 31 Dec 2025)\n\n| Index | Lot Size | Exchange |\n|-------|----------|----------|\n| Nifty 50 | 65 | NFO |\n| Nifty Bank | 30 | NFO |\n| Nifty Financial Services | 60 | NFO |\n| Nifty Midcap Select | 120 | NFO |\n| Nifty Next 50 | 25 | NFO |\n| BSE Sensex | 20 | BFO |\n| BSE Bankex | 30 | BFO |\n| BSE Sensex 50 | 70 | BFO |\n\n### Backtesting Folder Structure\n\nStrategy name = folder name. Symbol name = file prefix. Each strategy folder is self-contained.\n\n```\nbacktesting/\n├── ema_crossover/\n│   ├── .env\n│   ├── SBIN_ema_crossover_backtest.py\n│   ├── SBIN_ema_crossover_trades.csv\n│   ├── SBIN_tearsheet.html\n│   ├── AAPL_ema_crossover_backtest.py\n│   └── AAPL_ema_crossover_trades.csv\n├── rsi/\n│   ├── .env\n│   ├── INFY_rsi_backtest.py\n│   └── ...\n├── supertrend/\n│   └── ...\n└── custom/\n    └── ...\n```\n\n## Project Structure\n\n```\n.\n├── .claude/\n│   └── skills/\n│       ├── setup/                    # /setup - Environment setup\n│       │   └── SKILL.md\n│       ├── backtest/                 # /backtest - Quick backtest\n│       │   └── SKILL.md\n│       ├── optimize/                 # /optimize - Parameter optimization\n│       │   └── SKILL.md\n│       ├── quick-stats/              # /quick-stats - Inline stats\n│       │   └── SKILL.md\n│       ├── strategy-compare/         # /strategy-compare - Compare strategies\n│       │   └── SKILL.md\n│       └── vectorbt-expert/          # Knowledge base (auto-loaded)\n│           ├── SKILL.md              # Main skill (modular reference hub)\n│           └── rules/                # 20 modular rule files\n│               ├── data-fetching.md\n│               ├── simulation-modes.md\n│               ├── position-sizing.md\n│               ├── indicators-signals.md\n│               ├── openalgo-ta-helpers.md\n│               ├── stop-loss-take-profit.md\n│               ├── parameter-optimization.md\n│               ├── performance-analysis.md\n│               ├── plotting.md\n│               ├── indian-market-costs.md\n│               ├── us-market-costs.md\n│               ├── crypto-market-costs.md\n│               ├── futures-backtesting.md\n│               ├── long-short-trading.md\n│               ├── csv-data-resampling.md\n│               ├── walk-forward.md\n│               ├── robustness-testing.md\n│               ├── pitfalls.md\n│               ├── strategy-catalog.md\n│               ├── openstatz-tearsheet.md\n│               └── assets/           # Production-ready templates\n│                   ├── ema_crossover/backtest.py\n│                   ├── rsi/backtest.py\n│                   ├── donchian/backtest.py\n│                   ├── supertrend/backtest.py\n│                   ├── macd/backtest.py\n│                   ├── sda2/backtest.py\n│                   ├── momentum/backtest.py\n│                   ├── dual_momentum/backtest.py\n│                   ├── buy_hold/backtest.py\n│                   ├── rsi_accumulation/backtest.py\n│                   ├── walk_forward/template.py\n│                   └── realistic_costs/template.py\n├── .env.sample                      # Environment template (copy to .env)\n├── backtesting/                      # Generated backtest scripts (per strategy)\n│   ├── ema_crossover/\n│   ├── rsi/\n│   ├── donchian/\n│   ├── supertrend/\n│   ├── macd/\n│   ├── sda2/\n│   ├── momentum/\n│   ├── dual_momentum/\n│   ├── buy_hold/\n│   ├── rsi_accumulation/\n│   ├── walk_forward/\n│   └── custom/\n└── README.md\n```\n\n## Rule Files Reference\n\n| Rule File | Description |\n|-----------|-------------|\n| `data-fetching.md` | OpenAlgo (India), yfinance (US), CCXT (Crypto), custom providers, `.env` setup |\n| `simulation-modes.md` | from_signals, from_orders, from_holding, direction types |\n| `position-sizing.md` | Amount/Value/Percent/TargetPercent sizing, whole shares |\n| `indicators-signals.md` | OpenAlgo ta indicator reference (default), TA-Lib opt-in, signal generation |\n| `openalgo-ta-helpers.md` | Complete OpenAlgo ta catalog (100+ indicators): exrem, crossover, Supertrend, Donchian, Ichimoku, MAs |\n| `stop-loss-take-profit.md` | Fixed SL, TP, trailing stop configurations |\n| `parameter-optimization.md` | Broadcasting and loop-based optimization, heatmaps |\n| `performance-analysis.md` | Stats, metrics, benchmark comparison, CAGR calculation |\n| `plotting.md` | Candlestick (category x-axis), VectorBT plots, custom Plotly |\n| `indian-market-costs.md` | Indian market fee model — delivery, intraday, F&O (4-segment) |\n| `us-market-costs.md` | US market fee model — stocks, options, futures (per-share + per-contract) |\n| `crypto-market-costs.md` | Crypto fee model — spot, perpetual futures, funding rates (maker/taker) |\n| `futures-backtesting.md` | SEBI revised lot sizes (Dec 2025), US contract specs, value sizing |\n| `long-short-trading.md` | Simultaneous long/short, direction comparison |\n| `csv-data-resampling.md` | Loading CSV data, resampling with Indian market alignment |\n| `walk-forward.md` | Walk-forward analysis, WFE ratio, rolling optimization |\n| `robustness-testing.md` | Monte Carlo, noise test, parameter sensitivity, delay test |\n| `pitfalls.md` | 10 common mistakes and checklist before going live |\n| `strategy-catalog.md` | All strategy types with code snippets and asset references |\n| `openstatz-tearsheet.md` | OpenStatz interactive offline dashboard, 30+ metrics, Monte Carlo (replaces QuantStats) |\n\n## Data Sources\n\n| Source | Use Case | Tickers/Codes | API Key Required |\n|--------|----------|---------------|------------------|\n| OpenAlgo | Indian markets (primary) | NSE, BSE, NFO, BFO, CDS, MCX, NSE_INDEX, BSE_INDEX | Yes (`OPENALGO_API_KEY`) |\n| yfinance | US markets, global, crypto | `AAPL`, `SPY`, `^GSPC`, `^NSEI`, `BTC-USD`, `ETH-USD` | No |\n| CCXT | Crypto exchanges | `BTC/USDT`, `ETH/USDT` (higher resolution data) | Optional |\n| Custom | Any provider | User-defined | User-defined |\n\n## Configuration\n\nCopy the `.env.sample` and fill in your API keys:\n\n```bash\ncp .env.sample .env\n```\n\nThe `.env` file supports:\n\n```\n# Indian Markets (OpenAlgo)\nOPENALGO_API_KEY=your_openalgo_api_key_here\nOPENALGO_HOST=http://127.0.0.1:5000\n\n# Crypto Markets (CCXT) — Optional\nCRYPTO_API_KEY=\nCRYPTO_SECRET_KEY=\n\n# Custom Data Providers - add your own keys\n# ALPACA_API_KEY=\n# TWELVEDATA_API_KEY=\n```\n\nUS market data via yfinance does not require an API key.\n\n## License\n\nMIT\n",
  "bytes": 20620,
  "sha": "528dcc3c00f58767a8436e12cdff0fba40b5802e78c4fbb564831b2acc6a4913",
  "repo_slug": "marketcalls/vectorbt-backtesting-skills",
  "fonte": "repo",
  "truncated": false,
  "api": "https://agentalog.com/api/listings/skl_marketcalls_vectorbt_backtesting_skills__9024bbd2/readme"
}