Commit 92ca134f authored by 赵杰's avatar 赵杰

小数点后两位

parent 039488dd
......@@ -685,15 +685,15 @@ class PortfolioDiagnose(object):
# 整体表现 回撤能力
fund_rank_data = fund_rank[fund_rank["fund_id"].isin(self.portfolio)]
z_score = fund_rank_data["z_score"].mean()
drawdown_rank = fund_rank_data["max_drawdown_rank"].mean()
drawdown_rank = group_result[group_name]["max_drawdown"][0]
return_rank_df = fund_rank_data["annual_return_rank"]
z_score_level = np.select([z_score >= 80,
50 <= z_score < 80,
z_score < 50], [0, 1, 2]).item()
drawdown_level = np.select([drawdown_rank >= 0.8,
0.7 <= drawdown_rank < 0.8,
0.6 <= drawdown_rank < 0.7,
drawdown_rank < 0.6], [0, 1, 2, 3]).item()
drawdown_level = np.select([drawdown_rank <= 0.05,
0.05 <= drawdown_rank < 0.1,
0.1 <= drawdown_rank < 0.15,
drawdown_rank > 0.15], [0, 1, 2, 3]).item()
# 收益稳健
fund_rank_re = fund_rank_data[fund_rank_data["annual_return_rank"] > 0.8]
return_rank_evaluate = ""
......
......@@ -158,14 +158,14 @@ class UserCustomerResultAdaptor(UserCustomerDataAdaptor):
folio_report_data["group_nav_info"] = result_fund_nav_info
folio_report_data["group_hoding_info"] = result_fund_hoding_info
folio_report_data["group_hoding_info_total"] = \
{"total_cost": round(total_cost/10000.0, 2),
"cur_month_profit": round(cur_month_profit/10000.0, 2),
"cur_month_profit_ratio": round(cur_month_profit_ratio*100, 2),
"ending_assets": round(ending_assets/10000.0, 2),
{"total_cost": ".2f" % round(total_cost/10000.0, 2),
"cur_month_profit": ".2f" % round(cur_month_profit/10000.0, 2),
"cur_month_profit_ratio": ".2f" % round(cur_month_profit_ratio*100, 2),
"ending_assets": ".2f" % round(ending_assets/10000.0, 2),
"weight": 100,
"cumulative_profit": round(cumulative_profit/10000.0, 2),
"cumulative_return": round((cumulative_return-1)*100, 2),
"return_ratio_year": round(return_ratio_year*100, 2)}
"cumulative_profit": ".2f" % round(cumulative_profit/10000.0, 2),
"cumulative_return": ".2f" % round((cumulative_return-1)*100, 2),
"return_ratio_year": ".2f" % round(return_ratio_year*100, 2)}
# 对应指数数据
index_df = self.get_customer_index_nav_data()
......@@ -308,8 +308,8 @@ class UserCustomerResultAdaptor(UserCustomerDataAdaptor):
cur_month = int(d_index[5:])
cur_profit = round(d_row/10000.0, 2)
cur_net_amount = round(month_amount_sum.loc[d_index]/10000, 2)
month_return_data_dict[cur_year][cur_month]["profit"] = cur_profit
month_return_data_dict[cur_year][cur_month]["net_amount"] = cur_net_amount
month_return_data_dict[cur_year][cur_month]["profit"] = "%.2f"%cur_profit
month_return_data_dict[cur_year][cur_month]["net_amount"] = "%.2f"%cur_net_amount
# 组合月度回报表
report_data["month_return_data_dict"] = month_return_data_dict
......@@ -371,10 +371,10 @@ class UserCustomerResultAdaptor(UserCustomerDataAdaptor):
total_market_values = p_sum_profit + p_total_amount # 月末总市值
fund_hoding_info = {"fund_strategy_name": dict_substrategy[int(row["substrategy"])], "fund_name": row["fund_name"]}
fund_hoding_info["confirm_date"] = row["confirm_share_date"]
fund_hoding_info["hold_year"] = round((self.end_date - pd.to_datetime(row["confirm_share_date"])).days/365.0, 2) # 存续年数
fund_hoding_info["hold_year"] = "%.2f" % round((self.end_date - pd.to_datetime(row["confirm_share_date"])).days/365.0, 2) # 存续年数
fund_hoding_info["market_values"] = round((float(row["confirm_share"]) * (fund_basic_info["cur_cnav"] - confirm_cnav) + float(row["confirm_amount"]))/10000, 2)
fund_hoding_info["weight"] = round(fund_hoding_info["market_values"] / total_market_values * 10000.0 * 100, 2) # 月末占比
fund_hoding_info["cost"] = round(float(row["confirm_amount"])/10000, 2) # 投资本金
fund_hoding_info["weight"] = "%.2f" % round(float(fund_hoding_info["market_values"]) / total_market_values * 10000.0 * 100, 2) # 月末占比
fund_hoding_info["cost"] = "%.2f" % round(float(row["confirm_amount"])/10000, 2) # 投资本金
# 当月收益
last_month_cnav_serise = p_result_cnav_data[p_result_cnav_data.index<pd.to_datetime(self.month_start_date)][row["fund_id"]].dropna()
if len(last_month_cnav_serise) == 0:
......@@ -383,15 +383,15 @@ class UserCustomerResultAdaptor(UserCustomerDataAdaptor):
last_month_cnav = float(last_month_cnav_serise.values[-1])
fund_hoding_info["profit"] = round(float(row["confirm_share"]) * (fund_basic_info["cur_cnav"] - last_month_cnav)/10000, 2)
# 当月收益率
fund_hoding_info["month_return_ratio"] = round(fund_hoding_info["profit"] / fund_hoding_info["market_values"]*100, 2)
fund_hoding_info["month_return_ratio"] = "%.2f" % round(float(fund_hoding_info["profit"]) / float(fund_hoding_info["market_values"])*100, 2)
# 累积收益
fund_hoding_info["cum_profit"] = round(float(row["confirm_share"]) * (fund_basic_info["cur_cnav"] - confirm_cnav) / 10000, 2)
fund_hoding_info["cum_profit"] = "%.2f" % round(float(row["confirm_share"]) * (fund_basic_info["cur_cnav"] - confirm_cnav) / 10000, 2)
# 累积收益率
fund_hoding_info["cum_profit_ratio"] = round((fund_basic_info["cur_cnav"] - confirm_cnav)/confirm_cnav*100, 2)
fund_hoding_info["cum_profit_ratio"] = "%.2f" % round((fund_basic_info["cur_cnav"] - confirm_cnav)/confirm_cnav*100, 2)
# 累积年化收益率
cur_resample_df = resample_df[[row["fund_id"]]].dropna()
return_ratio_year = annual_return(fund_hoding_info["cum_profit_ratio"]/100.0, cur_resample_df, n_freq)
fund_hoding_info["return_ratio_year"] = round(float(return_ratio_year)*100, 2)
return_ratio_year = annual_return(float(fund_hoding_info["cum_profit_ratio"])/100.0, cur_resample_df, n_freq)
fund_hoding_info["return_ratio_year"] = "%.2f" % round(float(return_ratio_year)*100, 2)
group_fund_hoding_info.append(fund_hoding_info)
return group_fund_basic_info, group_fund_hoding_info
......
......@@ -1582,7 +1582,7 @@
<td>{{one.fund_name}}</td>
<td>{{one.confirm_date}}</td>
<td>{{one.hold_year}}</td>
<td>{{one.cost| round(precision=2)}}万</td>
<td>{{one.cost}}万</td>
<td>{{one.profit}}万</td>
<td>{{one.month_return_ratio}}%</td>
<td>{{one.market_values}}万</td>
......
......@@ -78,7 +78,7 @@ class DataIntegrate:
self.all_folio_result[group_name] = cur_group_portfolio_result
def get_portfolio_diagnose(self, portfolio, client_type=1, invest_amount=10000000):
portfolio_diagnose = PortfolioDiagnose(client_type=client_type, portfolio=portfolio, invest_amount=invest_amount,
portfolio_diagnose = PortfolioDiagnose(client_type=client_type, portfolio=portfolio, invest_amount=float(invest_amount),
start_date=self.user_customer.start_date)
portfolio_diagnose.optimize()
return portfolio_diagnose
......@@ -86,7 +86,7 @@ class DataIntegrate:
# 全部数据综述结果
def get_summarize(self):
"""投资总览."""
self.total_cost = round(self.df["total_cost"], 2) # 投资成本
self.total_cost = int(self.df["total_cost"]) # 投资成本
self.now_yield = round((self.df['cumulative_return']-1)*100, 2) # 成立以来累计收益率
self.now_annualised_return = round(self.df["return_ratio_year"] * 100, 2) # 年化收益率
self.index_yield = round((self.df["index_result"]["return_ratio"]-1)*100, 2) # 指数收益率
......@@ -203,17 +203,17 @@ class DataIntegrate:
def objectives_performance(self, group_result, cur_group_portfolio_result):
"""目标与业绩"""
cur_group_portfolio_result["totoal_rate_of_return"] = round((group_result['cumulative_return']-1)*100, 2) # 成立以来累计收益率
cur_group_portfolio_result["annualised_return"] = round(group_result["return_ratio_year"]*100, 2) # 年化收益率
cur_group_portfolio_result["volatility"] = round(group_result["volatility"]*100, 2)
cur_group_portfolio_result["max_withdrawal"] = round(group_result["max_drawdown"][0]*100, 2)
cur_group_portfolio_result["sharpe_ratio"] = round(group_result["sharpe"], 2)
cur_group_portfolio_result["cost_of_investment"] = round(group_result["total_cost"]/10000.0, 2) # 投资成本
cur_group_portfolio_result["index_section_return"] = round((group_result["index_result"]["return_ratio"]-1)*100, 2)
cur_group_portfolio_result["index_annualised_return"] = round(group_result["index_result"]["return_ratio_year"]*100, 2) # 年化收益率
cur_group_portfolio_result["index_volatility"] = round(group_result["index_result"]["volatility"]*100, 2)
cur_group_portfolio_result["index_max_withdrawal"] = round(group_result["index_result"]["max_drawdown"][0]*100, 2)
cur_group_portfolio_result["index_sharpe_ratio"] = round(group_result["index_result"]["sharpe"], 2)
cur_group_portfolio_result["totoal_rate_of_return"] = "%.2f" % round((group_result['cumulative_return']-1)*100, 2) # 成立以来累计收益率
cur_group_portfolio_result["annualised_return"] = "%.2f" % round(group_result["return_ratio_year"]*100, 2) # 年化收益率
cur_group_portfolio_result["volatility"] = "%.2f" % round(group_result["volatility"]*100, 2)
cur_group_portfolio_result["max_withdrawal"] = "%.2f" % round(group_result["max_drawdown"][0]*100, 2)
cur_group_portfolio_result["sharpe_ratio"] = "%.2f" % round(group_result["sharpe"], 2)
cur_group_portfolio_result["cost_of_investment"] = "%.2f" % round(group_result["total_cost"]/10000.0, 2) # 投资成本
cur_group_portfolio_result["index_section_return"] = "%.2f" % round((group_result["index_result"]["return_ratio"]-1)*100, 2)
cur_group_portfolio_result["index_annualised_return"] = "%.2f" % round(group_result["index_result"]["return_ratio_year"]*100, 2) # 年化收益率
cur_group_portfolio_result["index_volatility"] = "%.2f" % round(group_result["index_result"]["volatility"]*100, 2)
cur_group_portfolio_result["index_max_withdrawal"] = "%.2f" % round(group_result["index_result"]["max_drawdown"][0]*100, 2)
cur_group_portfolio_result["index_sharpe_ratio"] = "%.2f" % round(group_result["index_result"]["sharpe"], 2)
cur_group_portfolio_result["group_nav_info"] = group_result["group_nav_info"]
cur_group_portfolio_result["group_hoding_info"] = group_result["group_hoding_info"]
......
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