backtest_strategy
Run historical backtests on stock screening strategies. Automates rebalancing, sizing, and risk management to return equity curve, trade log, and performance metrics.
Instructions
Run a historical backtest on a stock screening strategy. Uses a rebalance-loop engine that re-runs the screening pipeline on each rebalance date, sizes positions, enforces risk limits, and tracks daily P&L.
Returns equity curve, trade log, and performance metrics including CAGR, Sharpe ratio, maximum drawdown, Calmar ratio, win rate, and turnover.
The backtest is fully deterministic — same inputs always produce identical results.
After backtesting, use factor_analysis on the equity_curve to decompose returns into Fama-French factors (market, size, value, momentum) and estimate true alpha.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| stages | Yes | Pipeline stages defining the strategy. Each stage is an object with: order (int), type ('screen'|'analyze'|'signal'), skill (skill name), config (dict). Example: [{order: 1, type: 'screen', skill: 'fundamental_screen', config: {pe_lt: 15}}, {order: 2, type: 'signal', skill: 'momentum_screen', config: {lookback_days: 200, top_pct: 0.3}}] | |
| universe | No | Stock universe. Options: sp500, russell2000, nasdaq100 | sp500 |
| rebalance | No | Rebalance frequency. Options: daily, weekly, monthly, quarterly | monthly |
| sizing | No | Position sizing method. Options: equal_weight, inverse_volatility | equal_weight |
| start_date | No | Backtest start date in YYYY-MM-DD format | 2023-01-01 |
| end_date | No | Backtest end date in YYYY-MM-DD format. Defaults to today. | |
| max_position_size | No | Maximum weight per position (0-1). E.g., 0.1 = 10% max per stock | |
| stop_loss | No | Per-position stop loss (0-1). E.g., 0.15 = sell if position drops 15% | |
| max_drawdown | No | Maximum portfolio drawdown before going to cash (0-1). E.g., 0.2 = 20% |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |