feat: 添加因子对齐调试输出
- 检查 factor_df 索引类型 - 检查 reindex 后 2026-04-30 的 HSI 动量值 - 待进一步分析为何 ffill 未生效
This commit is contained in:
@@ -143,10 +143,25 @@ def main():
|
|||||||
# 因子数据(DataFrame 格式)
|
# 因子数据(DataFrame 格式)
|
||||||
factor_df = pd.DataFrame(factors)
|
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')
|
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}}
|
holdings_state = {} # {code: {'entry_date': str, 'entry_price': float}}
|
||||||
prev_holdings = set()
|
prev_holdings = set()
|
||||||
|
|||||||
Reference in New Issue
Block a user