Skip to content

Commit e23f26a

Browse files
authored
Hide HK research and snapshot scaffolds from IBKR status (#127)
1 parent b011100 commit e23f26a

4 files changed

Lines changed: 22 additions & 46 deletions

File tree

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ jobs:
9494
assert CallableNotificationPort
9595
assert CallablePortfolioPort
9696
assert resolve_canonical_profile("mega_cap_leader_rotation_top50_balanced") == "mega_cap_leader_rotation_top50_balanced"
97-
assert resolve_hk_canonical_profile("hk_blue_chip_leader_rotation") == "hk_blue_chip_leader_rotation"
97+
assert resolve_hk_canonical_profile("hk_listed_global_etf_rotation") == "hk_listed_global_etf_rotation"
9898
PY
9999
100100
- name: Install editable shared repositories

docs/hk_equity_runtime.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ QuantStrategyLab 现有平台仓库里,能接入港股股票交易的平台是
1414

1515
## 运行时设计
1616

17-
本仓库只做券商运行时能力,不把港股策略逻辑硬编码进平台。当前已接入 `HkEquityStrategies` 的港股 profile 元数据`hk_blue_chip_leader_rotation` 是架构占位`hk_index_mean_reversion``hk_etf_regime_rotation``market_history` 研究候选,`hk_listed_global_etf_rotation` 已 runtime-enabled。生产 Cloud Run 仍保持原策略,除非单独变更 `RUNTIME_TARGET_JSON` / `STRATEGY_PROFILE`。整体沿用美股策略的架构:
17+
本仓库只做券商运行时能力,不把港股策略逻辑硬编码进平台。当前已接入 `HkEquityStrategies` 的港股 profile 元数据,平台可选港股 profile 只暴露 `runtime_enabled``hk_listed_global_etf_rotation``hk_blue_chip_leader_rotation` 是 snapshot 架构占位`hk_index_mean_reversion``hk_etf_regime_rotation``market_history` 研究候选,均留在研究/快照仓库,不进入平台可选列表。生产 Cloud Run 仍保持原策略,除非单独变更 `RUNTIME_TARGET_JSON` / `STRATEGY_PROFILE`。整体沿用美股策略的架构:
1818

19-
1. [`HkEquityStrategies`](https://github.com/QuantStrategyLab/HkEquityStrategies) 提供 `hk_equity` 策略 profile、运行入口和 IBKR runtime adapter。
19+
1. [`HkEquityStrategies`](https://github.com/QuantStrategyLab/HkEquityStrategies) 提供非 snapshot `hk_equity` 策略 profile、运行入口和 IBKR runtime adapter。
2020
2. [`HkEquitySnapshotPipelines`](https://github.com/QuantStrategyLab/HkEquitySnapshotPipelines) 发布 snapshot-backed profile 的 `<profile>_feature_snapshot_latest.csv`、manifest、ranking 和 release summary。
2121
3. 非 snapshot profile 使用平台 market-data feed 提供的 `market_history`,不需要 snapshot artifact。
2222
4. 平台仓库通过 `RUNTIME_TARGET_JSON`、snapshot/config 路径和平台 market scope 读取策略输入。
@@ -28,10 +28,12 @@ QuantStrategyLab 现有平台仓库里,能接入港股股票交易的平台是
2828

2929
| Profile | Domain | Inputs | Target mode | Snapshot manifest | Status |
3030
| --- | --- | --- | --- | --- | --- |
31-
| `hk_blue_chip_leader_rotation` | `hk_equity` | `feature_snapshot` | `weight` | required | eligible but disabled |
32-
| `hk_index_mean_reversion` | `hk_equity` | `market_history` | `weight` | not required | eligible but disabled |
33-
| `hk_etf_regime_rotation` | `hk_equity` | `market_history` | `weight` | not required | eligible but disabled |
34-
| `hk_listed_global_etf_rotation` | `hk_equity` | `market_history` | `weight` | not required | runtime-enabled; not deployed by default |
31+
| `hk_listed_global_etf_rotation` | `hk_equity` | `market_history` | `weight` | not required | runtime-enabled; platform-selectable |
32+
| `hk_blue_chip_leader_rotation` | `hk_equity` | `feature_snapshot` | `weight` | required | snapshot scaffold; not platform-selectable |
33+
| `hk_index_mean_reversion` | `hk_equity` | `market_history` | `weight` | not required | research/backtest only; not platform-selectable |
34+
| `hk_etf_regime_rotation` | `hk_equity` | `market_history` | `weight` | not required | research/backtest only; not platform-selectable |
35+
36+
`scripts/print_strategy_profile_status.py` 只显示平台可选 profile,因此只会列出 `hk_listed_global_etf_rotation` 这一条港股 profile。其他港股候选继续保留在研究文档和 snapshot pipeline,不应该出现在 Cloud Run switch plan 里。
3537

3638
未来启用 snapshot-backed profile 后的最小策略配置示例;当前不要写入 Cloud Run:
3739

@@ -145,5 +147,5 @@ gh workflow run sync-cloud-run-env.yml \
145147
- IBKR 港股实盘依赖账户权限、行情权限、Gateway 登录账户可见账号和交易许可;平台配置无法替代这些权限。
146148
- 不同 IBKR 账户或区域对港股 symbol 格式可能有差异,首批上线前需要用 dry-run 和小范围 symbol 做实盘连接验证。
147149
- `XHKG` 是否可用取决于部署环境里的 `pandas_market_calendars` 版本;如不可用,可用 `IBKR_MARKET_CALENDAR` 临时覆盖。
148-
- `hk_listed_global_etf_rotation` 已在策略包 runtime-enabled,但生产 Cloud Run 仍保持原配置;`hk_blue_chip_leader_rotation``hk_index_mean_reversion``hk_etf_regime_rotation` 仍未启用,不要写入生产 Cloud Run。
150+
- `hk_listed_global_etf_rotation` 已在策略包 runtime-enabled,但生产 Cloud Run 仍保持原配置;`hk_blue_chip_leader_rotation``hk_index_mean_reversion``hk_etf_regime_rotation` 不进入平台可选列表,不要写入生产 Cloud Run。
149151
- 港股 `market_history` profile 投入生产前,需要先用 IBKR HK 行情 feed 对 `02800``03033``02822``02840``03110``03188``02834``03175` 做 dry-run 校验,不提交真实订单。

strategy_registry.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,14 +105,16 @@ def describe_platform_runtime_requirements(profile: str | None, *, platform_id:
105105
),
106106
supported_capabilities=frozenset({"broker_client"}),
107107
)
108-
ELIGIBLE_STRATEGY_PROFILES = derive_eligible_profiles_for_platform(
108+
_STRUCTURALLY_ELIGIBLE_STRATEGY_PROFILES = derive_eligible_profiles_for_platform(
109109
STRATEGY_CATALOG,
110110
capability_matrix=PLATFORM_CAPABILITY_MATRIX,
111111
runtime_adapter_loader=lambda profile: get_platform_runtime_adapter(
112112
profile,
113113
platform_id=IBKR_PLATFORM,
114114
),
115115
)
116+
# Keep research-only and snapshot-scaffold HK profiles out of platform switch/status output.
117+
ELIGIBLE_STRATEGY_PROFILES = _STRUCTURALLY_ELIGIBLE_STRATEGY_PROFILES & IBKR_ROLLOUT_ALLOWLIST
116118
IBKR_ENABLED_PROFILES = derive_enabled_profiles_for_platform(
117119
STRATEGY_CATALOG,
118120
capability_matrix=PLATFORM_CAPABILITY_MATRIX,

tests/test_runtime_config_support.py

Lines changed: 9 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
"hk_etf_regime_rotation",
7474
}
7575
)
76-
EXPECTED_IBKR_PROFILES = EXPECTED_IBKR_ENABLED_PROFILES | HK_DISABLED_PROFILES
76+
EXPECTED_IBKR_PROFILES = EXPECTED_IBKR_ENABLED_PROFILES
7777

7878

7979
def runtime_target_json(
@@ -701,30 +701,6 @@ def test_platform_profile_status_matrix_matches_current_ibkr_rollout():
701701
assert by_profile["nasdaq_sp500_smart_dca"]["display_name"] == "Nasdaq/S&P 500 Smart DCA"
702702
assert by_profile["nasdaq_sp500_smart_dca"]["eligible"] is True
703703
assert by_profile["nasdaq_sp500_smart_dca"]["enabled"] is True
704-
assert by_profile["hk_blue_chip_leader_rotation"] == {
705-
"canonical_profile": "hk_blue_chip_leader_rotation",
706-
"display_name": "HK Blue Chip Leader Rotation",
707-
"domain": "hk_equity",
708-
"eligible": True,
709-
"enabled": False,
710-
"platform": "ibkr",
711-
}
712-
assert by_profile["hk_index_mean_reversion"] == {
713-
"canonical_profile": "hk_index_mean_reversion",
714-
"display_name": "HK Index Mean Reversion",
715-
"domain": "hk_equity",
716-
"eligible": True,
717-
"enabled": False,
718-
"platform": "ibkr",
719-
}
720-
assert by_profile["hk_etf_regime_rotation"] == {
721-
"canonical_profile": "hk_etf_regime_rotation",
722-
"display_name": "HK ETF Regime Rotation",
723-
"domain": "hk_equity",
724-
"eligible": True,
725-
"enabled": False,
726-
"platform": "ibkr",
727-
}
728704
assert by_profile["hk_listed_global_etf_rotation"] == {
729705
"canonical_profile": "hk_listed_global_etf_rotation",
730706
"display_name": "HK-listed Global ETF Rotation",
@@ -733,6 +709,8 @@ def test_platform_profile_status_matrix_matches_current_ibkr_rollout():
733709
"enabled": True,
734710
"platform": "ibkr",
735711
}
712+
for profile in HK_DISABLED_PROFILES:
713+
assert profile not in by_profile
736714

737715

738716
def test_print_strategy_profile_status_json_matches_registry():
@@ -774,12 +752,9 @@ def test_print_strategy_profile_status_json_matches_registry():
774752
assert by_profile["mega_cap_leader_rotation_top50_balanced"]["input_mode"] == "feature_snapshot"
775753
assert by_profile["mega_cap_leader_rotation_top50_balanced"]["requires_snapshot_artifacts"] is True
776754
assert by_profile["mega_cap_leader_rotation_top50_balanced"]["requires_strategy_config_path"] is False
777-
assert by_profile["hk_blue_chip_leader_rotation"]["profile_group"] == "snapshot_backed"
778-
assert by_profile["hk_blue_chip_leader_rotation"]["input_mode"] == "feature_snapshot"
779-
assert by_profile["hk_blue_chip_leader_rotation"]["requires_snapshot_artifacts"] is True
780-
assert by_profile["hk_blue_chip_leader_rotation"]["requires_snapshot_manifest_path"] is True
781-
assert by_profile["hk_blue_chip_leader_rotation"]["requires_strategy_config_path"] is False
782-
for profile in ("hk_index_mean_reversion", "hk_etf_regime_rotation", "hk_listed_global_etf_rotation"):
755+
for profile in ("hk_blue_chip_leader_rotation", "hk_index_mean_reversion", "hk_etf_regime_rotation"):
756+
assert profile not in by_profile
757+
for profile in ("hk_listed_global_etf_rotation",):
783758
assert by_profile[profile]["profile_group"] == "direct_runtime_inputs"
784759
assert by_profile[profile]["input_mode"] == "market_history"
785760
assert by_profile[profile]["requires_snapshot_artifacts"] is False
@@ -802,16 +777,13 @@ def test_print_strategy_profile_status_table_contains_expected_headers():
802777
assert "input_mode" in result.stdout
803778
assert "requires_snapshot_artifacts" in result.stdout
804779
assert "global_etf_rotation" in result.stdout
805-
assert "hk_blue_chip_leader_rotation" in result.stdout
806-
assert "hk_index_mean_reversion" in result.stdout
807-
assert "hk_etf_regime_rotation" in result.stdout
808780
assert "hk_listed_global_etf_rotation" in result.stdout
809781
assert "Tech/Communication Pullback Enhancement" in result.stdout
810-
assert "HK Blue Chip Leader Rotation" in result.stdout
811-
assert "HK Index Mean Reversion" in result.stdout
812-
assert "HK ETF Regime Rotation" in result.stdout
813782
assert "HK-listed Global ETF Rotation" in result.stdout
814783
assert "TQQQ Growth Income" in result.stdout
784+
assert "hk_blue_chip_leader_rotation" not in result.stdout
785+
assert "hk_index_mean_reversion" not in result.stdout
786+
assert "hk_etf_regime_rotation" not in result.stdout
815787

816788

817789
def test_print_strategy_switch_env_plan_for_tqqq_growth_income():

0 commit comments

Comments
 (0)