fix(datasource): 修复溢价率计算重复日期导致的 reindex 失败
问题:长时间范围 ETF 数据获取时,出现 'cannot reindex on an axis with duplicate labels' 错误 修复: - 在 _calculate_premium_series 中先检测并去除重复日期 - price_df 和 nav_df 的索引都使用 duplicated(keep='last') 去重 - 确保 reindex 操作正常执行
This commit is contained in:
@@ -247,7 +247,17 @@ class UniversalDataFetcher:
|
||||
"""
|
||||
# 对齐日期:净值用ffill填充(因为T+1公布)
|
||||
# 价格日期可能比净值日期多一天
|
||||
aligned_nav = nav_df['nav'].reindex(price_df.index, method='ffill')
|
||||
# 先去除重复日期
|
||||
price_index = price_df.index
|
||||
if price_index.has_duplicates:
|
||||
price_df = price_df[~price_df.index.duplicated(keep='last')]
|
||||
price_index = price_df.index
|
||||
|
||||
nav_index = nav_df.index
|
||||
if nav_index.has_duplicates:
|
||||
nav_df = nav_df[~nav_df.index.duplicated(keep='last')]
|
||||
|
||||
aligned_nav = nav_df['nav'].reindex(price_index, method='ffill')
|
||||
|
||||
# 计算溢价率
|
||||
close_prices = price_df['close']
|
||||
|
||||
Reference in New Issue
Block a user