fix: GlobalRotationStrategy select_num 未生效
- 修复分散化选股逻辑:每个 group 选 Top 1 后,需要再按动量排序选 Top select_num - 之前:所有 group 的 Top 1 都标记为信号(忽略 select_num) - 现在:先从每个 group 选 Top 1,再从中按动量选 Top select_num 个 - 影响:配置 select_num=3 时,实际持仓 3 只而不是 4 只(group 数量)
This commit is contained in:
@@ -229,9 +229,20 @@ class GlobalRotationStrategy(StrategyBase):
|
||||
top_code = date_factors.idxmax()
|
||||
selected_codes.append(top_code)
|
||||
|
||||
# 标记信号
|
||||
# 第二步:从所有 group 的 Top 1 中,按动量再选 Top select_num 个
|
||||
if selected_codes:
|
||||
signals.loc[date, selected_codes] = 1
|
||||
# 获取这些标的的当日因子值
|
||||
candidate_factors = factor_df.loc[date][selected_codes].dropna()
|
||||
|
||||
if not candidate_factors.empty:
|
||||
# 按动量排序,选 Top select_num
|
||||
if len(candidate_factors) > self.select_num:
|
||||
final_selected = candidate_factors.nlargest(self.select_num).index.tolist()
|
||||
else:
|
||||
final_selected = candidate_factors.index.tolist()
|
||||
|
||||
# 标记信号
|
||||
signals.loc[date, final_selected] = 1
|
||||
|
||||
return signals.astype(int)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user