run_backtest
Backtest a portfolio rotation strategy on historical price data with momentum or score ranking, and obtain return, Sharpe, drawdown, and equity curve.
Instructions
Backtest a rotation strategy on historical price data.
Uses price momentum ranking by default. Simulates monthly rebalancing with trailing stops and transaction costs.
Args: prices_json: JSON of price data from fetch_prices (the "prices" array). strategy_json: Optional JSON strategy config, e.g. '{"rebalance": "monthly", "max_positions": 5, "sizing": "equal_weight", "entry": {"min_score": 60}, "exit": {"trailing_stop": 0.15}}'. If empty, uses sensible defaults. benchmark: Benchmark ticker (default "SPY"). cost_bps: Transaction cost in basis points (default 10). scores_json: Optional JSON of score results from score_tickers tool. When provided with ranking_mode="score", uses composite scores for initial allocation instead of price momentum. ranking_mode: "momentum" (default, rank by 3M price return) or "score" (rank by composite scores for initial allocation). When "score", the entry.min_score threshold from strategy is honored. Note: subsequent rebalances use momentum since scores can't be recomputed mid-backtest without financials at each date.
Returns: JSON with metrics (total_return, CAGR, Sharpe, Sortino, max_drawdown, win_rate), equity_curve, trade_log, and monthly_returns.
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"prices_json": "<prices_json>"
},
"name": "run_backtest"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| prices_json | Yes | ||
| strategy_json | No | ||
| benchmark | No | SPY | |
| cost_bps | No | ||
| scores_json | No | ||
| ranking_mode | No | momentum |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |