Commit 4bad915b authored by 赵杰's avatar 赵杰

核减修复

parent 03fa8113
...@@ -34,7 +34,7 @@ class UserCustomerDataAdaptor: ...@@ -34,7 +34,7 @@ class UserCustomerDataAdaptor:
all_fund_distribution = {} all_fund_distribution = {}
all_fund_performance = {} all_fund_performance = {}
def __init__(self, user_id, customer_id, end_date=str(datetime.datetime.now().date()), index_id="IN0000007M"): def __init__(self, user_id, customer_id, end_date=str(datetime.datetime.now()), index_id="IN0000007M"):
self.user_id = user_id self.user_id = user_id
self.customer_id = customer_id self.customer_id = customer_id
self.compare_index_id = index_id self.compare_index_id = index_id
...@@ -42,7 +42,7 @@ class UserCustomerDataAdaptor: ...@@ -42,7 +42,7 @@ class UserCustomerDataAdaptor:
p_end_date = pd.to_datetime(end_date).date() p_end_date = pd.to_datetime(end_date).date()
# p_end_date = datetime.date(year=p_end_date.year, month=p_end_date.month, day=1) - datetime.timedelta(days=1) # p_end_date = datetime.date(year=p_end_date.year, month=p_end_date.month, day=1) - datetime.timedelta(days=1)
self.end_date = pd.to_datetime(str(p_end_date)) self.end_date = pd.to_datetime(str(p_end_date))
# self.end_date = pd.to_datetime("2020-12-25") # self.end_date = pd.to_datetime("2021-01-29")
p_start_date = datetime.date(year=p_end_date.year, month=p_end_date.month, day=1) p_start_date = datetime.date(year=p_end_date.year, month=p_end_date.month, day=1)
self.month_start_date = p_start_date self.month_start_date = p_start_date
# self.month_start_date = pd.to_datetime("2020-12-01") # self.month_start_date = pd.to_datetime("2020-12-01")
...@@ -162,7 +162,7 @@ class UserCustomerDataAdaptor: ...@@ -162,7 +162,7 @@ class UserCustomerDataAdaptor:
user_customer_order_df = pd.concat([inter_order_df, outside_order_df]) user_customer_order_df = pd.concat([inter_order_df, outside_order_df])
user_customer_order_df = user_customer_order_df[(user_customer_order_df["order_type"] <= 4)] user_customer_order_df = user_customer_order_df[((user_customer_order_df["order_type"] == 1)|(user_customer_order_df["order_type"] == 4))&(user_customer_order_df["confirm_share"] > 0)]
user_customer_order_df.index = pd.Series(range(len(user_customer_order_df))) user_customer_order_df.index = pd.Series(range(len(user_customer_order_df)))
self.start_date = user_customer_order_df["confirm_share_date"].min() self.start_date = user_customer_order_df["confirm_share_date"].min()
return user_customer_order_df return user_customer_order_df
...@@ -185,7 +185,7 @@ class UserCustomerDataAdaptor: ...@@ -185,7 +185,7 @@ class UserCustomerDataAdaptor:
break break
if _row["order_type"] == 1 and _row["fund_id"] == d_fund_id and _row["nav"] > d_nav: if _row["order_type"] == 1 and _row["fund_id"] == d_fund_id and _row["nav"] > d_nav:
coefficient = _row["nav"] / d_nav coefficient = _row["nav"] / d_nav
fund_order.loc[_index, "coefficient"] = coefficient fund_order.loc[_index, "coefficient"] = coefficient * _row["coefficient"]
fund_order.loc[_index, "divident_share"] = _row["confirm_share"] * coefficient fund_order.loc[_index, "divident_share"] = _row["confirm_share"] * coefficient
return fund_order return fund_order
...@@ -201,13 +201,15 @@ class UserCustomerDataAdaptor: ...@@ -201,13 +201,15 @@ class UserCustomerDataAdaptor:
for index_ori, row_ori in inter_order_df.iterrows(): for index_ori, row_ori in inter_order_df.iterrows():
if index_ori >= index: if index_ori >= index:
break break
if row["fund_id"] == row_ori["fund_id"] and row_ori["order_type"] == 1: if row["fund_id"] == row_ori["fund_id"] and (row_ori["order_type"] == 1 or row_ori["order_type"] == 4):
ori_share = row_ori["divident_share"] ori_share = row_ori["original_confirm_share"]
if need_less_share >= ori_share: div_share = row_ori["divident_share"]
if need_less_share >= div_share:
need_less_share -= ori_share need_less_share -= ori_share
inter_order_df.loc[index_ori, "divident_share"] = 0 inter_order_df.loc[index_ori, "divident_share"] = 0
else: else:
inter_order_df.loc[index_ori, "divident_share"] = row_ori["divident_share"] - need_less_share stay_share = row_ori["divident_share"] - need_less_share
inter_order_df.loc[index_ori, "divident_share"] = stay_share if stay_share > 0.01 else 0
need_less_share = 0 need_less_share = 0
if need_less_share <= 0: if need_less_share <= 0:
break break
...@@ -299,7 +301,7 @@ class UserCustomerDataAdaptor: ...@@ -299,7 +301,7 @@ class UserCustomerDataAdaptor:
elif fund_type == 3: elif fund_type == 3:
per_sql = """select distinct `price_date`, `ret_1w`, `ret_1m`, `ret_6m`, `ret_1y`, `ret_ytd`, `ret_incep` from `ifa_imported_fund_count` where `fund_id`='{}' order by `price_date` ASC""".format( per_sql = """select distinct `price_date`, `ret_1w`, `ret_1m`, `ret_6m`, `ret_1y`, `ret_ytd`, `ret_incep` from `ifa_imported_fund_count` where `fund_id`='{}' order by `price_date` ASC""".format(
cur_fund_id) cur_fund_id)
cur = tamp_product_session.execute(per_sql) cur = tamp_fund_session.execute(per_sql)
else: else:
cur = tamp_product_session.execute(per_sql) cur = tamp_product_session.execute(per_sql)
data = cur.fetchall() data = cur.fetchall()
...@@ -456,9 +458,9 @@ class UserCustomerDataAdaptor: ...@@ -456,9 +458,9 @@ class UserCustomerDataAdaptor:
# buy # buy
if row['order_type'] == 1: if row['order_type'] == 1:
cur_fund_share = actual_share_dict.get(cur_fund_id, 0) cur_fund_share = actual_share_dict.get(cur_fund_id, 0)
cur_fund_share += row["reduce_share"] / row["coefficient"] cur_fund_share += row["original_confirm_share"] - (row["original_confirm_share"] * row["coefficient"] - row["divident_share"])
nav_df.loc[confirm_share_date:, cur_fund_id + "_amount"] += row["reduce_share"] * row["nav"] nav_df.loc[confirm_share_date:, cur_fund_id + "_amount"] += row["reduce_share"] * row["nav"]
nav_df.loc[confirm_share_date:, cur_fund_id + "_share"] = cur_fund_share # nav_df.loc[confirm_share_date:, cur_fund_id + "_share"] = cur_fund_share
nav_df.loc[confirm_share_date:, cur_fund_id + "_reduce_share"] += row["reduce_share"] nav_df.loc[confirm_share_date:, cur_fund_id + "_reduce_share"] += row["reduce_share"]
actual_share_dict[cur_fund_id] = cur_fund_share actual_share_dict[cur_fund_id] = cur_fund_share
...@@ -466,7 +468,7 @@ class UserCustomerDataAdaptor: ...@@ -466,7 +468,7 @@ class UserCustomerDataAdaptor:
cur_fund_share = actual_share_dict.get(cur_fund_id, 0) cur_fund_share = actual_share_dict.get(cur_fund_id, 0)
# cur_fund_share += row["reduce_share"] # cur_fund_share += row["reduce_share"]
# nav_df.loc[confirm_share_date:, cur_fund_id + "_amount"] = cur_fund_share * row["nav"] # nav_df.loc[confirm_share_date:, cur_fund_id + "_amount"] = cur_fund_share * row["nav"]
# nav_df.loc[confirm_share_date:, cur_fund_id + "_share"] = cur_fund_share nav_df.loc[confirm_share_date:, cur_fund_id + "_share"] = cur_fund_share + row["reduce_share"]
nav_df.loc[confirm_share_date:, cur_fund_id + "_reduce_share"] = cur_fund_share + row["reduce_share"] nav_df.loc[confirm_share_date:, cur_fund_id + "_reduce_share"] = cur_fund_share + row["reduce_share"]
# actual_share_dict[cur_fund_id] = cur_fund_share # actual_share_dict[cur_fund_id] = cur_fund_share
...@@ -476,6 +478,8 @@ class UserCustomerDataAdaptor: ...@@ -476,6 +478,8 @@ class UserCustomerDataAdaptor:
cnav_df[p_fund_id_ + "_cum_earn"] = cnav_df[p_fund_id_ + "_earn"].cumsum().fillna(0) cnav_df[p_fund_id_ + "_cum_earn"] = cnav_df[p_fund_id_ + "_earn"].cumsum().fillna(0)
cnav_df[p_fund_id_ + "_net_amount"] = cnav_df[p_fund_id_ + "_cum_earn"].apply(lambda x: Decimal(x)) + \ cnav_df[p_fund_id_ + "_net_amount"] = cnav_df[p_fund_id_ + "_cum_earn"].apply(lambda x: Decimal(x)) + \
cnav_df[p_fund_id_ + "_amount"] cnav_df[p_fund_id_ + "_amount"]
# 内部订单
for p_fund_id_ in p_inter_order_df["fund_id"].unique(): for p_fund_id_ in p_inter_order_df["fund_id"].unique():
nav_df[p_fund_id_ + "_net_amount"] = (nav_df[p_fund_id_] * nav_df[p_fund_id_ + "_reduce_share"]).apply( nav_df[p_fund_id_ + "_net_amount"] = (nav_df[p_fund_id_] * nav_df[p_fund_id_ + "_reduce_share"]).apply(
lambda x: float(x)).fillna(0) lambda x: float(x)).fillna(0)
...@@ -488,6 +492,7 @@ class UserCustomerDataAdaptor: ...@@ -488,6 +492,7 @@ class UserCustomerDataAdaptor:
nav_df[p_fund_id_ + "_net_amount"] = nav_df[p_fund_id_ + "_net_amount"].apply(lambda x: Decimal(x)) nav_df[p_fund_id_ + "_net_amount"] = nav_df[p_fund_id_ + "_net_amount"].apply(lambda x: Decimal(x))
nav_df[p_fund_id_ + "_profit_ratio"] = nav_df[p_fund_id_ + "_profit_ratio"].apply( nav_df[p_fund_id_ + "_profit_ratio"] = nav_df[p_fund_id_ + "_profit_ratio"].apply(
lambda x: Decimal(0) if math.isnan(x) else x) lambda x: Decimal(0) if math.isnan(x) else x)
nav_df[p_fund_id_ + "_share"] = nav_df[p_fund_id_ + "_reduce_share"]
finall_cnav_df = cnav_df.copy() finall_cnav_df = cnav_df.copy()
all_nav_df = p_nav_df[p_nav_df.index >= start_date].copy().dropna(axis=0, how="all").fillna(method='ffill') all_nav_df = p_nav_df[p_nav_df.index >= start_date].copy().dropna(axis=0, how="all").fillna(method='ffill')
...@@ -617,7 +622,7 @@ class UserCustomerDataAdaptor: ...@@ -617,7 +622,7 @@ class UserCustomerDataAdaptor:
# buy # buy
if row['order_type'] == 1: if row['order_type'] == 1:
cur_fund_share = actual_share_dict.get(cur_fund_id, 0) cur_fund_share = actual_share_dict.get(cur_fund_id, 0)
cur_fund_share += row["reduce_share"] / row["coefficient"] cur_fund_share += row["original_confirm_share"] - (row["original_confirm_share"] * row["coefficient"] - row["divident_share"])
nav_df.loc[confirm_share_date:, cur_fund_id + "_amount"] += row["reduce_share"] * row["nav"] nav_df.loc[confirm_share_date:, cur_fund_id + "_amount"] += row["reduce_share"] * row["nav"]
nav_df.loc[confirm_share_date:, cur_fund_id + "_share"] = cur_fund_share nav_df.loc[confirm_share_date:, cur_fund_id + "_share"] = cur_fund_share
nav_df.loc[confirm_share_date:, cur_fund_id + "_reduce_share"] += row["reduce_share"] nav_df.loc[confirm_share_date:, cur_fund_id + "_reduce_share"] += row["reduce_share"]
...@@ -627,7 +632,7 @@ class UserCustomerDataAdaptor: ...@@ -627,7 +632,7 @@ class UserCustomerDataAdaptor:
cur_fund_share = actual_share_dict.get(cur_fund_id, 0) cur_fund_share = actual_share_dict.get(cur_fund_id, 0)
# cur_fund_share += row["reduce_share"] # cur_fund_share += row["reduce_share"]
# nav_df.loc[confirm_share_date:, cur_fund_id + "_amount"] = cur_fund_share * row["nav"] # nav_df.loc[confirm_share_date:, cur_fund_id + "_amount"] = cur_fund_share * row["nav"]
# nav_df.loc[confirm_share_date:, cur_fund_id + "_share"] = cur_fund_share nav_df.loc[confirm_share_date:, cur_fund_id + "_share"] = cur_fund_share + row["reduce_share"]
nav_df.loc[confirm_share_date:, cur_fund_id + "_reduce_share"] = cur_fund_share + row["reduce_share"] nav_df.loc[confirm_share_date:, cur_fund_id + "_reduce_share"] = cur_fund_share + row["reduce_share"]
# actual_share_dict[cur_fund_id] = cur_fund_share # actual_share_dict[cur_fund_id] = cur_fund_share
......
This diff is collapsed.
...@@ -31,7 +31,7 @@ def get_tamp_nav(fund, start_date, rollback=False, invest_type=2): ...@@ -31,7 +31,7 @@ def get_tamp_nav(fund, start_date, rollback=False, invest_type=2):
# # df = pd.read_sql(sql, con).dropna(how='any') # # df = pd.read_sql(sql, con).dropna(how='any')
# cur = tamp_product_session.execute(sql) # cur = tamp_product_session.execute(sql)
if invest_type == 0: if invest_type == 0:
sql = """select distinct `id`, `end_date`, `accum_nav` from `public_fund_nav` where `id`='{}' order by `end_date` ASC""".format( sql = """select distinct `fund_id`, `price_date`, `cumulative_nav` from `tx_fund_nav` where `fund_id`='{}' and `delete_tag`=0 order by `price_date` ASC""".format(
fund) fund)
cur = tamp_fund_session.execute(sql) cur = tamp_fund_session.execute(sql)
elif invest_type == 1: elif invest_type == 1:
...@@ -42,6 +42,10 @@ def get_tamp_nav(fund, start_date, rollback=False, invest_type=2): ...@@ -42,6 +42,10 @@ def get_tamp_nav(fund, start_date, rollback=False, invest_type=2):
sql = """select distinct `fund_id`,`price_date`,`cumulative_nav` from `fund_nav` where `fund_id`='{}' order by `price_date` ASC""".format( sql = """select distinct `fund_id`,`price_date`,`cumulative_nav` from `fund_nav` where `fund_id`='{}' order by `price_date` ASC""".format(
fund) fund)
cur = tamp_product_session.execute(sql) cur = tamp_product_session.execute(sql)
elif invest_type == 3:
sql = """select distinct `fund_id`,`price_date`,`cumulative_nav` from `ifa_imported_fund_nav` where `fund_id`='{}' order by `price_date` ASC""".format(
fund)
cur = tamp_fund_session.execute(sql)
data = cur.fetchall() data = cur.fetchall()
df = pd.DataFrame(data, columns=['fund_id', 'price_date', 'cumulative_nav']).dropna(how='any') df = pd.DataFrame(data, columns=['fund_id', 'price_date', 'cumulative_nav']).dropna(how='any')
......
...@@ -670,6 +670,44 @@ class PortfolioDiagnose(object): ...@@ -670,6 +670,44 @@ class PortfolioDiagnose(object):
return prod return prod
def proposal_customize(self, suggest_fund_list, suggest_fund_weight_list, suggest_fund_type):
"""建议申购基金
Args:
prod: 剔除建议替换基金的组合净值表
Returns: 增加建议申购基金的组合净值表
"""
trade_date_df = get_trade_cal()
prod = pd.DataFrame(index=trade_date_df["end_date"])
self.new_weights = suggest_fund_weight_list
for j in range(len(suggest_fund_list)):
proposal = suggest_fund_list[j]
# 获取净值
proposal_nav = get_tamp_nav(proposal, pd.to_datetime("2010-01-01"), invest_type=suggest_fund_type[proposal])
self.freq_list.append(get_frequency(proposal_nav))
proposal_nav = rename_col(proposal_nav, proposal)
prod[proposal] = proposal_nav[proposal]
self.proposal_fund.append(proposal)
prod.ffill(inplace=True)
prod = prod[prod.index >= self.start_date]
prod = resample(prod, get_trade_cal(), min(self.freq_list))
self.new_correlation = cal_correlation(prod)
prod.dropna(how='all', inplace=True)
prod.fillna(method="bfill", inplace=True)
self.new_correlation = self.new_correlation.fillna(1).round(2)
self.new_correlation.columns = self.new_correlation.columns.map(lambda x: get_fund_name(x, suggest_fund_type[x]).values[0][0])
self.new_correlation.index = self.new_correlation.index.map(lambda x: get_fund_name(x, suggest_fund_type[x]).values[0][0])
prod = pd.DataFrame(prod, dtype=np.float)
self.propose_portfolio = prod
self.prod = prod
return prod
def optimize(self, ): def optimize(self, ):
import time import time
start = time.time() start = time.time()
...@@ -778,25 +816,6 @@ class PortfolioDiagnose(object): ...@@ -778,25 +816,6 @@ class PortfolioDiagnose(object):
end4 = time.time() end4 = time.time()
print("模型计算一次时间:", end4 - start) print("模型计算一次时间:", end4 - start)
# S = np.asmatrix(S)
# w_origin = np.asarray([i for i in w_origin.values()])
# risk_target = np.asarray([1 / len(w_origin)] * len(w_origin))
# self.proposal_weights = calcu_w(w_origin, S, risk_target)
# elif self.client_type == 2:
# elif self.client_type == 3:
# elif self.client_type == 4:
# elif self.client_type == 5:
# print(len(propose_portfolio.columns))
# # 单支基金占投资额的下界为 100W/投资总额
# # w_low = 1e6 / self.invest_amount
# w_low = 0
# w_origin, S, mu = optim_drawdown(propose_portfolio, 0.5, [w_low, 1], min(self.freq_list))
# print(w_origin)
# S = np.asmatrix(S)
# w_origin = np.asarray([i for i in w_origin.values()])
# risk_target = np.asarray([1 / len(w_origin)] * len(w_origin))
# self.proposal_weights = calcu_w(w_origin, S, risk_target)
def return_compare(self): def return_compare(self):
index_data = get_index_daily(self.index_id, self.start_date) index_data = get_index_daily(self.index_id, self.start_date)
...@@ -1291,26 +1310,26 @@ class PortfolioDiagnose(object): ...@@ -1291,26 +1310,26 @@ class PortfolioDiagnose(object):
evaluation = choose_bad_evaluation(data) evaluation = choose_bad_evaluation(data)
ret = [] ret = []
fund_name = get_fund_name(fund_id).values[0][0] fund_name = get_fund_name(fund_id, fund_id_type).values[0][0]
# 默认评价 # 默认评价
# try: try:
# default_evaluation = pd.read_csv("./app/service/evaluation.csv", encoding='utf-8', names=['fund_id', 'eval']) default_evaluation = pd.read_csv("./app/service/evaluation.csv", encoding='utf-8', names=['fund_id', 'fund_name', 'eval'])
# if default_evaluation[default_evaluation['fund_id'] == fund_id]['eval'].values[0]: if default_evaluation[default_evaluation['fund_id'] == fund_id]['eval'].values[0]:
# ret.append('1、' + default_evaluation[default_evaluation['fund_id'] == fund_id]['eval'].values[0]) ret.append('1、' + default_evaluation[default_evaluation['fund_id'] == fund_id]['eval'].values[0])
#
# evaluation_dict = {'name': fund_name, 'data': ret} evaluation_dict = {'name': fund_name, 'data': ret}
#
# if objective: if objective:
# if fund_id in self.abandon_fund_score + self.abandon_fund_corr: if fund_id in self.abandon_fund_score + self.abandon_fund_corr:
# evaluation_dict['status'] = "换仓" evaluation_dict['status'] = "换仓"
# elif fund_id in self.portfolio: elif fund_id in self.portfolio:
# evaluation_dict['status'] = "保留" evaluation_dict['status'] = "保留"
# else: else:
# evaluation_dict['status'] = "" evaluation_dict['status'] = ""
# return evaluation_dict return evaluation_dict
# except Exception as e: except Exception as e:
# pass pass
i = 1 i = 1
for k, v in evaluation.items(): for k, v in evaluation.items():
......
...@@ -174,7 +174,8 @@ class UserCustomerResultAdaptor(UserCustomerDataAdaptor): ...@@ -174,7 +174,8 @@ class UserCustomerResultAdaptor(UserCustomerDataAdaptor):
# folio_report_data["contribution_decomposition"] = month_earn # folio_report_data["contribution_decomposition"] = month_earn
# 组合内单个基金净值数据 组合内基金持仓数据 # 组合内单个基金净值数据 组合内基金持仓数据
result_fund_nav_info, result_fund_hoding_info = self.group_fund_basic_info_data(cur_folio_order_data, cur_folio_result_cnav_data, cumulative_profit, total_cost) result_fund_nav_info, result_fund_hoding_info, weight_res = self.group_fund_basic_info_data(cur_folio_order_data, cur_folio_result_cnav_data, cumulative_profit, total_cost)
folio_report_data["weight_result"] = weight_res
# 拼接组合以及综合结果数据 # 拼接组合以及综合结果数据
folio_report_data["group_nav_info"] = result_fund_nav_info folio_report_data["group_nav_info"] = result_fund_nav_info
...@@ -388,6 +389,7 @@ class UserCustomerResultAdaptor(UserCustomerDataAdaptor): ...@@ -388,6 +389,7 @@ class UserCustomerResultAdaptor(UserCustomerDataAdaptor):
n_freq = freq_days(int(freq_max)) n_freq = freq_days(int(freq_max))
resample_df = resample(p_result_cnav_data, self.trade_cal_date, freq_max) resample_df = resample(p_result_cnav_data, self.trade_cal_date, freq_max)
# for index, row in p_order_df.iterrows(): # for index, row in p_order_df.iterrows():
fund_weight = {}
for hold_fund_id in p_order_df["fund_id"].unique(): for hold_fund_id in p_order_df["fund_id"].unique():
order = p_order_df[(p_order_df["fund_id"] == hold_fund_id)] order = p_order_df[(p_order_df["fund_id"] == hold_fund_id)]
row = order[order["order_type"] == 1].iloc[0] row = order[order["order_type"] == 1].iloc[0]
...@@ -457,11 +459,11 @@ class UserCustomerResultAdaptor(UserCustomerDataAdaptor): ...@@ -457,11 +459,11 @@ class UserCustomerResultAdaptor(UserCustomerDataAdaptor):
# 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["market_values"] = round((float(row["confirm_share"]) * (fund_basic_info["cur_cnav"] - confirm_cnav) + float(row["confirm_amount"]))/10000, 2)
temp_market_values = float(p_result_cnav_data[cur_fund_id + "_net_amount"].values[-1]) temp_market_values = float(p_result_cnav_data[cur_fund_id + "_net_amount"].values[-1])
fund_hoding_info["market_values"] = round(temp_market_values / 10000.0, 2) fund_hoding_info["market_values"] = round(temp_market_values / 10000.0, 2)
fund_hoding_info["weight"] = "%.2f" % round( temp_weight = float(fund_hoding_info["market_values"]) / total_market_values * 10000.0
float(fund_hoding_info["market_values"]) / total_market_values * 10000.0 * 100, 2) # 月末占比 fund_hoding_info["weight"] = "%.2f" % round(temp_weight * 100, 2) # 月末占比
temp_cost = float(p_result_cnav_data[cur_fund_id + "_amount"].values[-1]) temp_cost = float(p_result_cnav_data[cur_fund_id + "_amount"].values[-1])
fund_hoding_info["cost"] = "%.2f" % round( temp_cost / 10000, 2) # 投资本金 fund_hoding_info["cost"] = "%.2f" % round(temp_cost / 10000, 2) # 投资本金
fund_weight[cur_fund_id] = round(temp_weight, 4)
# 当月收益 # 当月收益
if row['confirm_share_date'] > self.month_start_date: if row['confirm_share_date'] > self.month_start_date:
cal_month_start_date = row['confirm_share_date'] cal_month_start_date = row['confirm_share_date']
...@@ -494,7 +496,7 @@ class UserCustomerResultAdaptor(UserCustomerDataAdaptor): ...@@ -494,7 +496,7 @@ class UserCustomerResultAdaptor(UserCustomerDataAdaptor):
return_ratio_year = annual_return(float(cum_profit_ratio_temp), cur_resample_df, n_freq) return_ratio_year = annual_return(float(cum_profit_ratio_temp), cur_resample_df, n_freq)
fund_hoding_info["return_ratio_year"] = "%.2f" % round(float(return_ratio_year)*100, 2) fund_hoding_info["return_ratio_year"] = "%.2f" % round(float(return_ratio_year)*100, 2)
group_fund_hoding_info.append(fund_hoding_info) group_fund_hoding_info.append(fund_hoding_info)
return group_fund_basic_info, group_fund_hoding_info return group_fund_basic_info, group_fund_hoding_info, fund_weight
@staticmethod @staticmethod
def combination_yield(p_combina_df, fund_id_list): def combination_yield(p_combina_df, fund_id_list):
......
...@@ -9,7 +9,7 @@ import datetime ...@@ -9,7 +9,7 @@ import datetime
import time import time
import traceback import traceback
import uuid import uuid
import pandas as pd
from app.api.engine import logging, pdf_folder, tamp_diagnose_app_engine, config, env from app.api.engine import logging, pdf_folder, tamp_diagnose_app_engine, config, env
import os import os
...@@ -65,6 +65,7 @@ def call_month_report(ifauser_id, ifauser_name, customer_id, customer_name): ...@@ -65,6 +65,7 @@ def call_month_report(ifauser_id, ifauser_name, customer_id, customer_name):
start = time.time() start = time.time()
try: try:
dt = DataIntegrate(ifauser_id, customer_id, '{}_{}_.pdf'.format(ifauser_name, customer_name)) dt = DataIntegrate(ifauser_id, customer_id, '{}_{}_.pdf'.format(ifauser_name, customer_name))
data = dt.get_template_data()
dt.render_data() dt.render_data()
print('IFA: {}, 客户: {}的基金月报已经生成, 耗时{}秒'.format(ifauser_name, customer_name, time.time()-start)) print('IFA: {}, 客户: {}的基金月报已经生成, 耗时{}秒'.format(ifauser_name, customer_name, time.time()-start))
except OSError: except OSError:
...@@ -80,8 +81,19 @@ if __name__ == '__main__': ...@@ -80,8 +81,19 @@ if __name__ == '__main__':
data = [] data = []
with TAMP_SQL(tamp_user_engine) as tamp_user, TAMP_SQL(tamp_order_engine) as tamp_order: with TAMP_SQL(tamp_user_engine) as tamp_user, TAMP_SQL(tamp_order_engine) as tamp_order:
tamp_user_session = tamp_user.session tamp_user_session = tamp_user.session
res = tamp_user_session.execute('SELECT DISTINCT user_id, customer_id , realname, customer_name FROM (select f1.user_id, f1.customer_id, f2.realname,f3.customer_name from tamp_order.customer_order_view f1, tamp_user.user_info f2,tamp_user.customer_info f3 where f2.id=f1.user_id and f3.id=f1.customer_id) res;') res = tamp_user_session.execute('SELECT DISTINCT user_id, customer_id , realname, customer_name FROM (select f1.user_id, f1.customer_id, f2.realname,f3.customer_name from tamp_order.customer_order_view f1, tamp_user.user_info f2,tamp_order.customer f3 where f2.id=f1.user_id and f3.id=f1.customer_id) res;')
data = res.fetchall() data = res.fetchall()
with TAMP_SQL(tamp_user_engine) as tamp_user:
tamp_user_session = tamp_user.session
sql = "SELECT `id` from user_info where team_id=0;"
cur = tamp_user_session.execute(sql)
ifa = cur.fetchall()
inner_ifa_df = pd.DataFrame(list(ifa), columns=["ifa_id"])
inner_ifa_list = list(inner_ifa_df["ifa_id"].values)
for d in data: for d in data:
if d[0] in inner_ifa_list:
print(d)
continue
call_month_report(d[0], d[2], d[1], d[3]) call_month_report(d[0], d[2], d[1], d[3])
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