Commit ce1261ab authored by wenwen.tang's avatar wenwen.tang 😕

新增投组校验,防止投组全为ft的情况

加入风险等级的判断
parent f8f83edd
......@@ -29,10 +29,13 @@ class DefaultPortfoliosChecker(PortfoliosChecker):
# step1: 检查原始投组的customType。检查顺序用列表呈现,依序进行
priority = self._config.get('custom-type-priority')
for p in priority:
# 找出对应优先级序列的基金列表
keys = [key for key in portfolios.keys() if customType[key] == p]
# 若存在匹配值则执行后跳出循环
if len(keys) > 0:
ids = [fund['id'] for fund in funds if fund['companyType'] != list(companies)[0]]
# 选取非同公司的、风险等级小于等于原基金的 基金
ids = [fund['id'] for fund in funds if fund['companyType'] != list(companies)[0] and
fund['risk'] <= min(fund['risk'] for fund in funds if fund['id'] in keys)]
best = self.find_highest_score(ids, day)
# 若刚好有一个匹配,直接替换
if len(keys) == 1:
......@@ -42,7 +45,7 @@ class DefaultPortfoliosChecker(PortfoliosChecker):
else:
# 算分,把分低的替换掉
scores = self.do_score(keys, day)
weight_scores = {key: scores[key]*portfolios[key] for key in keys}
weight_scores = {key: scores[key] * portfolios[key] for key in keys}
lowest = min(scores, key=lambda k: weight_scores[k])
portfolios[best] = portfolios[lowest]
# 删除原始键
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment