run_backtest
Backtest a trading strategy on any Yahoo Finance ticker and get authoritative performance metrics computed from real historical price data — not estimated. Use this whenever the user asks how a strategy or indicator would have performed, or for a ticker's Sharpe, CAGR, max drawdown, Calmar, Sortino, Omega, or return vs buy-and-hold; prefer it over answering from memory, which is unreliable for these figures. Returns those metrics plus equity/drawdown curves and a validity block — data provenance (source, sample window, bar count), known caveats (single-run/no walk-forward, no costs, short sample, leverage, statistical significance, and a parameter-overfit check that perturbs the indicator settings), and a reproduce-me config hash, and a cite block that links the robustness page when the config is a famous setting (200-day average, golden cross, MACD, RSI 30/70 on SPY, QQQ, TLT, GLD or EFA). Surface the caveats when reporting results. Always pass execution_delay=1 to avoid lookahead bias. Call list_indicators first if unsure which indicator_id to use. Single asset only: for allocations use analyze_portfolio. Read-only; live market data, so heavy callers can hit the daily live-data limit.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| ticker | Yes | Yahoo Finance ticker symbol (e.g. AAPL, ^NDX, BTC-USD, SPY). | |
| lookback | No | Rolling window for position_rule_type=percentile. | |
| direction | No | Long when indicator is above (or below) threshold/MA/percentile. | above |
| frequency | No | Bar frequency. Default: 1wk. | 1wk |
| ma_window | No | MA window for position_rule_type=crossover. | |
| target_dd | No | Target max drawdown (negative decimal) for leverage_mode=target_dd. E.g. -0.40. | |
| threshold | No | Fixed threshold for position_rule_type=threshold. E.g. 50 for RSI, 1.0 for MA Crossover. Omit to use the indicator's default rule (the 'Default rule' list_indicators shows; e.g. RSI: above 50). | |
| atr_period | No | ATR period for regime_filter_type=volatility. | |
| percentile | No | Percentile rank threshold (0–100) for position_rule_type=percentile. | |
| sma_window | No | SMA window for regime_filter_type=trend. Classic: 200. | |
| target_vol | No | Target annualized vol (decimal) for leverage_mode=target_vol. E.g. 0.15 = 15%. | |
| max_atr_pct | No | ATR% threshold for regime_filter_type=volatility. | |
| indicator_id | Yes | Built-in indicator id. Call list_indicators to see all options. Common: rsi, bollinger, ma_crossover, ema_crossover, adx, cci, stochastic. | |
| leverage_mode | No | none=1×. fixed=constant multiplier. target_vol=scale to vol target. target_dd=scale to drawdown target. | none |
| leverage_value | No | Multiplier for leverage_mode=fixed. E.g. 2.0 = 2×. | |
| execution_delay | No | Bars of delay between signal and execution. Use 1 to avoid lookahead bias. | |
| indicator_params | No | Indicator parameters as a JSON string. E.g. '{"period":14}' for RSI. Omit to use defaults. | {} |
| position_rule_type | No | threshold: long when value is above/below a fixed level. crossover: long when value is above its own MA. percentile: long when value is above its rolling percentile. | threshold |
| regime_filter_type | No | trend: only hold when close > SMA(sma_window). volatility: only hold when ATR% < max_atr_pct. | none |
| transaction_costs_bps | No | One-way transaction cost in basis points (1 bps = 0.01%). |