run_backtest_dynamic
Run a custom Python trading strategy in an isolated sandbox, validate its code and configuration, and get backtest performance metrics such as total return and max drawdown.
Instructions
Run a dynamic Strategy backtest in an isolated sandbox and persist artifacts.
Args:
code: Python source with exactly one Strategy subclass. Strategy rules and
allowed imports are enforced before execution; see quantforge://codegen/spec.
config_json: JSON string for backtest settings (required: symbols; optional:
name, start, end, initial_capital, commission, slippage,
target_weights, sizing_fraction, rebalance, last_rebalance_ts,
history_tail). Dates must be YYYY-MM-DD. Full schema and examples:
quantforge://codegen/spec.
Returns:
On success: {"ok": true, "job_id": str, "status": "done", "result": {...}}
where result includes metrics (total_return, max_drawdown, n_trades, ...).
On validation failure: {"ok": false, "validation": {...}} (no job created).
On runtime failure: {"ok": false, "job_id": str, "status": "failed", "error": str}.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| code | Yes | ||
| config_json | Yes |