optimize
marketcalls/vectorbt-backtesting-skills
Optimize trading 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 against historical data, generates performance heatmaps, and compares results against NIFTY benchmark—useful for traders refining strategy rules before live deployment.
- Tests parameter combinations and tracks total return, Sharpe ratio, max drawdown, and trade count for each
- Generates Plotly heatmaps visualizing performance across parameter grids
- Compares optimized strategy results against NIFTY benchmark with side-by-side metrics
- Loads data from OpenAlgo API or DuckDB, with OpenAlgo ta indicators by default
- Applies Indian delivery fees (0.00111 + ₹20 fixed) and futures lot-size awareness (NIFTY/BANKNIFTY)
- Saves optimization results to CSV and prints top 10 parameter sets by return and Sharpe ratio
How to install optimize
npx skills add https://github.com/marketcalls/vectorbt-backtesting-skills --skill optimize- VectorBT and OpenAlgo installed in your Python environment
- Access to OpenAlgo API credentials in `.env` file, or a DuckDB file with historical data
- Historical price data available for the chosen symbol and interval
How to use optimize
- 1.Run the skill with strategy name, symbol, exchange, and interval: `/optimize ema-crossover RELIANCE NSE D`
- 2.Review the generated Python script in `backtesting/{strategy_name}/{symbol}_{strategy}_optimize.py`
- 3.Execute the script to test parameter combinations and generate heatmaps
- 4.Examine the CSV results file and Plotly heatmaps to identify best parameter sets
- 5.Compare your optimized strategy performance against NIFTY benchmark in the printed table
- 6.Use top-performing parameters for paper trading or live deployment
Use cases
- Find optimal EMA crossover periods (fast/slow) for a stock before trading live
- Test RSI window and oversold threshold combinations to maximize Sharpe ratio
- Optimize Donchian channel period for mean-reversion strategies
- Compare Supertrend multiplier and period settings across different symbols
- Validate strategy robustness by checking performance consistency across parameter ranges
- Quantitative traders building systematic strategies
- Retail traders backtesting rule-based entry/exit logic
- Strategy developers optimizing parameters before paper trading
- Traders working with Indian equities (NSE) and derivatives (NFO)
optimize FAQ
By default it fetches data via OpenAlgo API using credentials from `.env`. You can also provide a DuckDB file path to load data directly from a local database.
OpenAlgo ta indicators are used by default for all strategies (EMA, RSI, Donchian, Supertrend). TA-Lib is only used if you explicitly request it.
Indian delivery equity fees are applied as 0.00111 (0.111%) plus ₹20 fixed per trade. Futures use lot-size-aware sizing (NIFTY: 65 shares, BANKNIFTY: 30 shares).
The script tracks total return, Sharpe ratio, max drawdown, and trade count for each parameter combination, then ranks results by both total return and Sharpe ratio separately.
Yes, you can run the skill multiple times with different strategy names (ema-crossover, rsi, donchian, supertrend) to compare optimization results across strategies.
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 OpenAlgo ta for ALL indicators by default (never VectorBT built-in). Only switch to TA-Lib if the user explicitly says "talib"/"TA-Lib"
- Always use OpenAlgo ta for specialty indicators (Supertrend, Donchian, etc.) - no TA-Lib equivalent exists
- 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 backtest a symbol with EMA crossover strategy and print key stats inline—no file creation.

setup
Set up a complete Python backtesting environment with VectorBT, OpenAlgo, and market data sources.

strategy-compare
Compare multiple trading strategies side-by-side with performance metrics and equity curves.

vectorbt-expert
VectorBT backtesting expert for strategy testing, signal generation, and portfolio optimization.

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

asr
Transcribe audio files to text offline using local speech recognition models.