Commit a95fe87e authored by 赵杰's avatar 赵杰

旧指标对比剥离

parent 077b37a0
......@@ -756,12 +756,25 @@ class PortfolioDiagnose(object):
# 旧组合累积收益df
group_result_data = group_result[group_name]
hold_info = group_result_data["group_hoding_info"]
hold_info_df = pd.DataFrame(hold_info)
group_order_df = data_adaptor.user_customer_order_df[
data_adaptor.user_customer_order_df["folio_name"] == group_name]
group_order_start_date = pd.to_datetime(group_order_df["confirm_share_date"].min())
freq_max = group_order_df["freq"].max()
n_freq = freq_days(int(freq_max))
old_return_df = group_result_data["return_df"]
old_return_df["cum_return_ratio"] = old_return_df["cum_return_ratio"] - 1
# 原组合总市值, 区间收益, 年化收益, 波动率, 最大回撤, 夏普比率
total_asset = round(hold_info_df["market_values"].sum(), 2)
old_return = group_result_data["cumulative_return"]
old_return_ratio_year = group_result_data["return_ratio_year"]
old_volatility = group_result_data["volatility"]
old_max_drawdown = group_result_data["max_drawdown"]
old_sharpe = group_result_data["sharpe"]
# 指数收益
index_data = get_index_daily(self.index_id, self.start_date)
index_data = pd.merge(index_data, self.propose_portfolio, how='inner', left_index=True, right_index=True)
......@@ -771,6 +784,14 @@ class PortfolioDiagnose(object):
index_return = index_return[index_return.index >= group_order_start_date]
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_ratio = index_return["new_index_return"].values[-1]
index_return_ratio_year = annual_return(index_return["new_index_return"].values[-1],
index_return["new_index_return"], n_freq)
index_volatility = volatility(index_return["new_index_return"] + 1, n_freq)
index_drawdown = max_drawdown(index_return["new_index_return"] + 1)
index_sim = simple_return(index_return["new_index_return"]+1)
index_exc = excess_return(index_sim, BANK_RATE, n_freq)
index_sharpe = sharpe_ratio(index_exc, index_sim, n_freq)
# 收益对比数据
return_compare_df = pd.merge(index_return[["new_index_return"]], old_return_df[["cum_return_ratio"]],
......@@ -785,8 +806,19 @@ class PortfolioDiagnose(object):
"origin_combination": {"name": "原组合", "data": return_compare_df["cum_return_ratio"].values*100},
"xlabels": return_compare_df["date"].values
}
# 指标对比
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)}
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)}
old_indicator_compare = [old_indicator, index_indicator]
return ret, old_return_compare_result
return ret, old_return_compare_result, old_indicator_compare
def new_evaluation(self, group_name, group_result, data_adaptor):
try:
......@@ -892,7 +924,7 @@ class PortfolioDiagnose(object):
index_return_ratio_year = annual_return(index_return["new_index_return"].values[-1], index_return["new_index_return"], n_freq)
index_volatility = volatility(index_return["new_index_return"]+1, n_freq)
index_drawdown = max_drawdown(index_return["new_index_return"]+1)
index_sim = simple_return(propose_fund_return_limit_data["new_return"]+1)
index_sim = simple_return(index_return["new_index_return"]+1)
index_exc = excess_return(index_sim, BANK_RATE, n_freq)
index_sharpe = sharpe_ratio(index_exc, index_sim, n_freq)
......
......@@ -1363,20 +1363,20 @@
<tr>
<tr class="yellow">
<td>{{indicator_compare[1]["group_name"]}}</td>
<td>{{indicator_compare[1]["return_ratio"]}}</td>
<td>{{indicator_compare[1]["return_ratio_year"]}}</td>
<td>{{indicator_compare[1]["volatility"]}}</td>
<td>{{indicator_compare[1]["max_drawdown"]}}</td>
<td>{{indicator_compare[1]["sharpe"]}}</td>
<td>{{old_indicator_compare[0]["group_name"]}}</td>
<td>{{old_indicator_compare[0]["return_ratio"]}}</td>
<td>{{old_indicator_compare[0]["return_ratio_year"]}}</td>
<td>{{old_indicator_compare[0]["volatility"]}}</td>
<td>{{old_indicator_compare[0]["max_drawdown"]}}</td>
<td>{{old_indicator_compare[0]["sharpe"]}}</td>
</tr>
<tr >
<td>{{indicator_compare[2]["group_name"]}}</td>
<td>{{indicator_compare[2]["return_ratio"]}}</td>
<td>{{indicator_compare[2]["return_ratio_year"]}}</td>
<td>{{indicator_compare[2]["volatility"]}}</td>
<td>{{indicator_compare[2]["max_drawdown"]}}</td>
<td>{{indicator_compare[2]["sharpe"]}}</td>
<td>{{old_indicator_compare[1]["group_name"]}}</td>
<td>{{old_indicator_compare[1]["return_ratio"]}}</td>
<td>{{old_indicator_compare[1]["return_ratio_year"]}}</td>
<td>{{old_indicator_compare[1]["volatility"]}}</td>
<td>{{old_indicator_compare[1]["max_drawdown"]}}</td>
<td>{{old_indicator_compare[1]["sharpe"]}}</td>
</tr>
</table>
......
......@@ -83,7 +83,7 @@ class DataIntegrate:
def comments_on_position_portfolio(self):
"""旧持仓组合点评. 旧贡献分解数据"""
self.old_evaluation, self.old_return_compare_data = self.portfolio_diagnose.old_evaluation('default', self.d, self.user_customer)
self.old_evaluation, self.old_return_compare_data, self.old_indicator_compare = self.portfolio_diagnose.old_evaluation('default', self.d, self.user_customer)
def contribution_deco(self):
"""贡献分解."""
......@@ -244,6 +244,7 @@ class DataIntegrate:
'group_hoding_info': self.group_hoding_info,
'group_hoding_info_total': self.group_hoding_info_total,
'old_evaluation': self.old_evaluation,
'old_indicator_compare': self.old_indicator_compare,
'contribution_decomposition': self.contribution_decomposition,
'single_fund_data_list': self.single_fund_data_list,
'old_correlation': self.old_correlation,
......
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