optimize
marketcalls/vectorbt-backtesting-skills
Optimize strategy parameters using VectorBT with heatmap visualization and benchmark comparison.
What is optimize?
This skill creates parameter optimization scripts for VectorBT trading strategies. It tests multiple parameter combinations, tracks performance metrics (return, Sharpe ratio, drawdown, trade count), and generates Plotly heatmaps to visualize results. Use it to find the best parameter settings for your strategy on specific symbols and timeframes.
- Tests parameter combinations via loop-based optimization with progress tracking
- Generates Plotly heatmaps of total return and Sharpe ratio across parameter grids
- Compares optimized strategy performance against NIFTY benchmark with side-by-side table
- Loads data from OpenAlgo API or DuckDB with automatic fallback for standalone environments
- Uses TA-Lib and OpenAlgo ta for indicators (Supertrend, Donchian, RSI, EMA, etc.)
- Applies Indian delivery fees (0.00111 + 20 fixed) and futures lot-size awareness (NIFTY/BANKNIFTY)
How to install optimize
npx skills add https://github.com/marketcalls/vectorbt-backtesting-skills --skill optimize- VectorBT library installed
- TA-Lib installed for indicator calculations
- OpenAlgo client configured (or DuckDB path for standalone mode)
- .env file in project root with OpenAlgo credentials (if using API)
- vectorbt-expert skill rules available for reference patterns
How to use optimize
- 1.Run the skill with strategy name, symbol, exchange, and interval (e.g., `/optimize ema-crossover RELIANCE NSE D`)
- 2.If no arguments provided, select a strategy when prompted
- 3.Review the generated Python script in `backtesting/{strategy_name}/{symbol}_{strategy}_optimize.py`
- 4.Execute the script to test parameter combinations and generate results
- 5.Check the printed top 10 results sorted by total return and Sharpe ratio
- 6.View Plotly heatmaps showing parameter performance across the grid
- 7.Compare your optimized strategy metrics against NIFTY benchmark in the output table
- 8.Export results to CSV for further analysis or record-keeping
Use cases
- Find optimal EMA crossover parameters (fast/slow periods) for a stock on daily timeframe
- Optimize RSI window and oversold threshold for intraday trading on multiple symbols
- Determine best Donchian channel period for breakout strategies on futures
- Compare Supertrend multiplier and period settings across different assets
- Backtest parameter ranges and export top 10 results by return and Sharpe ratio to CSV
- Quantitative traders optimizing strategy parameters
- Retail traders backtesting Indian equity and futures strategies
- Developers building automated trading systems with VectorBT
- Analysts comparing strategy performance against NIFTY benchmark
optimize FAQ
It supports OpenAlgo API (via client.history()) and DuckDB files. If neither is available, it falls back to inline ta.exrem() for signal cleaning.
Use TA-Lib for standard indicators (EMA, RSI, etc.) and OpenAlgo ta for specialty indicators like Supertrend and Donchian. Never use VectorBT built-in indicators.
Delivery equity uses fees=0.00111 (0.111%) plus fixed_fees=20. Futures use lot-size-aware sizing: NIFTY min_size=65, BANKNIFTY min_size=30.
Total return, Sharpe ratio, maximum drawdown, and trade count. Results are sorted by both total return and Sharpe ratio separately.
Yes. Specify any interval (5m, 1h, D, etc.) as the fourth argument. The skill handles both intraday and daily optimization.
Full instructions (SKILL.md)
Source of truth, from marketcalls/vectorbt-backtesting-skills.
name: optimize description: Optimize strategy parameters using VectorBT. Tests parameter combinations and generates heatmaps. argument-hint: "[strategy] [symbol] [exchange] [interval]" allowed-tools: Read, Write, Edit, Bash, Glob, Grep
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
- Read the vectorbt-expert skill rules for reference patterns
- Create
backtesting/{strategy_name}/directory if it doesn't exist (on-demand) - Create a
.pyfile inbacktesting/{strategy_name}/named{symbol}_{strategy}_optimize.py - The script must:
- Load
.envfrom project root usingfind_dotenv()and fetch data via OpenAlgoclient.history() - If user provides a DuckDB path, load data directly via
duckdb.connect(path, read_only=True). See vectorbt-expertrules/duckdb-data.md. - If
openalgo.tais not importable (standalone DuckDB), use inlineexrem()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
tqdmfor progress bars - Indian delivery fees:
fees=0.00111, fixed_fees=20for 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
- Load
- Never use icons/emojis in code or logger output
- For futures symbols, use lot-size-aware sizing:
- NIFTY:
min_size=65, size_granularity=65 - BANKNIFTY:
min_size=30, size_granularity=30
- NIFTY:
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
Related skills
More from marketcalls/vectorbt-backtesting-skills and the wider catalog.

quick-stats
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.

setup
Set up the Python backtesting environment. Detects OS, creates virtual environment, installs dependencies (openalgo, ta-lib, vectorbt, plotly), and creates the backtesting folder structure.

strategy-compare
Compare multiple trading strategies on the same symbol with side-by-side performance metrics and equity curve visualization.

vectorbt-expert
VectorBT backtesting expert for strategy simulation, signal generation, and portfolio analysis.

claude-brainrot
Always-on meme dropper that fires image+sound combos and sound-only hits automatically on every user message.

asr
|