跳转至

2026-03-09

  • OpenClaw model: attempting to set default openai/gpt-5.4 caused Agent failed before reply: Unknown model due to catalog/validation; reverted default back to openai/gpt-5.2.
  • clawtrading refactor work:
  • Added docs skeleton under clawtrading/docs/ (overview, cron runbook, execution engine).
  • Archived unused entry scripts to clawtrading/legacy/src/: rebalance_v2*, open_exec_ctl/status.
  • Added planner order truncation options --truncate-by alpha|risk_adj; default later set to alpha.
  • Backtest markowitz_backtest_us.py gained truncation params (max_holdings + truncate_by) and report header echo.
  • Universe registry introduced as ground truth:
  • clawtrading/config/universe_registry.json
  • src/universe_registry.py + approval script writes registry + exports snapshots status/universe_US_SIM_active.json / status/universe_HK_SIM_active.json.
  • Planners default to --universe-source registry_active and fallback to approved if snapshot/active missing.
  • Plan/execute naming and schema simplification:
  • Universe snapshots reduced to minimal fields (schema, market_key, universe_id, symbols).
  • Planners emit minimal clawtrading.rebalance_plan.v1 JSON, but still write legacy filenames for compatibility.
  • US executor updated to prefer market_key plan/confirm files with legacy fallback (--market-key).
  • Added src/rebalance_confirm.py to write rebalance_plan_confirmed_<MARKETKEY>.json (+ legacy).
  • Updated print_plan_summary.py to prefer keyed plan, compute turnover/fee from orders, and show correct executor command.
  • HK execution attempt revealed issues: cash insufficient when sell leg produced no proceeds; fixed execution_engine:
  • abort BUY stage on cash poll timeout for HK (proceed_on_cash_timeout=False in HK executor)
  • fix order book unpack in counter_price (levels rows may have >2 columns)
  • lot-size aware BUY downsizing/rounding for HK.
  • OpenClaw upgraded to 2026.3.7; tightened security: set Discord groupPolicy=allowlist, chmod 700 ~/.openclaw/credentials.
  • clawtrading cleanup:
  • HK executor now supports --market-key and prefers keyed plan/confirm files.
  • Moved legacy US preopen/confirm scripts to clawtrading/legacy/src/ and replaced src/us_preopen_plan.py + src/confirm_us_rebalance_plan.py with deprecated shims that call the unified rebalance planner/confirm.
  • Updated clawtrading/config/cron_jobs.json to use unified rebalance plan pipeline; renamed job to ct-us-rebalance-plan and updated docs.
  • Ops: user requested removal of macOS LaunchAgents (except gateway) in favor of OpenClaw built-in cron; moved the following plists to ~/.Trash/ after launchctl bootout: ai.openclaw.level2-us, com.openclaw. (auto-rebalance, daily-model-update, data-cache, risk-guardian, order-check-*, us-open-market-execute, us-preopen-plan, etc.). Remaining: ai.openclaw.gateway.plist.

策略插件化 + 统一回测 (20:00-20:35)

