From 982fbe250b21eb2c89b537e397b78974ae2a9619 Mon Sep 17 00:00:00 2001 From: aszerW Date: Wed, 20 May 2026 22:34:12 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E8=B7=A8=E5=B8=82?= =?UTF-8?q?=E5=9C=BA=E6=94=B6=E7=9B=8A=E7=8E=87=E8=AE=A1=E7=AE=97Bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bug机制: - 先pct_change再ffill对齐,导致海外标的休市日复制前一天非零收益率 - 例如:美股圣诞节放假,但ffill填入前一天的+1.2%,重复计算收益 修复方案: - 先ffill价格对齐到A股日历(休市日价格不变) - 再pct_change计算收益率(休市日自然为0%) 影响: - 修复前净值: 394.80(高估) - 修复后净值: 16.23(真实) - 该Bug导致海外标的在A股独有的交易日被重复计算收益 验证: - 语法检查通过 - 回测运行正常 --- strategies/rotation/strategy.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/strategies/rotation/strategy.py b/strategies/rotation/strategy.py index 1e9ae13..f60b56f 100644 --- a/strategies/rotation/strategy.py +++ b/strategies/rotation/strategy.py @@ -420,10 +420,11 @@ class RotationStrategy(StrategyBase): # 提取原始收盘价序列 if 'close' in df.columns: close_series = df['close'].dropna() - # 先在原始交易日历计算收益率 - returns_series = close_series.pct_change(fill_method=None) - # 然后对齐到A股交易日历(用ffill填充非共同交易日) - returns_aligned = returns_series.reindex(a_share_dates, method='ffill') + # 修复:先ffill价格对齐到A股日历,再计算收益率 + # 原因:若先pct_change再ffill,休市日会复制前一天的非零收益率 + # 正确做法:休市日价格不变 → 收益率应为0% + close_aligned = close_series.reindex(a_share_dates, method='ffill') + returns_aligned = close_aligned.pct_change(fill_method=None) returns_data[f'日收益率_{code}'] = returns_aligned returns_df = pd.DataFrame(returns_data)