Commit fba17062 authored by 赵杰's avatar 赵杰

优化建议支持公募

parent 7adeb860
...@@ -14,6 +14,7 @@ import datetime ...@@ -14,6 +14,7 @@ import datetime
import math import math
from decimal import Decimal from decimal import Decimal
from app.api.engine import tamp_user_engine, tamp_product_engine, TAMP_SQL, tamp_fund_engine, tamp_diagnose_app_engine from app.api.engine import tamp_user_engine, tamp_product_engine, TAMP_SQL, tamp_fund_engine, tamp_diagnose_app_engine
from app.service.portfolio_diagnose import get_fund_substrategy
# from app.model.tamp_user_models import CustomerOrder, CustomerInfo # from app.model.tamp_user_models import CustomerOrder, CustomerInfo
...@@ -135,8 +136,8 @@ class UserCustomerDataAdaptor: ...@@ -135,8 +136,8 @@ class UserCustomerDataAdaptor:
if len(fund_df_0) > 0: if len(fund_df_0) > 0:
product_df = product_df.append(fund_df_0) product_df = product_df.append(fund_df_0)
product_df = product_df.drop_duplicates("fund_id") product_df = product_df.drop_duplicates("fund_id")
user_customer_order_df = order_df.set_index('fund_id').join(product_df.set_index('fund_id')).reset_index() user_customer_order_df = order_df.set_index('fund_id').join(product_df.set_index('fund_id')).reset_index()
user_customer_order_df["substrategy"] = user_customer_order_df.apply(lambda x: get_fund_substrategy(x["fund_id"], x["type"]), axis=1)
user_customer_order_df["confirm_share_date"] = user_customer_order_df["confirm_share_date"].apply(lambda x: pd.to_datetime(x.date())) user_customer_order_df["confirm_share_date"] = user_customer_order_df["confirm_share_date"].apply(lambda x: pd.to_datetime(x.date()))
self.customer_real_name = user_customer_order_df["customer_name"].values[0] self.customer_real_name = user_customer_order_df["customer_name"].values[0]
self.ifa_real_name = user_customer_order_df["username"].values[0] self.ifa_real_name = user_customer_order_df["username"].values[0]
......
...@@ -445,7 +445,7 @@ def get_fund_substrategy(fund, fund_type=1): ...@@ -445,7 +445,7 @@ def get_fund_substrategy(fund, fund_type=1):
if fund_type == 0: if fund_type == 0:
with TAMP_SQL(tamp_fund_engine) as tamp_fund: with TAMP_SQL(tamp_fund_engine) as tamp_fund:
tamp_fund_session = tamp_fund.session tamp_fund_session = tamp_fund.session
sql = "SELECT fund_short_name FROM tx_fund_info WHERE `id`='{}'".format(fund) sql = "SELECT substrategy FROM tx_fund_info WHERE `id`='{}'".format(fund)
# df = pd.read_sql(sql, con) # df = pd.read_sql(sql, con)
cur = tamp_fund_session.execute(sql) cur = tamp_fund_session.execute(sql)
data = cur.fetchall() data = cur.fetchall()
...@@ -454,7 +454,7 @@ def get_fund_substrategy(fund, fund_type=1): ...@@ -454,7 +454,7 @@ def get_fund_substrategy(fund, fund_type=1):
elif fund_type == 1 or fund_type == 2: elif fund_type == 1 or fund_type == 2:
with TAMP_SQL(tamp_fund_engine) as tamp_fund: with TAMP_SQL(tamp_fund_engine) as tamp_fund:
tamp_fund_session = tamp_fund.session tamp_fund_session = tamp_fund.session
sql = "SELECT fund_short_name FROM fund_info WHERE id='{}'".format(fund) sql = "SELECT substrategy FROM fund_info WHERE id='{}'".format(fund)
# df = pd.read_sql(sql, con) # df = pd.read_sql(sql, con)
cur = tamp_fund_session.execute(sql) cur = tamp_fund_session.execute(sql)
data = cur.fetchall() data = cur.fetchall()
...@@ -462,7 +462,7 @@ def get_fund_substrategy(fund, fund_type=1): ...@@ -462,7 +462,7 @@ def get_fund_substrategy(fund, fund_type=1):
if len(df) == 0: if len(df) == 0:
with TAMP_SQL(tamp_product_engine) as tamp_product: with TAMP_SQL(tamp_product_engine) as tamp_product:
tamp_product_session = tamp_product.session tamp_product_session = tamp_product.session
sql = "SELECT fund_short_name FROM fund_info WHERE id='{}'".format(fund) sql = "SELECT substrategy FROM fund_info WHERE id='{}'".format(fund)
# df = pd.read_sql(sql, con) # df = pd.read_sql(sql, con)
cur = tamp_product_session.execute(sql) cur = tamp_product_session.execute(sql)
data = cur.fetchall() data = cur.fetchall()
...@@ -471,7 +471,7 @@ def get_fund_substrategy(fund, fund_type=1): ...@@ -471,7 +471,7 @@ def get_fund_substrategy(fund, fund_type=1):
else: else:
with TAMP_SQL(tamp_fund_engine) as tamp_fund: with TAMP_SQL(tamp_fund_engine) as tamp_fund:
tamp_fund_session = tamp_fund.session tamp_fund_session = tamp_fund.session
sql = "SELECT fund_name FROM ifa_imported_fund_info WHERE id='{}'".format(fund) sql = "SELECT substrategy FROM ifa_imported_fund_info WHERE id='{}'".format(fund)
# df = pd.read_sql(sql, con) # df = pd.read_sql(sql, con)
cur = tamp_fund_session.execute(sql) cur = tamp_fund_session.execute(sql)
data = cur.fetchall() data = cur.fetchall()
...@@ -1057,7 +1057,7 @@ class PortfolioDiagnose(object): ...@@ -1057,7 +1057,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_type_dict): def new_evaluation(self, group_name, group_result, data_adaptor, fund_tye_dict=None):
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"]
...@@ -1109,14 +1109,15 @@ class PortfolioDiagnose(object): ...@@ -1109,14 +1109,15 @@ class PortfolioDiagnose(object):
propose_fund_df[propose_fund_df["fund_id"] == fund_id]["substrategy"].values[0]) propose_fund_df[propose_fund_df["fund_id"] == fund_id]["substrategy"].values[0])
for for
fund_id in propose_fund_id_list] fund_id in propose_fund_id_list]
propose_fund_asset = [round(self.new_weights[i] * total_asset, 2) for i in range(len(propose_fund_id_name_list))]
else: else:
propose_fund_id_name_list = [get_fund_name(fund_id, fund_tye_dict[fund_id]).values[0][0] for fund_id in propose_fund_id_name_list = [get_fund_name(fund_id, fund_tye_dict[fund_id]).values[0][0] for fund_id in
propose_fund_id_list] propose_fund_id_list]
propose_fund_id_strategy_name_list = [ propose_fund_id_strategy_name_list = [
get_substrategy_name(get_fund_substrategy(fund_id, fund_tye_dict[fund_id])) for fund_id in get_substrategy_name(get_fund_substrategy(fund_id, fund_tye_dict[fund_id])) for fund_id in
propose_fund_id_list] propose_fund_id_list]
propose_fund_asset = [round(portfolio_diagnose.new_weights[i] * total_asset, 2) for i in propose_fund_asset = [round(self.new_weights[i] * total_asset, 2) for i in range(len(propose_fund_id_name_list))]
range(len(propose_fund_id_name_list))]
propose_info = {propose_fund_id_strategy_name_list[i]: propose_info = {propose_fund_id_strategy_name_list[i]:
...@@ -1235,7 +1236,7 @@ class PortfolioDiagnose(object): ...@@ -1235,7 +1236,7 @@ class PortfolioDiagnose(object):
abandon_fund = (self.abandon_fund_score + self.abandon_fund_corr) abandon_fund = (self.abandon_fund_score + self.abandon_fund_corr)
abandon_fund_name = [get_fund_name(x, self.portfolio_dict[x]).values[0][0] for x in abandon_fund] abandon_fund_name = [get_fund_name(x, self.portfolio_dict[x]).values[0][0] for x in abandon_fund]
proposal_fund = self.proposal_fund proposal_fund = self.proposal_fund
proposal_fund_name = [get_fund_name(x).values[0][0] for x in proposal_fund] proposal_fund_name = [get_fund_name(x, fund_tye_dict[x]).values[0][0] for x in proposal_fund]
sentence = [] sentence = []
if len(hold_fund) > 0: if len(hold_fund) > 0:
......
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