策略 Schema + Loader

  • src/strategy_schema.py: StrategyConfig dataclass (UniverseConfig/AlphaConfig/OptimizerConfig/RiskConfig/ExecutionConfig)
  • src/strategy_loader.py: 从 config/strategies/*.json 加载策略
  • 3个策略JSON: markowitz_alpha_v9 (US生产), markowitz_alpha_v9_hk (HK生产), markowitz_mean_v9 (A/B基线)
  • src/run_strategy.py: 统一planner入口,读策略JSON→构建CLI参数→执行

统一回测引擎

  • src/markowitz_backtest.py: 合并US+HK,市场从策略JSON自动推断
  • 统一simulate(): US费率跟踪 + HK止损系统 + 组合熔断器
  • compute_schedules_shared(): 日期级串行+策略共享计算(cov/p_up/ma60只算一次)
  • 比ProcessPoolExecutor更快:70-85%计算共享,零进程开销
  • 旧 markowitz_backtest_us.py / _hk.py 变thin shim
  • Commits: 2be15ed, 78fe8d3, 52e0478, 942da05

回归测试

  • scripts/capture_golden.py: 生成基准golden files
  • tests/test_backtest_regression.py: 参数化pytest,19/19 core cases passing
  • tests/golden/: weights(1e-10), equity(1e-8), metrics(1e-6), CB events(exact)
  • docs/70_backtest_regression_tests.md: 完整测试方案
  • Commit: 12d67bd

回归对比 + Bug 发现 (20:40)

精确参数对比 (US 2y, end 2026-03-04, topk=15, max_holdings=8)

  • base/minvar/SPY 一致(±2pp 日期对齐差异)
  • alpha 差异 -38pp: 旧版 +100.59% → 新版 +61.93%

发现旧版 Bug

  • 旧 markowitz_backtest_us.py: mu_alpha 变量在 alpha_precomputed=True 分支未赋值
  • truncation 用 score = mu_alpha.copy() → 读到上次循环残值
  • 新版 _optimize_single_strategy 正确用 mu_for_trunc(当前 rebalance 点实际 mu)
  • 旧版高收益是"幸运 bug"——残值排序碰巧选中好组合
  • 新版行为才是正确的

Golden files 需要注意

  • 当前 golden files 是基于新版(修复后)代码生成的
  • 与旧版报告不可直接对比(truncation 逻辑不同)

新特征 + A/B + 模型管理 (20:45-21:50)

v9.3 新特征(6个)

  • 加入 alpha_features.py + level1_pipeline.py
  • mom_accel_5_20, mom_accel_10_20, vol_contraction, range_position_20, ma_converge_5_20, dd_from_60d_high

特征重要性分析 → 精选 v9.4

  • v9.3 (67 features) 表现下降: +32.1% Sharpe 0.98 (vs 旧模型 +76%)
  • 旧特征重训 (61 features): +29.8% Sharpe 0.94 — 也下降!
  • 根因:3/9 重训 vs 3/3 旧模型,训练时间点才是最大变量
  • 特征重要性排序:range_position_20 (#4), dd_from_60d_high (#8) 有价值;其余4个 (#17-41) 噪音
  • 精选 v9.4 (63 features, +2): +37.5% Sharpe 1.07 — 三个版本中最好
  • Commits: cf702f8 (v9.3), b600ffd (v9.4 精选)

模型版本化管理

  • models/current 改为 symlink → models/releases/<timestamp>_<tag>/
  • scripts/promote_models.py: 标准 promote 流程 + manifest
  • 回滚: ln -sfn releases/<旧版> models/current
  • 当前 active: 20260309_213401_v94 (63 features)
  • Commit: d7c01c4

CONFIG NameError 修复

  • US/HK planner 里 resolve_macro_profile(CONFIG, ...)resolve_macro_profile(ROOT / "config", ...)
  • CONFIG 变量未定义,cron 运行时 NameError
  • Commit: 524edf1

Cron 改名

  • ct-us-preopen-planct-us-rebalance-plan
  • ct-hk-preopen-planct-hk-rebalance-plan
  • ct-us-open-market-executect-us-rebalance-execute

三项优化实现

  1. Anchor assets: SPY/QQQ 在回撤>10%时自动加入候选池
  2. 动态调仓频率: 正常20天,回撤>10%时10天
  3. Walk-forward: scripts/train_wf_snapshots.py,10个快照正在训练 (~80min)
  4. A/B (#1+#3 无WF): +37.6% vs +37.5%(差异极小)
  5. WF 训练在后台 /tmp/train_wf.log
  6. Commit: 8ab0389

Walk-forward + Munger 回测 (23:00-23:16)

Walk-forward 结果

  • 10个WF snapshot训练完成(~75min),每60交易日一个
  • WF回测: +35.6% Sharpe 1.05 MDD -18.8% (vs 固定模型 +37.5% MDD -22.7%)
  • WF用1.9pp收益换4pp MDD改善——风控更好但收益略低
  • _ensure_wf_models 加了 nearest-snapshot fallback(避免在线重训)
  • Commit: 061ee10

核心发现:候选股票池才是关键

  • 固定approved 30只 (Munger最新): +37.5% Sharpe 1.07
  • 固定candidates 62只 (screener全集): +22.5% Sharpe 0.86
  • 动态月度选股 Munger: +164% Sharpe 2.52 MDD -20.4%
  • 结论: 动态universe >>> 固定universe,ML alpha信号本身价值有限
  • 每月用技术面+流动性打分选Top30 + walk-forward LogisticRegression + Markowitz
  • 无look-ahead,完全用历史数据

模型版本化

  • models/current → symlink → models/releases/_/
  • 当前: 20260309_213401_v94 (63 features)
  • scripts/promote_models.py + rollback via symlink
  • Commit: d7c01c4

回测引擎大重构 (23:16-00:33)

动态选股整合

  • Munger 独立回测逻辑整合到主引擎 markowitz_backtest.py
  • 新增: dynamic_pick(), simulate_weights(), compute_schedule_munger()
  • 新增 universe source: screener (547只全量)
  • 新增 alpha model: wf_logreg (walk-forward LogisticRegression)
  • 策略配置: markowitz_wf_munger.json (最佳), markowitz_wf_munger_ext.json

A/B 测试结果汇总

  • 固定approved 30只 (alpha_v9): +22.5% Sharpe 0.86
  • 固定candidates 62只: +22.5% Sharpe 0.86
  • 动态alpha_v9_dynamic 62只: +48.4% Sharpe 1.43
  • 动态mean_dynamic 62只: +72.3% Sharpe 1.68
  • 动态wf_dynamic_fast 547只: +103% Sharpe 1.35
  • 动态wf_munger 547只 每日check: +203.4% Sharpe 2.53 MDD -18.8% ← 最佳
  • 动态wf_munger_ext 13特征: +199.3% Sharpe 2.54 MDD -17.3% (风控更好)
  • Munger独立回测: +164% Sharpe 2.52

关键发现

  1. 动态选股 >>> 固定universe(最大收益来源)
  2. 每日check + turnover trigger >>> 固定grid step
  3. 547只全量pool >>> 62只candidates
  4. 简单5特征LogReg ≈ 复杂13特征(alpha主要来自选股不是预测)
  5. weight-based simulate > share-based(weight更理想化但更准确反映策略能力)
  6. 子集cov (30x30) vs 全量cov (547x547) 影响显著

测试覆盖

  • 73个pytest测试全部通过
  • 15个测试类,覆盖单元/集成/一致性/精度/边界
  • docs/backtest_test_plan.md + tests/test_backtest_engine.py

Legacy迁移

  • us_open_market_plan_markowitz_alpha_v9_2.py → legacy/
  • hk_open_market_plan_markowitz_alpha_v9_2.py → legacy/
  • us_preopen_plan.py → legacy/
  • munger_backtest_us.py → legacy/

Commits

  • 2f9ae82: exact Munger daily-check logic
  • a38eefe: Munger-style simulation integrated
    • screener universe, wf_logreg, extended features, test suite