diff --git a/app/service/portfolio_diagnose.py b/app/service/portfolio_diagnose.py index 3862efc2f2a918502c169fd8a05195cb033dce8a..7ae644b87dd99c06c404da9056e37ab8b164dc6f 100644 --- a/app/service/portfolio_diagnose.py +++ b/app/service/portfolio_diagnose.py @@ -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 = "" diff --git a/app/service/result_service_v2.py b/app/service/result_service_v2.py index da787e4b6956ad9182d82d3f39eeebe2bb874a63..a92cdd8d56276e1bc399a9b5d7804e685d8d89a8 100644 --- a/app/service/result_service_v2.py +++ b/app/service/result_service_v2.py @@ -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 diff --git a/app/templates/v2/monthReportV2.1.html b/app/templates/v2/monthReportV2.1.html index f1bb86cea6649cbf7fc227c19e6fa786496d0f87..004dc0a2116c6fed9286a18eb8dbbd0507fc6cba 100644 --- a/app/templates/v2/monthReportV2.1.html +++ b/app/templates/v2/monthReportV2.1.html @@ -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> diff --git a/app/utils/jinjia2html_v2.py b/app/utils/jinjia2html_v2.py index a3382db4f37ab2373fe7422a53f5603562280a04..a8d063877f0a687bc0b8eb5b7fdba53ee872df67 100644 --- a/app/utils/jinjia2html_v2.py +++ b/app/utils/jinjia2html_v2.py @@ -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"]