backtest
Run historical backtests on trading strategies using VectorBT. Fetches OHLCV from exchange (ccxt), computes indicators (RSI/MACD/BB/EMA/ATR), evaluates entry/exit signals, simulates portfolio, returns structured metrics (return%, Sharpe, max drawdown, win rate, profit factor). Optionally generates equity curve chart. Supports pre-fetched OHLCV via ohlcv_json for coingecko/yfinance data.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| action | Yes | run=execute backtest, chart=regenerate chart from previous metrics | |
| period | No | Lookback period, e.g. '6m', '1y', '30d'. Default: 6m | |
| exchange | No | Exchange for OHLCV data. Default: binance | |
| ohlcv_json | No | Pre-fetched OHLCV as JSON string (from coingecko/yfinance tools). Format: {"SYMBOL": [{"timestamp":ms,"open":...,"close":...}, ...]} | |
| metrics_json | No | For action=chart: JSON metrics from a previous run. | |
| generate_chart | No | Generate equity curve chart (requires playwright). Default: false | |
| strategy_config | No | JSON string with strategy config. Keys: name, symbols (list), timeframe, indicators (list of {name, params, key}), entry_conditions (list of {indicator, field, operator, value}), exit_conditions, direction (long/short/both), stop_loss_pct, take_profit_pct, trade_size_pct, fees. | |
| starting_balance | No | Initial cash. Default: 100000 |