Commit 7cca54ea authored by 赵杰's avatar 赵杰

调仓建议,指标对比

parent 1bc1d63c
...@@ -702,12 +702,14 @@ class PortfolioDiagnose(object): ...@@ -702,12 +702,14 @@ class PortfolioDiagnose(object):
suggestions["before_optimization"] = 0 suggestions["before_optimization"] = 0
suggestions["after_optimization"] = value["asset"] suggestions["after_optimization"] = value["asset"]
suggestions_result[key][suggestions["fund_name"]] = suggestions suggestions_result[key][suggestions["fund_name"]] = suggestions
for key, value in suggestions_result.items():
suggestions_result[key] = list(value.values())
suggestions_result_asset = {"before": total_asset, "after": total_asset} suggestions_result_asset = {"before": total_asset, "after": total_asset}
# 旧组合累积收益 # 旧组合累积收益df
old_return_df = group_result_data["return_df"] old_return_df = group_result_data["return_df"]
old_return_df["cum_return_ratio"] = old_return_df["cum_return_ratio"] - 1 old_return_df["cum_return_ratio"] = old_return_df["cum_return_ratio"] - 1
# 新组合累积收益 # 新组合累积收益df
propose_fund_return_limit_data = propose_fund_return[propose_fund_return.index >= group_order_start_date] propose_fund_return_limit_data = propose_fund_return[propose_fund_return.index >= group_order_start_date]
start_return = propose_fund_return_limit_data['return'].values[0] start_return = propose_fund_return_limit_data['return'].values[0]
propose_fund_return_limit_data["new_return"] = (propose_fund_return_limit_data["return"] - start_return)/(1+start_return) propose_fund_return_limit_data["new_return"] = (propose_fund_return_limit_data["return"] - start_return)/(1+start_return)
...@@ -716,13 +718,15 @@ class PortfolioDiagnose(object): ...@@ -716,13 +718,15 @@ class PortfolioDiagnose(object):
start_index_return = index_return[" close"].values[0] start_index_return = index_return[" close"].values[0]
index_return["new_index_return"] = (index_return[" close"] - start_index_return) / (1 + start_index_return) index_return["new_index_return"] = (index_return[" close"] - start_index_return) / (1 + start_index_return)
# 新组合累积收益
new_return_ratio = propose_fund_return_limit_data["new_return"].values[-1]
# 新组合区间年化收益率 # 新组合区间年化收益率
freq_max = group_order_df["freq"].max() freq_max = group_order_df["freq"].max()
n_freq = freq_days(int(freq_max)) n_freq = freq_days(int(freq_max))
new_return_ratio_year = annual_return(propose_fund_return_limit_data["new_return"].values[-1], propose_fund_return_limit_data, n_freq) new_return_ratio_year = annual_return(propose_fund_return_limit_data["new_return"].values[-1], propose_fund_return_limit_data, n_freq)
# 新组合波动率 # 新组合波动率
new_volatility_ = volatility(propose_fund_return_limit_data["new_return"]+1, n_freq) new_volatility = volatility(propose_fund_return_limit_data["new_return"]+1, n_freq)
# 新组合最大回撤 # 新组合最大回撤
new_drawdown = max_drawdown(propose_fund_return_limit_data["new_return"]+1) new_drawdown = max_drawdown(propose_fund_return_limit_data["new_return"]+1)
...@@ -732,7 +736,13 @@ class PortfolioDiagnose(object): ...@@ -732,7 +736,13 @@ class PortfolioDiagnose(object):
exc = excess_return(sim, BANK_RATE, n_freq) exc = excess_return(sim, BANK_RATE, n_freq)
new_sharpe = sharpe_ratio(exc, sim, n_freq) new_sharpe = sharpe_ratio(exc, sim, n_freq)
propose_fund_id_list_name = [] # 基金名称,策略分级 # 指标对比
odl_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)}
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)}
indicator_compare = [new_indicator, odl_indicator]
sentence = "在保留{}的基础上,建议赎回{},并增配{}后,整体组合波动率大幅降低,最大回撤从{}降到不足{},年化收益率提升{}个点" sentence = "在保留{}的基础上,建议赎回{},并增配{}后,整体组合波动率大幅降低,最大回撤从{}降到不足{},年化收益率提升{}个点"
hold_fund = set(self.portfolio) - set(self.abandon_fund_score + self.abandon_fund_corr) hold_fund = set(self.portfolio) - set(self.abandon_fund_score + self.abandon_fund_corr)
...@@ -750,7 +760,7 @@ class PortfolioDiagnose(object): ...@@ -750,7 +760,7 @@ class PortfolioDiagnose(object):
sentence.join("整体组合波动率大幅降低,") sentence.join("整体组合波动率大幅降低,")
if new_return_ratio_year > old_return_ratio_year: if new_return_ratio_year > old_return_ratio_year:
sentence.join("年化收益率提升{}个点。".format(round(new_return_ratio_year-old_return_ratio_year, 1))) sentence.join("年化收益率提升{}个点。".format(round(new_return_ratio_year-old_return_ratio_year, 1)))
return suggestions_result, suggestions_result_asset, sentence return suggestions_result, suggestions_result_asset, indicator_compare, sentence
def single_evaluation(self, fund_id): def single_evaluation(self, fund_id):
""" """
......
...@@ -2561,26 +2561,26 @@ ...@@ -2561,26 +2561,26 @@
<th>优化前(万元)</th> <th>优化前(万元)</th>
<th>优化后(万元)</th> <th>优化后(万元)</th>
</tr> </tr>
<!-- <dl>-->
{% for key, value in suggestions_result.items() %}
{% for i in range(value|length) %}
<tr> <tr>
<td rowspan="3">宏观策略</td> {% if i == 0%}
<td>半夏宏观对冲</td> <td rowspan={{value|length }}>{{key}}</td>
<td class="font_red">200</td> {% endif %}
<td class="font_green">1000</td> <td> {{value[i]["fund_name"]}}</td>
</tr> <td class="font_red">{{value[i]["before_optimization"]}}</td>
<tr> <td class="font_green">{{value[i]["after_optimization"]}}</td>
<td>半夏宏观对冲</td>
<td class="font_red">200</td>
<td class="font_green">1000</td>
</tr>
<tr>
<td>半夏宏观对冲</td>
<td class="font_red">200</td>
<td class="font_green">1000</td>
</tr> </tr>
{% endfor %}
{% endfor %}
<tr> <tr>
<td colspan="2" class="back_gray font_bold">总市值(万元)</td> <td colspan="2" class="back_gray font_bold">总市值(万元)</td>
<td class="font_bold">1200</td> <td class="font_bold">{{suggestions_result_asset["before"]}}</td>
<td class="font_bold">1000</td> <td class="font_bold">{{suggestions_result_asset["after"]}}</td>
</tr> </tr>
</table> </table>
...@@ -2721,30 +2721,23 @@ ...@@ -2721,30 +2721,23 @@
<th>最大回撤(%)</th> <th>最大回撤(%)</th>
<th>夏普比率</th> <th>夏普比率</th>
</tr> </tr>
{%for i in range(indicator_compare|length)%}
{%if i<(indicator_compare|length)-1%}
{%if i%2==0 %}
<tr class="back_yellow1"> <tr class="back_yellow1">
<td>建议优化组合</td> {%endif%}
<td>5.75</td> {%if i%2==1 %}
<td>0.40</td>
<td>2.29</td>
<td>2.15</td>
<td>3.05</td>
</tr>
<tr class="back_yellow2"> <tr class="back_yellow2">
<td>建议优化组合</td> {%endif%}
<td>5.75</td> {%endif%}
<td>0.40</td> <td>{{indicator_compare[i]["group_name"]}}</td>
<td>2.29</td> <td>{{indicator_compare[i]["return_ratio"]}}</td>
<td>2.15</td> <td>{{indicator_compare[i]["return_ratio_year"]}}</td>
<td>3.05</td> <td>{{indicator_compare[i]["volatility"]}}</td>
</tr> <td>{{indicator_compare[i]["max_drawdown"]}}</td>
<tr> <td>{{indicator_compare[i]["sharpe"]}}</td>
<td>现有持仓组合</td>
<td>5.75</td>
<td>0.40</td>
<td>2.29</td>
<td>2.15</td>
<td>3.05</td>
</tr> </tr>
{%endfor%}
</table> </table>
<div class="aim_foot"> <div class="aim_foot">
...@@ -2761,7 +2754,7 @@ ...@@ -2761,7 +2754,7 @@
<div class="all_item"> <div class="all_item">
<div class="all_dot"></div> <div class="all_dot"></div>
<div class="all_text"> <div class="all_text">
在保留综合性基金(富国创新,鹏华匠心,汇添富中盘)并增配申毅套利基金后,整体组合的波动率大幅降低,最大回撤从26%降到不足4%,年化收益提升1个点。 {{new_group_evaluation}}
</div> </div>
</div> </div>
</div> </div>
......
...@@ -76,7 +76,8 @@ class DataIntegrate: ...@@ -76,7 +76,8 @@ class DataIntegrate:
# 调仓建议 # 调仓建议
def get_transfer_suggestions(self): def get_transfer_suggestions(self):
self.suggestions_result, self.suggestions_result_asset = portfolio_diagnose.new_evaluation("default", self.d, self.user_customer) self.suggestions_result, self.suggestions_result_asset, \
self.indicator_compare, self.new_group_evaluation = portfolio_diagnose.new_evaluation("default", self.d, self.user_customer)
# 收益比较 # 收益比较
...@@ -161,7 +162,10 @@ class DataIntegrate: ...@@ -161,7 +162,10 @@ class DataIntegrate:
'old_correlation': self.old_correlation, 'old_correlation': self.old_correlation,
'propose_fund_data_list': self.propose_fund_data_list, 'propose_fund_data_list': self.propose_fund_data_list,
'suggestions_result': self.suggestions_result, 'suggestions_result': self.suggestions_result,
'suggestions_result_asset': self.suggestions_result_asset 'suggestions_result_asset': self.suggestions_result_asset,
'indicator_compare': self.indicator_compare,
'new_group_evaluation': self.new_group_evaluation
} }
# 开始渲染html模板 # 开始渲染html模板
env = Environment(loader=PackageLoader('app', 'templates')) # 创建一个包加载器对象 env = Environment(loader=PackageLoader('app', 'templates')) # 创建一个包加载器对象
......
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