From 959a863b5edee32760cf2c3237de49bd4cae24e9 Mon Sep 17 00:00:00 2001 From: aszerW Date: Mon, 25 May 2026 02:07:18 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=AF=BC=E5=87=BA=E8=84=9A=E6=9C=AC?= =?UTF-8?q?=E5=9B=A0=E5=AD=90=E5=AF=B9=E9=BD=90=E5=88=B0A=E8=82=A1?= =?UTF-8?q?=E6=97=A5=E5=8E=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 因子在原始数据上计算(正确) - 导出时将因子前向填充到A股交易日历 - 修复境外市场放假时动量显示为None的问题 --- framework_v2/scripts/export_backtest_detail.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/framework_v2/scripts/export_backtest_detail.py b/framework_v2/scripts/export_backtest_detail.py index 58c682d..75ef2e0 100644 --- a/framework_v2/scripts/export_backtest_detail.py +++ b/framework_v2/scripts/export_backtest_detail.py @@ -140,6 +140,10 @@ def main(): # 因子数据(DataFrame 格式) factor_df = pd.DataFrame(factors) + # 将因子对齐到 A 股交易日历(前向填充) + # 因子已经在原始数据上计算完成,这里只是将结果对齐到展示日历 + factor_df_aligned = factor_df.reindex(trading_calendar, method='ffill') + # 持仓状态跟踪 holdings_state = {} # {code: {'entry_date': str, 'entry_price': float}} prev_holdings = set() @@ -177,11 +181,11 @@ def main(): 'entry_price': entry_price, } - # 动态阈值 + # 动态阈值(使用对齐后的因子) factor_scores = {} - if date in factor_df.index: - for code in factor_df.columns: - v = factor_df.loc[date, code] + if date in factor_df_aligned.index: + for code in factor_df_aligned.columns: + v = factor_df_aligned.loc[date, code] if pd.notna(v): factor_scores[code] = float(v)