Phoenix Iterate
A structured workflow for AI-assisted quantitative strategy iteration. Instead of randomly tweaking code, this skill enforces a disciplined loop: read history, form hypothesis, write code, validate against past mistakes, backtest progressively, diagnose results, and record lessons.
Dependencies
This skill is an orchestrator — it coordinates two companion skills that must be installed separately:
| Skill | Purpose | Commands provided |
|---|
| INLINECODE0 | Backtest submission, monitoring, early-stop, results | INLINECODE1 |
| INLINECODE2 |
Deep feature-level forensic analysis |
deep_forensics.py |
Install them first:
CODEBLOCK0
All cli.py references below assume backtest-poller is installed as a sibling directory (../backtest-poller/cli.py). Adjust the path if your install location differs.
When to use
- - "Let's iterate on the strategy"
- "Start a new strategy version"
- "Run the phoenix iteration loop"
- "What should I try next?"
The Iteration Loop
CODEBLOCK1
Step 1: Get Decision Context
CODEBLOCK2
Returns:
- - Constitutional memory (all past lessons sorted by severity)
- Available strategy blueprints with historical performance
- Mutation dimensions (what can be changed)
- Recent iteration history (what was tried, what happened)
- Resource constraints and validation windows
Step 2: Form a Trading Hypothesis
Before writing code, answer these questions:
- 1. What am I changing? — Pick exactly one mutation dimension
- Why do I think this will be better? — Based on data, not intuition
- What if I'm wrong? — Worst case scenario, does it violate any iron laws?
- Will this affect trade frequency? — If trades decrease, there must be a compensating mechanism
Mutation Dimensions:
| Dimension | Description | Examples |
|---|
| INLINECODE7 | How the strategy survives downturns | QQQ buy-and-hold, cash defense, SMA filter |
| INLINECODE8 |
How much capital per trade | Kelly %, max trade value, total exposure cap |
|
selection | What stocks to trade | Premarket volume, RS breakout, HV lottery |
|
profit_management | What to do with winners | Hold to expiry, take-profit at 200%, trailing stop |
Step 3: Write & Scan Code
- 1. Create a new strategy directory: INLINECODE11
- Base it on the latest passing version
- Run constitutional scan:
CODEBLOCK3
If violations are found, fix them before submitting.
Step 4: Progressive Validation
Submit through increasingly demanding test windows. Only promote to the next stage after passing.
CODEBLOCK4
CODEBLOCK5
Shortcut: If you only changed profit management (not entry logic), you can skip Smoke/Stress and start from Medium.
Step 5: Diagnose
CODEBLOCK6
For deeper analysis, run the feature forensics (requires qc-deep-feature-forensics skill):
CODEBLOCK7
Step 6: Record & Decide
CODEBLOCK8
Decision Matrix:
| Outcome | Action |
|---|
| Current stage passed | Change dates to next stage, resubmit |
| DD exceeded but promising |
Analyze monthly cashflow, find bleeding point, targeted fix |
| Too few trades |
Red flag — loosen entry conditions or shorten cooldown |
| Sharpe < 1.0 but DD ok | Acceptable for now, optimize Sharpe later |
| Full period passed | Strategy qualified! |
Quick Reference
CODEBLOCK9
Rules
- - Only 1 backtest can run at a time (serial execution). Never submit a second backtest while one is running.
- Full-period backtests take 2-3 hours — always use progressive validation to fail fast. Do not jump directly to full-period.
- Always run
scan_strategy() before submitting. Constitutional violations must be resolved before backtest submission. Do not bypass the scanner. - Each iteration must change exactly one mutation dimension. Changing multiple variables at once makes it impossible to attribute success or failure to a specific change.
- Record every iteration result, including failures. Unrecorded iterations will be lost and the same mistake may be repeated.
- The poller daemon handles monitoring automatically after submission. Do not poll the QC API manually — let the daemon manage state.
Phoenix Iterate
一个用于AI辅助量化策略迭代的结构化工作流。该技能不是随机调整代码,而是强制执行一个纪律性循环:读取历史、形成假设、编写代码、验证过往错误、渐进式回测、诊断结果并记录经验教训。
依赖项
本技能是一个编排器——它协调两个必须单独安装的配套技能:
| 技能 | 用途 | 提供的命令 |
|---|
| backtest-poller | 回测提交、监控、提前停止、结果 | cli.py submit/status/results/logs |
| qc-deep-feature-forensics |
深度特征级取证分析 | deep_forensics.py |
首先安装它们:
bash
clawhub install backtest-poller
clawhub install qc-deep-feature-forensics
下文所有cli.py引用均假设backtest-poller作为同级目录安装(../backtest-poller/cli.py)。如果安装位置不同,请调整路径。
使用时机
- - 让我们迭代策略
- 开始新的策略版本
- 运行凤凰迭代循环
- 接下来应该尝试什么?
迭代循环
步骤1:简报 ──> 读取宪法记忆 + 历史记录
步骤2:假设 ──> 选择一个突变维度,形成可测试的假设
步骤3:代码 ──> 编写策略,扫描违规
步骤4:提交 ──> 渐进式验证(冒烟 -> 压力 -> 中等 -> 完整)
步骤5:诊断 ──> 对结果进行取证分析
步骤6:记录 ──> 用新经验更新宪法记忆
|
└──────────> 循环回到步骤1
步骤1:获取决策上下文
bash
python3 orchestrator.py briefing
返回:
- - 宪法记忆(按严重程度排序的所有过往经验教训)
- 可用的策略蓝图及历史表现
- 突变维度(可以更改的内容)
- 近期迭代历史(尝试过什么,发生了什么)
- 资源约束和验证窗口
步骤2:形成交易假设
在编写代码之前,回答以下问题:
- 1. 我在改变什么? — 只选择一个突变维度
- 为什么我认为这会更好? — 基于数据,而非直觉
- 如果我错了怎么办? — 最坏情况,是否违反任何铁律?
- 这会影响交易频率吗? — 如果交易减少,必须有补偿机制
突变维度:
| 维度 | 描述 | 示例 |
|---|
| survivalstructure | 策略如何度过市场低迷期 | QQQ买入持有、现金防御、SMA过滤器 |
| positionsizing |
每笔交易投入多少资金 | 凯利百分比、最大交易价值、总敞口上限 |
| selection | 交易哪些股票 | 盘前成交量、RS突破、HV彩票 |
| profit_management | 如何处理盈利头寸 | 持有至到期、200%止盈、移动止损 |
步骤3:编写并扫描代码
- 1. 创建新的策略目录:strategies/M{N}_{description}/main.py
- 基于最新通过的版本
- 运行宪法扫描:
bash
python3 orchestrator.py scan --code strategies/M31_test/main.py
如果发现违规,在提交前修复。
步骤4:渐进式验证
通过越来越严格的测试窗口提交。只有通过后才能进入下一阶段。
阶段1:冒烟测试 (3个月, ~15分钟) 最大回撤 < 50% — 捕捉明显错误
阶段2:压力测试 (5个月, ~30分钟) 最大回撤 < 45% — 在最差条件下存活
阶段3:中等测试 (18个月, ~1小时) 最大回撤 < 42% — 牛熊转换
阶段4:完整测试 (3年, ~3小时) 最大回撤 < 40% — 最终验收
bash
检查是否有活跃回测 (backtest-poller 技能)
python3 ../backtest-poller/cli.py status
提交并启用提前停止保护
python3 ../backtest-poller/cli.py submit \
--backtest-id
\
--name MyStrategy_smoke \
--max-dd 50
监控进度
python3 ../backtest-poller/cli.py status
完成后查看结果
python3 ../backtest-poller/cli.py results --name MyStrategy_smoke --full
快捷方式:如果只更改了利润管理(而非入场逻辑),可以跳过冒烟/压力测试,直接从中等测试开始。
步骤5:诊断
bash
python3 orchestrator.py diagnose \
--orders results/MyStrategysmoke/xxxorders.csv \
--result results/MyStrategysmoke/xxxresult.json
如需更深入分析,运行特征取证分析(需要qc-deep-feature-forensics技能):
bash
python3 ../qc-deep-feature-forensics/deepforensics.py results/MyStrategysmoke/xxx_orders.csv
步骤6:记录与决策
bash
python3 orchestrator.py record \
--name MyStrategy_v2 \
--blueprint baseline \
--dimension position_sizing \
--hypothesis 将仓位规模降至2%以获得更好的生存能力 \
--window smoke_test \
--status completed \
--sharpe 1.5 \
--drawdown 0.35 \
--net-profit 0.85
决策矩阵:
| 结果 | 行动 |
|---|
| 当前阶段通过 | 更改日期至下一阶段,重新提交 |
| 最大回撤超标但有前景 |
分析月度现金流,找到出血点,针对性修复 |
| 交易太少 | 红色警报 — 放宽入场条件或缩短冷却期 |
| 夏普比率 < 1.0 但最大回撤正常 | 暂时可接受,后续优化夏普比率 |
| 完整周期通过 | 策略合格! |
快速参考
bash
本技能(编排器)
python3 orchestrator.py briefing # 决策上下文
python3 orchestrator.py status # 系统状态
python3 orchestrator.py list # 可用策略
python3 orchestrator.py scan --code # 代码违规检查
backtest-poller 技能
python3 ../backtest-poller/cli.py status # 回测状态
python3 ../backtest-poller/cli.py logs --lines 30 # 轮询器日志
python3 ../backtest-poller/cli.py results --name --full # 查看结果
qc-deep-feature-forensics 技能
python3 ../qc-deep-feature-forensics/deep_forensics.py # 深度取证分析
规则
- - 一次只能运行1个回测(串行执行)。切勿在回测运行中提交第二个回测。
- 完整周期回测需要2-3小时 — 始终使用渐进式验证以快速失败。不要直接跳到完整周期。
- 提交前始终运行scan_strategy()。 宪法违规必须在回测提交前解决。不要绕过扫描器。
- 每次迭代必须只更改一个突变维度。 同时更改多个变量将无法将成功或失败归因于特定更改。
- 记录每次迭代结果,包括失败。未记录的迭代将丢失,相同的错误可能会重复发生。
- 提交后轮询器守护进程自动处理监控。 不要手动轮询QC API——让守护进程管理状态。