Commit 0f9ed718 authored by 赵杰's avatar 赵杰

默认诊断报告的数据一致性

parent 4d433e86
...@@ -1061,7 +1061,7 @@ class PortfolioDiagnose(object): ...@@ -1061,7 +1061,7 @@ class PortfolioDiagnose(object):
return ret, old_return_compare_result, old_indicator_compare return ret, old_return_compare_result, old_indicator_compare
def new_evaluation(self, group_name, group_result, data_adaptor, fund_tye_dict=None): def new_evaluation(self, group_name, group_result, data_adaptor, fund_tye_dict=None, default=0):
try: try:
group_result_data = group_result[group_name] group_result_data = group_result[group_name]
hold_info = group_result_data["group_hoding_info"] hold_info = group_result_data["group_hoding_info"]
...@@ -1148,6 +1148,8 @@ class PortfolioDiagnose(object): ...@@ -1148,6 +1148,8 @@ class PortfolioDiagnose(object):
suggestions["fund_type"] = hold["fund_type"] suggestions["fund_type"] = hold["fund_type"]
if suggestions["fund_strategy_name"] in propose_fund_id_strategy_name_list: if suggestions["fund_strategy_name"] in propose_fund_id_strategy_name_list:
suggestions["after_optimization"] = 0 suggestions["after_optimization"] = 0
if default > 0:
suggestions["after_optimization"] = hold["market_values"]
suggestions_result[hold["fund_strategy_name"]][suggestions["fund_name"]] = suggestions suggestions_result[hold["fund_strategy_name"]][suggestions["fund_name"]] = suggestions
for key, value in propose_info.items(): for key, value in propose_info.items():
...@@ -1163,6 +1165,8 @@ class PortfolioDiagnose(object): ...@@ -1163,6 +1165,8 @@ class PortfolioDiagnose(object):
suggestions["fund_type"] = value["fund_type"] suggestions["fund_type"] = value["fund_type"]
suggestions_result[key][suggestions["fund_name"]] = suggestions suggestions_result[key][suggestions["fund_name"]] = suggestions
else: else:
if default > 0:
continue
suggestions_result[key][value["fund_name"]]["after_optimization"] = value["asset"] suggestions_result[key][value["fund_name"]]["after_optimization"] = value["asset"]
for key, value in suggestions_result.items(): for key, value in suggestions_result.items():
...@@ -1231,17 +1235,20 @@ class PortfolioDiagnose(object): ...@@ -1231,17 +1235,20 @@ class PortfolioDiagnose(object):
"origin_combination": {"name": "原组合", "data": return_compare_df["cum_return_ratio"].values*100}, "origin_combination": {"name": "原组合", "data": return_compare_df["cum_return_ratio"].values*100},
"xlabels": return_compare_df["date"].values "xlabels": return_compare_df["date"].values
} }
if default > 0:
return_compare_result["new_combination"]["data"] = return_compare_result["origin_combination"]["data"]
# 指标对比 # 指标对比
old_indicator = {"group_name": "现有持仓组合", "return_ratio": round((old_return-1)*100, 2), "return_ratio_year": round(old_return_ratio_year*100,2), old_indicator = {"group_name": "现有持仓组合", "return_ratio": round((old_return-1)*100, 2), "return_ratio_year": round(old_return_ratio_year*100,2),
"volatility": round(old_volatility*100, 2), "max_drawdown": round(old_max_drawdown[0]*100, 2), "sharpe": round(old_sharpe, 2)} "volatility": round(old_volatility*100, 2), "max_drawdown": round(old_max_drawdown[0]*100, 2), "sharpe": round(old_sharpe, 2)}
new_indicator = {"group_name": "建议优化组合", "return_ratio": round(new_return_ratio*100, 2), "return_ratio_year": round(new_return_ratio_year*100, 2), new_indicator = {"group_name": "建议优化组合", "return_ratio": round(new_return_ratio*100, 2), "return_ratio_year": round(new_return_ratio_year*100, 2),
"volatility": round(new_volatility*100, 2), "max_drawdown": round(new_drawdown[0]*100, 2), "sharpe": round(new_sharpe, 2)} "volatility": round(new_volatility*100, 2), "max_drawdown": round(new_drawdown[0]*100, 2), "sharpe": round(new_sharpe, 2)}
if default > 0:
new_indicator = {"group_name": "建议优化组合", "return_ratio": round((old_return-1)*100, 2), "return_ratio_year": round(old_return_ratio_year*100, 2),
"volatility": round(old_volatility*100, 2), "max_drawdown": round(old_max_drawdown[0]*100, 2), "sharpe": round(old_sharpe, 2)}
index_indicator = {"group_name": "中证500", "return_ratio": round(index_return_ratio*100, 2), "return_ratio_year": round(index_return_ratio_year*100, 2), index_indicator = {"group_name": "中证500", "return_ratio": round(index_return_ratio*100, 2), "return_ratio_year": round(index_return_ratio_year*100, 2),
"volatility": round(index_volatility*100, 2), "max_drawdown": round(index_drawdown[0]*100, 2), "sharpe": round(index_sharpe, 2)} "volatility": round(index_volatility*100, 2), "max_drawdown": round(index_drawdown[0]*100, 2), "sharpe": round(index_sharpe, 2)}
indicator_compare = [new_indicator, old_indicator, index_indicator] indicator_compare = [new_indicator, old_indicator, index_indicator]
# 在保留{}的基础上,建议赎回{},并增配{}后,整体组合波动率大幅降低,最大回撤从{}降到不足{},年化收益率提升{}个点 # 在保留{}的基础上,建议赎回{},并增配{}后,整体组合波动率大幅降低,最大回撤从{}降到不足{},年化收益率提升{}个点
hold_fund = set(self.portfolio) - set(self.abandon_fund_score + self.abandon_fund_corr + self.no_data_fund) hold_fund = set(self.portfolio) - set(self.abandon_fund_score + self.abandon_fund_corr + self.no_data_fund)
hold_fund_name = [get_fund_name(x, self.portfolio_dict[x]).values[0][0] for x in hold_fund] hold_fund_name = [get_fund_name(x, self.portfolio_dict[x]).values[0][0] for x in hold_fund]
......
...@@ -176,7 +176,7 @@ class DataIntegrate: ...@@ -176,7 +176,7 @@ class DataIntegrate:
cur_group_portfolio_result["suggestions_result"], cur_group_portfolio_result["suggestions_result_asset"], \ cur_group_portfolio_result["suggestions_result"], cur_group_portfolio_result["suggestions_result_asset"], \
cur_group_portfolio_result["return_compare_data"], \ cur_group_portfolio_result["return_compare_data"], \
cur_group_portfolio_result["indicator_compare"], cur_group_portfolio_result["new_group_evaluation"] = \ cur_group_portfolio_result["indicator_compare"], cur_group_portfolio_result["new_group_evaluation"] = \
portfolio_diagnose.new_evaluation(folio, self.d, self.user_customer, self.user_customer.all_fund_type_dict) portfolio_diagnose.new_evaluation(folio, self.d, self.user_customer, self.user_customer.all_fund_type_dict, default=1)
cur_group_portfolio_result["return_compare_pic"] = draw_combination_chart(cur_group_portfolio_result["return_compare_data"]["xlabels"], cur_group_portfolio_result["return_compare_pic"] = draw_combination_chart(cur_group_portfolio_result["return_compare_data"]["xlabels"],
cur_group_portfolio_result["return_compare_data"]["new_combination"], cur_group_portfolio_result["return_compare_data"]["new_combination"],
...@@ -323,9 +323,9 @@ class DataIntegrate: ...@@ -323,9 +323,9 @@ class DataIntegrate:
template = env.get_template('/v2/monthReportV2.1.html') # 获取一个模板文件 template = env.get_template('/v2/monthReportV2.1.html') # 获取一个模板文件
monthReport_html = template.render(self.data).replace('None', 'none') # 渲染 monthReport_html = template.render(self.data).replace('None', 'none') # 渲染
# 保存 monthReport_html # 保存 monthReport_html
save_file = "app/pdf/monthReport.html" # save_file = "app/pdf/monthReport.html"
with open(save_file, 'w', encoding="utf-8") as f: # with open(save_file, 'w', encoding="utf-8") as f:
f.write(monthReport_html) # f.write(monthReport_html)
# save_file = "app/html/v2/monthReportV2.html" # save_file = "app/html/v2/monthReportV2.html"
# with open(save_file, 'w', encoding="utf-8") as f: # with open(save_file, 'w', encoding="utf-8") as f:
......
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