Skip to content

Commit 0e3d8b3

Browse files
committed
feat: implement dynamic pool mode for backtesting and enhance tradable bond filtering
1 parent 648b925 commit 0e3d8b3

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

convertible_bond/gui/controllers/backtest.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,11 @@ def _run_strategy_backtest(self):
542542
freq_map = {"周": "W", "月": "M", "季": "Q"}
543543
view = self.v_st_view.get()
544544
policy = STRATEGY_VIEW_POLICY.get(view, _DEFAULT_VIEW_POLICY)
545+
# 本地全市场池含大量退市/已到期/定向债, 静态全量送 Wind 会大面积取数失败。
546+
# 改用动态时点池: 每期先按 list_tradable_cbs(当期) 取存活券再筛选定价,
547+
# 无幸存者偏差且从源头避开死债的 Wind 请求。自选/当前筛选池保持静态。
548+
gui_pool_mode = self.v_st_pool_mode.get() if hasattr(self, "v_st_pool_mode") else "本地全市场"
549+
engine_pool_mode = "dynamic" if gui_pool_mode == "本地全市场" else "static"
545550
try:
546551
config = ScoreStrategyConfig(
547552
top_n=max(1, int(float(self.v_st_top_n.get()))),
@@ -563,6 +568,7 @@ def _run_strategy_backtest(self):
563568
execution_timing="next_close",
564569
transaction_cost=max(0.0, self._optional_float(self.v_st_cost) or 0.0) / 10000.0,
565570
compute_benchmark=bool(self.v_st_benchmark.get()),
571+
pool_mode=engine_pool_mode,
566572
)
567573
admission_config = AdmissionFilterConfig(
568574
delist_window_days=max(0, int(float(self.v_st_delist_window.get() or 0))),

convertible_bond/strategy_backtest.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1091,7 +1091,12 @@ def _dynamic_pool_for_date(
10911091
try:
10921092
tradable = provider.list_tradable_cbs(on_date)
10931093
if tradable:
1094-
tradable_set = set(str(code) for code in tradable)
1094+
# list_tradable_cbs 返回 [(wind_code, sec_name), ...]; 仅取代码做交集。
1095+
# 兼容个别 provider 直接返回代码字符串的情况。
1096+
tradable_set = {
1097+
str(entry[0] if isinstance(entry, (tuple, list)) else entry)
1098+
for entry in tradable
1099+
}
10951100
return [code for code in base_codes if code in tradable_set]
10961101
except (NotImplementedError, Exception):
10971102
pass

0 commit comments

Comments
 (0)