feat: 添加因子对齐调试输出

- 检查 factor_df 索引类型
- 检查 reindex 后 2026-04-30 的 HSI 动量值
- 待进一步分析为何 ffill 未生效
This commit is contained in:
2026-05-25 02:45:27 +08:00
parent 0ef0623538
commit 2f6b031361

View File

@@ -143,10 +143,25 @@ def main():
# 因子数据DataFrame 格式)
factor_df = pd.DataFrame(factors)
# 调试输出
print(f"[DEBUG] factor_df 索引类型: {type(factor_df.index)}")
print(f"[DEBUG] factor_df 索引是否为 DatetimeIndex: {isinstance(factor_df.index, pd.DatetimeIndex)}")
print(f"[DEBUG] factor_df 索引示例: {factor_df.index[:3]}")
# 确保索引是 DatetimeIndex
if not isinstance(factor_df.index, pd.DatetimeIndex):
print("[DEBUG] 转换索引为 DatetimeIndex...")
factor_df.index = pd.to_datetime(factor_df.index)
# 将因子对齐到实际展示日历(前向填充)
# 因子已经在原始数据上计算完成,这里只是将结果对齐到展示日历
factor_df_aligned = factor_df.reindex(common_dates, method='ffill')
# 调试:检查 2026-04-30 的值
if '2026-04-30' in common_dates:
hsi_val = factor_df_aligned.loc['2026-04-30', 'HSI'] if 'HSI' in factor_df_aligned.columns else 'NO COLUMN'
print(f"[DEBUG] factor_df_aligned['2026-04-30', 'HSI']: {hsi_val}")
# 持仓状态跟踪
holdings_state = {} # {code: {'entry_date': str, 'entry_price': float}}
prev_holdings = set()