
Optimize
Generate a VectorBT parameter-optimization script with heatmaps for a named strategy, symbol, exchange, and interval using OpenAlgo or DuckDB data.
Overview
Optimize is an agent skill for the Validate phase that creates VectorBT parameter-optimization scripts with heatmaps for a chosen strategy, symbol, exchange, and interval.
Install
npx skills add https://github.com/marketcalls/vectorbt-backtesting-skills --skill optimizeWhat is this skill?
- Scaffolds `backtesting/{strategy}/{symbol}_{strategy}_optimize.py` from CLI-style arguments
- Loads market data via OpenAlgo `client.history()` or read-only DuckDB paths
- Uses TA-Lib for indicators and OpenAlgo `ta` for specialty signals with `ta.exrem()` cleaning
- Produces parameter combination tests and heatmap-oriented optimization output
- On-demand strategy folders with vectorbt-expert rule references (duckdb-data, exrem fallback)
Adoption & trust: 1.2k installs on skills.sh; 150 GitHub stars; 3/3 security scanners passed (skills.sh audits).
What problem does it solve?
You have a trading idea but no standardized script to sweep parameters and visualize robustness across symbols and intervals.
Who is it for?
Solo quants iterating ema-crossover, RSI, Donchian, or similar rule strategies on NSE-style symbols before scaling position size.
Skip if: Live order execution, portfolio accounting, or teams that want optimization without VectorBT, OpenAlgo, or DuckDB data plumbing.
When should I use this skill?
User asks to optimize a VectorBT strategy with strategy symbol exchange interval arguments or needs a parameter optimization script with heatmaps.
What do I get? / Deliverables
You get a ready-to-run `{symbol}_{strategy}_optimize.py` under `backtesting/{strategy}/` wired to your data source and TA-Lib/OpenAlgo conventions.
- Parameter optimization Python script
- Heatmap-oriented grid test layout under `backtesting/{strategy}/`
Recommended Skills
Journey fit
Parameter sweeps and heatmaps are how solo quants validate whether a strategy edge survives before committing capital or a full automated stack. Prototype subphase matches experimental backtests and optimization scripts rather than production execution infra.
How it compares
Workflow script generator for VectorBT grids—not a hosted optimizer SaaS or a generic pandas notebook.
Common Questions / FAQ
Who is optimize for?
Independent builders running VectorBT and OpenAlgo (or DuckDB) who want agent-generated optimization scripts instead of copying paste from old notebooks.
When should I use optimize?
During Validate when you need heatmaps and parameter combinations for a named strategy and symbol before you treat results as production-ready.
Is optimize safe to install?
Check the Security Audits panel on this page; the skill uses Bash and may read `.env` and market credentials—rotate keys and run in an isolated project directory.
SKILL.md
READMESKILL.md - Optimize
Create a parameter optimization script for a VectorBT strategy. ## Arguments Parse `$ARGUMENTS` as: strategy symbol exchange interval - `$0` = strategy name (e.g., ema-crossover, rsi, donchian). Default: ema-crossover - `$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 to optimize. ## 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}_optimize.py` 4. The script must: - Load `.env` from project root using `find_dotenv()` and fetch data via OpenAlgo `client.history()` - If user provides a DuckDB path, load data directly via `duckdb.connect(path, read_only=True)`. 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** (never VectorBT built-in) - **Use OpenAlgo ta** for specialty indicators (Supertrend, Donchian, etc.) - Use `ta.exrem()` to clean signals (always `.fillna(False)` before exrem) - Define sensible parameter ranges for the chosen strategy - Use loop-based optimization to collect multiple metrics per combo - Track: total_return, sharpe_ratio, max_drawdown, trade_count for each combination - Use `tqdm` for progress bars - **Indian delivery fees**: `fees=0.00111, fixed_fees=20` for delivery equity - Find best parameters by total return AND by Sharpe ratio - Print top 10 results for both criteria - Generate Plotly heatmap of total return across parameter grid (`template="plotly_dark"`) - Generate Plotly heatmap of Sharpe ratio across parameter grid - **Fetch NIFTY benchmark** and compare best parameters vs benchmark - **Print Strategy vs Benchmark comparison table** - **Explain results** in plain language for normal traders - Save results to CSV 4. Never use icons/emojis in code or logger output 5. For futures symbols, use lot-size-aware sizing: - NIFTY: `min_size=65, size_granularity=65` - BANKNIFTY: `min_size=30, size_granularity=30` ## Default Parameter Ranges | Strategy | Parameter 1 | Parameter 2 | |----------|------------|-------------| | ema-crossover | fast EMA: 5-50 | slow EMA: 10-60 | | rsi | window: 5-30 | oversold: 20-40 | | donchian | period: 5-50 | - | | supertrend | period: 5-30 | multiplier: 1.0-5.0 | ## Example Usage `/optimize ema-crossover RELIANCE NSE D` `/optimize rsi SBIN`