Commit add80656 authored by pengxiong's avatar pengxiong

Merge branch 'dev' of http://47.100.44.39:10001/pengxiong/fund_report into dev

# Conflicts:
#	app/service/data_service.py
#	app/utils/jinjia2html.py
parents 3a23edc9 82206f51
...@@ -35,10 +35,10 @@ class UserCustomerDataAdaptor: ...@@ -35,10 +35,10 @@ 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-04") # self.end_date = pd.to_datetime("2020-12-04")
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-11-1") # self.month_start_date = pd.to_datetime("2020-11-01")
self.user_customer_order_df = self.get_user_customer_order_data() self.user_customer_order_df = self.get_user_customer_order_data()
self.fund_nav_total, self.fund_cnav_total = self.get_customer_fund_nav_data() self.fund_nav_total, self.fund_cnav_total = self.get_customer_fund_nav_data()
self.index_df = self.get_customer_index_nav_data() self.index_df = self.get_customer_index_nav_data()
...@@ -68,10 +68,10 @@ class UserCustomerDataAdaptor: ...@@ -68,10 +68,10 @@ class UserCustomerDataAdaptor:
with TAMP_SQL(tamp_user_engine) as tamp_user, TAMP_SQL(tamp_product_engine) as tamp_product: with TAMP_SQL(tamp_user_engine) as tamp_user, TAMP_SQL(tamp_product_engine) as tamp_product:
tamp_user_session = tamp_user.session tamp_user_session = tamp_user.session
tamp_product_session = tamp_product.session tamp_product_session = tamp_product.session
sql_user = """select f2.realname,f3.customer_name,fund_id,f1.order_type,f1.pay_date,f1.subscription_fee,f1.confirm_share_date,f1.confirm_share,f1.confirm_amount,f1.nav,f1.folio_name from customer_order f1, user_info f2,customer_info f3 where f2.id=f1.user_id and f3.id=f1.customer_id and f1.user_id='{}' and f1.customer_id='{}'""".format(self.user_id, self.customer_id) sql_user = """select f1.id, f2.realname,f3.customer_name,fund_id,f1.order_type,f1.pay_date,f1.subscription_fee,f1.confirm_share_date,f1.confirm_share,f1.confirm_amount,f1.nav,f1.folio_name from customer_order f1, user_info f2,customer_info f3 where f2.id=f1.user_id and f3.id=f1.customer_id and f1.user_id='{}' and f1.customer_id='{}'""".format(self.user_id, self.customer_id)
cur = tamp_user_session.execute(sql_user) cur = tamp_user_session.execute(sql_user)
data = cur.fetchall() data = cur.fetchall()
order_df = pd.DataFrame(list(data), columns=['username', 'customer_name', 'fund_id', 'order_type', 'pay_date', order_df = pd.DataFrame(list(data), columns=['order_id', 'username', 'customer_name', 'fund_id', 'order_type', 'pay_date',
'subscription_fee', 'confirm_share_date', 'confirm_share', 'subscription_fee', 'confirm_share_date', 'confirm_share',
'confirm_amount', 'nav', 'folio_name']) 'confirm_amount', 'nav', 'folio_name'])
...@@ -122,7 +122,7 @@ class UserCustomerDataAdaptor: ...@@ -122,7 +122,7 @@ class UserCustomerDataAdaptor:
cur_fund_nav_df["price_date"] = pd.to_datetime(cur_fund_nav_df["price_date"]) cur_fund_nav_df["price_date"] = pd.to_datetime(cur_fund_nav_df["price_date"])
cur_fund_nav_df.drop_duplicates(subset="price_date", keep='first', inplace=True) cur_fund_nav_df.drop_duplicates(subset="price_date", keep='first', inplace=True)
cur_fund_nav_df.set_index("price_date", inplace=True) cur_fund_nav_df.set_index("price_date", inplace=True)
cur_fund_nav_df = cur_fund_nav_df[cur_fund_nav_df.index.isin(all_fund_nav.index & cur_fund_nav_df.index)] cur_fund_nav_df = cur_fund_nav_df[cur_fund_nav_df.index.isin(all_fund_nav.index)]
all_fund_nav[cur_fund_id] = cur_fund_nav_df["nav"] all_fund_nav[cur_fund_id] = cur_fund_nav_df["nav"]
all_fund_cnav[cur_fund_id] = cur_fund_nav_df["cnav"] all_fund_cnav[cur_fund_id] = cur_fund_nav_df["cnav"]
...@@ -186,6 +186,12 @@ class UserCustomerDataAdaptor: ...@@ -186,6 +186,12 @@ class UserCustomerDataAdaptor:
diff_nav = row["nav"] - last_nav_data.values[0] diff_nav = row["nav"] - last_nav_data.values[0]
cur_cnav = last_cnav_data.values[0] + diff_nav cur_cnav = last_cnav_data.values[0] + diff_nav
cnav_df.loc[confirm_share_date, cur_fund_id] = cur_cnav cnav_df.loc[confirm_share_date, cur_fund_id] = cur_cnav
else:
confirm_date_nav_data = p_nav_df[p_nav_df.index == confirm_share_date][cur_fund_id].tail(1)
confirm_date_cnav_data = p_cnav_df[p_cnav_df.index == confirm_share_date][cur_fund_id].tail(1)
diff_nav = row["nav"] - confirm_date_nav_data.values[0]
cur_cnav = confirm_date_cnav_data.values[0] + diff_nav
cnav_df.loc[confirm_share_date, cur_fund_id] = cur_cnav
cnav_df = cnav_df.dropna(axis=0, how="all").fillna(method='ffill') cnav_df = cnav_df.dropna(axis=0, how="all").fillna(method='ffill')
for index, row in p_order_df.iterrows(): for index, row in p_order_df.iterrows():
...@@ -237,6 +243,8 @@ class UserCustomerDataAdaptor: ...@@ -237,6 +243,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_ + "_amount"] 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_ + "_net_amount"] = cnav_df[p_fund_id_ + "_share"] * cnav_df[p_fund_id_] # cnav_df[p_fund_id_ + "_net_amount"] = cnav_df[p_fund_id_ + "_share"] * cnav_df[p_fund_id_]
# cnav_df[p_fund_id_ + "_profit_ratio"] = cnav_df[p_fund_id_ + "_earn"].apply(lambda x: Decimal(x)) / cnav_df[
# p_fund_id_ + "_net_amount"].shift()
self.group_data[p_folio] = {"result_cnav_data": cnav_df, "order_df": p_order_df} self.group_data[p_folio] = {"result_cnav_data": cnav_df, "order_df": p_order_df}
return cnav_df return cnav_df
...@@ -273,6 +281,12 @@ class UserCustomerDataAdaptor: ...@@ -273,6 +281,12 @@ class UserCustomerDataAdaptor:
diff_nav = row["nav"] - last_nav_data.values[0] diff_nav = row["nav"] - last_nav_data.values[0]
cur_cnav = last_cnav_data.values[0] + diff_nav cur_cnav = last_cnav_data.values[0] + diff_nav
cnav_df.loc[confirm_share_date, cur_fund_id] = cur_cnav cnav_df.loc[confirm_share_date, cur_fund_id] = cur_cnav
else:
confirm_date_nav_data = p_nav_df[p_nav_df.index == confirm_share_date][cur_fund_id].tail(1)
confirm_date_cnav_data = p_cnav_df[p_cnav_df.index == confirm_share_date][cur_fund_id].tail(1)
diff_nav = row["nav"] - confirm_date_nav_data.values[0]
cur_cnav = confirm_date_cnav_data.values[0] + diff_nav
cnav_df.loc[confirm_share_date, cur_fund_id] = cur_cnav
cnav_df = cnav_df.dropna(axis=0, how="all").fillna(method='ffill') cnav_df = cnav_df.dropna(axis=0, how="all").fillna(method='ffill')
for index, row in p_order_df.iterrows(): for index, row in p_order_df.iterrows():
...@@ -314,5 +328,8 @@ class UserCustomerDataAdaptor: ...@@ -314,5 +328,8 @@ class UserCustomerDataAdaptor:
# cnav_df[p_fund_id_ + "_earn"] = cnav_df[p_fund_id_ + "_earn"].apply(lambda x: float(x)) # cnav_df[p_fund_id_ + "_earn"] = cnav_df[p_fund_id_ + "_earn"].apply(lambda x: float(x))
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_ + "_amount"] 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_ + "_profit_ratio"] = cnav_df[p_fund_id_ + "_earn"].apply(lambda x: Decimal(x)) / cnav_df[
# p_fund_id_ + "_net_amount"].shift()
# cnav_df[p_fund_id_ + "_net_amount"] = cnav_df[p_fund_id_ + "_share"] * cnav_df[p_fund_id_] # cnav_df[p_fund_id_ + "_net_amount"] = cnav_df[p_fund_id_ + "_share"] * cnav_df[p_fund_id_]
return cnav_df return cnav_df
This diff is collapsed.
...@@ -402,11 +402,21 @@ class UserCustomerResultAdaptor(UserCustomerDataAdaptor): ...@@ -402,11 +402,21 @@ class UserCustomerResultAdaptor(UserCustomerDataAdaptor):
# nav_net_amount_df = resample(return_ratio_df, self.trade_cal_date, freq_max) # nav_net_amount_df = resample(return_ratio_df, self.trade_cal_date, freq_max)
nav_net_amount_df["sum_net_amount"] = nav_net_amount_df[fund_id_list_amount].sum(axis=1).apply(lambda x: Decimal.from_float(x)) nav_net_amount_df["sum_net_amount"] = nav_net_amount_df[fund_id_list_amount].sum(axis=1).apply(lambda x: Decimal.from_float(x))
for amount_name in fund_id_list: for amount_name in fund_id_list:
price = nav_net_amount_df[amount_name].dropna()
profit = price.diff().fillna(Decimal(0))
profit_ratio_new = profit / price.shift(1)
profit_ratio_old = nav_net_amount_df[amount_name+"_profit_ratio"]
nan_index = profit_ratio_new[pd.isna(profit_ratio_new)].index
profit_ratio_new[nan_index] = profit_ratio_old[nan_index]
nav_net_amount_df[amount_name + "_profit_ratio"] = profit_ratio_new
nav_net_amount_df[amount_name+"_amount_ratio"] = nav_net_amount_df[amount_name+"_net_amount"]/(nav_net_amount_df["sum_net_amount"]) nav_net_amount_df[amount_name+"_amount_ratio"] = nav_net_amount_df[amount_name+"_net_amount"]/(nav_net_amount_df["sum_net_amount"])
nav_net_amount_df[amount_name+"_profit_ratio_weight"] = nav_net_amount_df[amount_name+"_amount_ratio"].shift(1) * nav_net_amount_df[amount_name+"_profit_ratio"]
fund_profit_ratio = nav_net_amount_df[amount_name + "_profit_ratio"].dropna() + 1 fund_profit_ratio = nav_net_amount_df[amount_name + "_profit_ratio"].dropna() + 1
nav_net_amount_df[amount_name + "_profit_cum_ratio_weight"] = (fund_profit_ratio.cumprod()-1)*nav_net_amount_df[amount_name+"_amount_ratio"].shift(1) amount_ratio_shift = nav_net_amount_df[amount_name + "_amount_ratio"].shift(1)
# enter_date = nav_net_amount_df[amount_name+"_profit_ratio"].dropna() num_va = len(amount_ratio_shift[amount_ratio_shift.values==0])
amount_ratio_shift.iloc[num_va] = amount_ratio_shift.values[num_va+1]
nav_net_amount_df[amount_name + "_profit_ratio_weight"] = amount_ratio_shift * nav_net_amount_df[amount_name + "_profit_ratio"]
nav_net_amount_df[amount_name + "_profit_cum_ratio_weight"] = (fund_profit_ratio.cumprod()-1)*amount_ratio_shift # enter_date = nav_net_amount_df[amount_name+"_profit_ratio"].dropna()
fund_id_list_profit_ratio_weight = [i + "_profit_ratio_weight" for i in fund_id_list] fund_id_list_profit_ratio_weight = [i + "_profit_ratio_weight" for i in fund_id_list]
nav_profit_ratio_weight = nav_net_amount_df[fund_id_list_profit_ratio_weight].copy().fillna(method='ffill') nav_profit_ratio_weight = nav_net_amount_df[fund_id_list_profit_ratio_weight].copy().fillna(method='ffill')
......
...@@ -1037,27 +1037,55 @@ ...@@ -1037,27 +1037,55 @@
<table class="tss1_table"> <table class="tss1_table">
<tr> <tr>
<td> <td>
{%if month_rise>=0%}
本月涨幅:<span class="red">{{month_rise}}%</span> 本月涨幅:<span class="red">{{month_rise}}%</span>
{%else%}
本月涨幅:<span class="green">{{month_rise}}%</span>
{%endif%}
</td> </td>
<td> <td>
{%if now_month_income>=0%}
本月收益:<span class="red">{{now_month_income}}元</span>
{%else%}
本月收益:<span class="green">{{now_month_income}}元</span> 本月收益:<span class="green">{{now_month_income}}元</span>
{%endif%}
</td> </td>
<td> <td>
{%if year_totoal_rate_of_return>=0%}
今年累计收益率:<span class="red">{{year_totoal_rate_of_return}}%</span> 今年累计收益率:<span class="red">{{year_totoal_rate_of_return}}%</span>
{%else%}
今年累计收益率:<span class="green">{{year_totoal_rate_of_return}}%</span>
{%endif%}
</td> </td>
<td> <td>
{%if now_year_income>=0%}
今年累计收益:<span class="red">{{now_year_income}}元</span>
{%else%}
今年累计收益:<span class="green">{{now_year_income}}元</span> 今年累计收益:<span class="green">{{now_year_income}}元</span>
{%endif%}
</td> </td>
</tr> </tr>
<tr> <tr>
<td> <td>
{%if totoal_rate_of_return>=0%}
成立以来累计收益率:<span class="red">{{totoal_rate_of_return}}%</span> 成立以来累计收益率:<span class="red">{{totoal_rate_of_return}}%</span>
{%else%}
成立以来累计收益率:<span class="green">{{totoal_rate_of_return}}%</span>
{%endif%}
</td> </td>
<td> <td>
{%if now_annualised_return>=0%}
年化收益率:<span class="red">{{now_annualised_return}}%</span>
{%else%}
年化收益率:<span class="green">{{now_annualised_return}}%</span> 年化收益率:<span class="green">{{now_annualised_return}}%</span>
{%endif%}
</td> </td>
<td> <td>
{%if now_withdrawal>=0%}
最大回撤:<span class="red">{{now_withdrawal}}%</span> 最大回撤:<span class="red">{{now_withdrawal}}%</span>
{%else%}
最大回撤:<span class="green">{{now_withdrawal}}%</span>
{%endif%}
</td> </td>
<td> <td>
</td> </td>
...@@ -1076,10 +1104,20 @@ ...@@ -1076,10 +1104,20 @@
投资成本:<span class="red">{{now_allocation_amount}}元</span> 投资成本:<span class="red">{{now_allocation_amount}}元</span>
</td> </td>
<td> <td>
{%if final_balance>=now_allocation_amount%}
期末资产:<span class="red">{{final_balance}}元</span>
{%else%}
期末资产:<span class="green">{{final_balance}}元</span> 期末资产:<span class="green">{{final_balance}}元</span>
{%endif%}
</td> </td>
<td> <td>
{%if total_profit>=0%}
累计盈利:<span class="red">{{total_profit}}元</span> 累计盈利:<span class="red">{{total_profit}}元</span>
{%else%}
累计盈利:<span class="green">{{total_profit}}元</span>
{%endif%}
</td> </td>
<td> <td>
</td> </td>
...@@ -1296,7 +1334,7 @@ ...@@ -1296,7 +1334,7 @@
<th>目标最大回撤(%)</th> <th>目标最大回撤(%)</th>
</tr> </tr>
<tr> <tr>
<td>2000</td> <td>{{cost_of_investment}}</td>
<td>5%-10%</td> <td>5%-10%</td>
<td>5%-10%</td> <td>5%-10%</td>
</tr> </tr>
...@@ -1513,7 +1551,7 @@ ...@@ -1513,7 +1551,7 @@
<table border="1"> <table border="1">
<tr> <tr>
<th colspan="5">投资本金</th> <th colspan="5">投资本金</th>
<th colspan="4">10月业绩</th> <th colspan="4">{{month}}月业绩</th>
<th colspan="3">累计业绩</th> <th colspan="3">累计业绩</th>
</tr> </tr>
<tr> <tr>
......
...@@ -211,11 +211,13 @@ class DataIntegrate: ...@@ -211,11 +211,13 @@ class DataIntegrate:
'customer_name': self.customer_name, 'customer_name': self.customer_name,
'customer_gender': '女', 'customer_gender': '女',
'year_month': self.user_customer.month_start_date.strftime("%Y-%m"), 'year_month': self.user_customer.month_start_date.strftime("%Y-%m"),
'month': self.user_customer.month_start_date.strftime("%m"),
'start_date': self.user_customer.start_date.strftime("%Y-%m-%d"), 'start_date': self.user_customer.start_date.strftime("%Y-%m-%d"),
'ifa_company': '飞度工作室', 'ifa_company': '飞度工作室',
'title': '10月综述', 'title': '10月综述',
'brand_name': '小飞象<br>工作室', 'brand_name': '小飞象<br>工作室',
'customer_old': 42, 'customer_level': '平衡型', 'customer_old': 42, 'customer_level': '平衡型',
# 'new_evaluation': self.new_evaluation,
'position_years': '5年', 'planned_allocation_amount': 2000.00, 'position_years': '5年', 'planned_allocation_amount': 2000.00,
'now_allocation_amount': self.total_cost, 'now_yield': self.now_yield, 'index_yield': self.index_yield, 'now_allocation_amount': self.total_cost, 'now_yield': self.now_yield, 'index_yield': self.index_yield,
'expected_yield': 20, 'now_annualised_return': self.now_annualised_return, 'expected_yield': 20, 'now_annualised_return': self.now_annualised_return,
...@@ -272,5 +274,5 @@ class DataIntegrate: ...@@ -272,5 +274,5 @@ class DataIntegrate:
if __name__ == '__main__': if __name__ == '__main__':
start = time.time() start = time.time()
DataIntegrate(ifa_id='189138514712358912',customer_id='6716613796058116091') DataIntegrate(ifa_id='USER_INFO15916072577875', customer_id='6716613804966817792')
print('耗时{}秒'.format(round(time.time()-start, 2))) print('耗时{}秒'.format(round(time.time()-start, 2)))
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