fix: 导出脚本因子对齐到A股日历
- 因子在原始数据上计算(正确) - 导出时将因子前向填充到A股交易日历 - 修复境外市场放假时动量显示为None的问题
This commit is contained in:
@@ -140,6 +140,10 @@ def main():
|
|||||||
# 因子数据(DataFrame 格式)
|
# 因子数据(DataFrame 格式)
|
||||||
factor_df = pd.DataFrame(factors)
|
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}}
|
holdings_state = {} # {code: {'entry_date': str, 'entry_price': float}}
|
||||||
prev_holdings = set()
|
prev_holdings = set()
|
||||||
@@ -177,11 +181,11 @@ def main():
|
|||||||
'entry_price': entry_price,
|
'entry_price': entry_price,
|
||||||
}
|
}
|
||||||
|
|
||||||
# 动态阈值
|
# 动态阈值(使用对齐后的因子)
|
||||||
factor_scores = {}
|
factor_scores = {}
|
||||||
if date in factor_df.index:
|
if date in factor_df_aligned.index:
|
||||||
for code in factor_df.columns:
|
for code in factor_df_aligned.columns:
|
||||||
v = factor_df.loc[date, code]
|
v = factor_df_aligned.loc[date, code]
|
||||||
if pd.notna(v):
|
if pd.notna(v):
|
||||||
factor_scores[code] = float(v)
|
factor_scores[code] = float(v)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user