修复关键问题:移除多时间框架处理中的bfill(),避免数据前瞻偏差

This commit is contained in:
zhangkun9038@dingtalk.com 2026-02-24 01:04:12 +08:00
parent 369a3e7b8a
commit dc4fa4411a

View File

@ -741,7 +741,8 @@ class FreqaiPrimer(IStrategy):
# 确保 StochRSI 指标已正确计算
# 将 1h 数据重新索引到主时间框架 (3m),并填充缺失值
df_1h = df_1h.set_index('date').reindex(dataframe['date']).ffill().bfill().reset_index()
# 注意:只使用 ffill()(向前填充),不要用 bfill()(避免数据前瞻偏差)
df_1h = df_1h.set_index('date').reindex(dataframe['date']).ffill().reset_index()
df_1h = df_1h.rename(columns={'index': 'date'})
# Include macd_1h, macd_signal_1h, ema_5_1h, ema_20_1h, ema5_cross_above_ema20 in the column selection
df_1h = df_1h[['date', 'rsi_1h', 'trend_1h', 'ema_50_1h', 'ema_200_1h', 'bb_lower_1h', 'bb_upper_1h', 'stochrsi_k_1h', 'stochrsi_d_1h', 'macd_1h', 'macd_signal_1h', 'macd_hist_1h', 'ema_5_1h', 'ema_20_1h', 'ema20_slope_normalized', 'ema5_cross_above_ema20']].ffill()