From b374e06bf8f85f05bb045a7ed715763a904b97b8 Mon Sep 17 00:00:00 2001
From: log
Date: Thu, 09 Jul 2026 21:28:11 +0800
Subject: [PATCH] fix: retry baostock returned network errors
---
code/strategy/multi_factor_model.py | 47 +++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 47 insertions(+), 0 deletions(-)
diff --git a/code/strategy/multi_factor_model.py b/code/strategy/multi_factor_model.py
index fd57cd7..5fe6f09 100644
--- a/code/strategy/multi_factor_model.py
+++ b/code/strategy/multi_factor_model.py
@@ -249,6 +249,15 @@
return weights
+ def get_weights(self) -> Dict[str, float]:
+ """
+ 获取当前因子权重
+
+ Returns:
+ 当前因子权重字典
+ """
+ return self.current_weights.copy() if self.current_weights else {}
+
def get_weight_stability(self) -> Dict:
"""
获取权重稳定性指标
@@ -308,6 +317,44 @@
})
return pd.DataFrame(reports).sort_values('current_weight', ascending=False)
+
+ def calculate_score(self, factor_df: pd.DataFrame) -> pd.Series:
+ """
+ 计算综合得分
+
+ Args:
+ factor_df: 因子数据 DataFrame (index: stock_code, columns: factor_names)
+
+ Returns:
+ 综合得分 Series (index: stock_code)
+ """
+ if not self.current_weights:
+ n = len(factor_df.columns)
+ weights = {f: 1.0/n for f in factor_df.columns}
+ else:
+ weights = self.current_weights
+
+ available_factors = [f for f in weights.keys() if f in factor_df.columns]
+
+ if not available_factors:
+ return pd.Series(0.0, index=factor_df.index)
+
+ scores = pd.Series(0.0, index=factor_df.index)
+
+ for factor in available_factors:
+ weight = weights[factor]
+ factor_data = factor_df[factor]
+
+ mean = factor_data.mean()
+ std = factor_data.std()
+ if std > 0:
+ normalized_factor = (factor_data - mean) / std
+ else:
+ normalized_factor = pd.Series(0.0, index=factor_data.index)
+
+ scores += weight * normalized_factor
+
+ return scores
class MultiFactorScoreModel:
--
Gitblit v1.8.0