Vectorbt-backtesting-skills optimize
Optimize strategy parameters using VectorBT. Tests parameter combinations and generates heatmaps.
install
source · Clone the upstream repo
git clone https://github.com/marketcalls/vectorbt-backtesting-skills
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/marketcalls/vectorbt-backtesting-skills "$T" && mkdir -p ~/.claude/skills && cp -r "$T/.claude/skills/optimize" ~/.claude/skills/marketcalls-vectorbt-backtesting-skills-optimize && rm -rf "$T"
manifest:
.claude/skills/optimize/SKILL.mdsource content
Create a parameter optimization script for a VectorBT strategy.
Arguments
Parse
$ARGUMENTS as: strategy symbol exchange interval
= strategy name (e.g., ema-crossover, rsi, donchian). Default: ema-crossover$0
= symbol (e.g., SBIN, RELIANCE, NIFTY). Default: SBIN$1
= exchange (e.g., NSE, NFO). Default: NSE$2
= interval (e.g., D, 1h, 5m). Default: D$3
If no arguments, ask the user which strategy to optimize.
Instructions
- Read the vectorbt-expert skill rules for reference patterns
- Create
directory if it doesn't exist (on-demand)backtesting/{strategy_name}/ - Create a
file in.py
namedbacktesting/{strategy_name}/{symbol}_{strategy}_optimize.py - The script must:
- Load
from project root using.env
and fetch data via OpenAlgofind_dotenv()client.history() - If user provides a DuckDB path, load data directly via
. See vectorbt-expertduckdb.connect(path, read_only=True)
.rules/duckdb-data.md - If
is not importable (standalone DuckDB), use inlineopenalgo.ta
fallback.exrem() - Use TA-Lib for ALL indicators (never VectorBT built-in)
- Use OpenAlgo ta for specialty indicators (Supertrend, Donchian, etc.)
- Use
to clean signals (alwaysta.exrem()
before exrem).fillna(False) - 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
for progress barstqdm - Indian delivery fees:
for delivery equityfees=0.00111, fixed_fees=20 - 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