Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Sign in
Toggle navigation
F
fund_report
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
彭熊
fund_report
Commits
b2db96ec
Commit
b2db96ec
authored
Dec 27, 2020
by
赵杰
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
持仓报告修复数据
parent
b2bd9f89
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
76 additions
and
14 deletions
+76
-14
data_service_v2.py
app/service/data_service_v2.py
+24
-1
data_service_v2_1.py
app/service/data_service_v2_1.py
+25
-1
result_service_v2.py
app/service/result_service_v2.py
+21
-8
monthReportV2.1.html
app/templates/v2/monthReportV2.1.html
+3
-3
jinjia2html_v2.py
app/utils/jinjia2html_v2.py
+3
-1
No files found.
app/service/data_service_v2.py
View file @
b2db96ec
...
...
@@ -106,11 +106,32 @@ class UserCustomerDataAdaptor:
user_customer_order_df
=
order_df
.
set_index
(
'fund_id'
)
.
join
(
product_df
.
set_index
(
'fund_id'
))
.
reset_index
()
user_customer_order_df
[
"confirm_share_date"
]
=
user_customer_order_df
[
"confirm_share_date"
]
.
apply
(
lambda
x
:
pd
.
to_datetime
(
x
.
date
()))
self
.
start_date
=
user_customer_order_df
[
"confirm_share_date"
]
.
min
()
self
.
customer_real_name
=
user_customer_order_df
[
"customer_name"
]
.
values
[
0
]
self
.
ifa_real_name
=
user_customer_order_df
[
"username"
]
.
values
[
0
]
user_customer_order_df
=
user_customer_order_df
[
user_customer_order_df
[
"confirm_share_date"
]
<=
self
.
end_date
]
user_customer_order_df
[
"confirm_amount"
]
=
user_customer_order_df
[
"confirm_amount"
]
-
user_customer_order_df
[
"subscription_fee"
]
user_customer_order_df
.
index
=
pd
.
Series
(
range
(
len
(
user_customer_order_df
)))
for
index
,
row
in
user_customer_order_df
.
iterrows
():
if
row
[
"order_type"
]
==
2
:
need_less_share
=
row
[
"confirm_share"
]
for
index_ori
,
row_ori
in
user_customer_order_df
.
iterrows
():
if
index_ori
>=
index
:
break
if
row
[
"fund_id"
]
==
row_ori
[
"fund_id"
]
and
row_ori
[
"order_type"
]
==
1
:
ori_share
=
row_ori
[
"confirm_share"
]
if
need_less_share
>=
ori_share
:
need_less_share
-=
ori_share
user_customer_order_df
.
loc
[
index_ori
,
"confirm_share"
]
=
0
else
:
need_less_share
=
0
user_customer_order_df
.
loc
[
index_ori
,
"confirm_share"
]
=
row_ori
[
"confirm_share"
]
-
need_less_share
if
need_less_share
<=
0
:
break
user_customer_order_df
=
user_customer_order_df
[(
user_customer_order_df
[
"order_type"
]
==
1
)
&
(
user_customer_order_df
[
"confirm_share"
]
>
0
)]
user_customer_order_df
.
index
=
pd
.
Series
(
range
(
len
(
user_customer_order_df
)))
self
.
start_date
=
user_customer_order_df
[
"confirm_share_date"
]
.
min
()
return
user_customer_order_df
# 获取客户持有的基金净值数据
...
...
@@ -163,6 +184,8 @@ class UserCustomerDataAdaptor:
data
=
cur
.
fetchall
()
cur_fund_performance_df
=
pd
.
DataFrame
(
list
(
data
),
columns
=
[
'price_date'
,
'ret_1w'
,
'ret_cum_1m'
,
'ret_cum_6m'
,
'ret_cum_1y'
,
'ret_cum_ytd'
,
'ret_cum_incep'
])
cur_fund_performance_df
=
cur_fund_performance_df
[
cur_fund_performance_df
[
"price_date"
]
<=
self
.
end_date
.
date
()]
self
.
all_fund_performance
[
cur_fund_id
]
=
cur_fund_performance_df
cur_fund_nav_df
[
"price_date"
]
=
pd
.
to_datetime
(
cur_fund_nav_df
[
"price_date"
])
...
...
app/service/data_service_v2_1.py
View file @
b2db96ec
...
...
@@ -105,11 +105,33 @@ class UserCustomerDataAdaptor:
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
()
self
.
start_date
=
user_customer_order_df
[
"confirm_share_date"
]
.
min
(
)
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
.
ifa_real_name
=
user_customer_order_df
[
"username"
]
.
values
[
0
]
user_customer_order_df
=
user_customer_order_df
[
user_customer_order_df
[
"confirm_share_date"
]
<=
self
.
end_date
]
user_customer_order_df
[
"confirm_amount"
]
=
user_customer_order_df
[
"confirm_amount"
]
-
user_customer_order_df
[
"subscription_fee"
]
user_customer_order_df
.
index
=
pd
.
Series
(
range
(
len
(
user_customer_order_df
)))
for
index
,
row
in
user_customer_order_df
.
iterrows
():
if
row
[
"order_type"
]
==
2
:
need_less_share
=
row
[
"confirm_share"
]
for
index_ori
,
row_ori
in
user_customer_order_df
.
iterrows
():
if
index_ori
>=
index
:
break
if
row
[
"fund_id"
]
==
row_ori
[
"fund_id"
]
and
row_ori
[
"order_type"
]
==
1
:
ori_share
=
row_ori
[
"confirm_share"
]
if
need_less_share
>=
ori_share
:
need_less_share
-=
ori_share
user_customer_order_df
.
loc
[
index_ori
,
"confirm_share"
]
=
0
else
:
need_less_share
=
0
user_customer_order_df
.
loc
[
index_ori
,
"confirm_share"
]
=
row_ori
[
"confirm_share"
]
-
need_less_share
if
need_less_share
<=
0
:
break
user_customer_order_df
=
user_customer_order_df
[(
user_customer_order_df
[
"order_type"
]
==
1
)
&
(
user_customer_order_df
[
"confirm_share"
]
>
0
)]
user_customer_order_df
.
index
=
pd
.
Series
(
range
(
len
(
user_customer_order_df
)))
self
.
start_date
=
user_customer_order_df
[
"confirm_share_date"
]
.
min
()
return
user_customer_order_df
# 获取客户持有的基金净值数据
...
...
@@ -162,6 +184,8 @@ class UserCustomerDataAdaptor:
data
=
cur
.
fetchall
()
cur_fund_performance_df
=
pd
.
DataFrame
(
list
(
data
),
columns
=
[
'price_date'
,
'ret_1w'
,
'ret_cum_1m'
,
'ret_cum_6m'
,
'ret_cum_1y'
,
'ret_cum_ytd'
,
'ret_cum_incep'
])
cur_fund_performance_df
=
cur_fund_performance_df
[
cur_fund_performance_df
[
"price_date"
]
<=
self
.
end_date
.
date
()]
self
.
all_fund_performance
[
cur_fund_id
]
=
cur_fund_performance_df
cur_fund_nav_df
[
"price_date"
]
=
pd
.
to_datetime
(
cur_fund_nav_df
[
"price_date"
])
...
...
app/service/result_service_v2.py
View file @
b2db96ec
...
...
@@ -63,8 +63,7 @@ class UserCustomerResultAdaptor(UserCustomerDataAdaptor):
"cumulative"
:
cumulative_data
}
# 总成本
total_cost
=
float
(
cur_folio_order_data
[
cur_folio_order_data
[
"order_type"
]
==
1
][
"confirm_amount"
]
.
sum
()
-
\
cur_folio_order_data
[
cur_folio_order_data
[
"order_type"
]
==
2
][
"confirm_amount"
]
.
sum
())
total_cost
=
round
(
float
((
cur_folio_order_data
[
cur_folio_order_data
[
"order_type"
]
==
1
][
"confirm_share"
]
*
cur_folio_order_data
[
cur_folio_order_data
[
"order_type"
]
==
1
][
"nav"
])
.
sum
()),
2
)
folio_report_data
[
"total_cost"
]
=
total_cost
# 累积盈利
...
...
@@ -104,7 +103,7 @@ class UserCustomerResultAdaptor(UserCustomerDataAdaptor):
# 本月累积收益率
last_profit_ratio
=
return_ratio_df
.
loc
[:
self
.
month_start_date
,
"cum_return_ratio"
]
.
values
cur_profit_ratio
=
return_ratio_df
.
loc
[
self
.
month_start_date
:,
"cum_return_ratio"
]
.
values
cur_profit_ratio
=
return_ratio_df
.
loc
[
self
.
month_start_date
-
datetime
.
timedelta
(
days
=
1
)
:,
"cum_return_ratio"
]
.
values
if
len
(
last_profit_ratio
)
<=
0
:
cur_month_profit_ratio
=
cur_profit_ratio
[
-
1
]
-
1
else
:
...
...
@@ -215,8 +214,7 @@ class UserCustomerResultAdaptor(UserCustomerDataAdaptor):
resample_df
=
resample_df
[
resample_df
.
index
<=
self
.
end_date
]
# 总成本
total_cost
=
float
(
cur_folio_order_data
[
cur_folio_order_data
[
"order_type"
]
==
1
][
"confirm_amount"
]
.
sum
()
-
\
cur_folio_order_data
[
cur_folio_order_data
[
"order_type"
]
==
2
][
"confirm_amount"
]
.
sum
())
total_cost
=
round
(
float
((
cur_folio_order_data
[
cur_folio_order_data
[
"order_type"
]
==
1
][
"confirm_share"
]
*
cur_folio_order_data
[
cur_folio_order_data
[
"order_type"
]
==
1
][
"nav"
])
.
sum
()),
2
)
report_data
[
"total_cost"
]
=
total_cost
# 累积盈利
...
...
@@ -350,6 +348,8 @@ class UserCustomerResultAdaptor(UserCustomerDataAdaptor):
n_freq
=
freq_days
(
int
(
freq_max
))
resample_df
=
resample
(
p_result_cnav_data
,
self
.
trade_cal_date
,
freq_max
)
for
index
,
row
in
p_order_df
.
iterrows
():
if
row
[
'order_type'
]
==
2
or
row
[
"confirm_share"
]
<=
0
:
continue
cur_fund_id
=
str
(
row
[
"fund_id"
])
cur_fund_performance
=
self
.
all_fund_performance
[
cur_fund_id
]
if
len
(
cur_fund_performance
)
<=
0
:
...
...
@@ -410,24 +410,37 @@ class UserCustomerResultAdaptor(UserCustomerDataAdaptor):
fund_hoding_info
[
"confirm_date"
]
=
row
[
"confirm_share_date"
]
.
strftime
(
"
%
Y-
%
m-
%
d"
)
fund_hoding_info
[
"hold_year"
]
=
"
%.2
f"
%
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
)
temp_market_values
=
float
(
row
[
"confirm_share"
])
*
(
fund_basic_info
[
"cur_cnav"
]
-
confirm_cnav
)
+
float
(
row
[
"confirm_amount"
])
fund_hoding_info
[
"weight"
]
=
"
%.2
f"
%
round
(
float
(
fund_hoding_info
[
"market_values"
])
/
total_market_values
*
10000.0
*
100
,
2
)
# 月末占比
fund_hoding_info
[
"cost"
]
=
"
%.2
f"
%
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
row
[
'confirm_share_date'
]
>
self
.
month_start_date
:
cal_month_start_date
=
row
[
'confirm_share_date'
]
last_month_cnav_serise
=
p_result_cnav_data
[
p_result_cnav_data
.
index
==
pd
.
to_datetime
(
cal_month_start_date
)][
row
[
"fund_id"
]]
.
dropna
()
else
:
cal_month_start_date
=
self
.
month_start_date
-
datetime
.
timedelta
(
days
=
1
)
last_month_cnav_serise
=
p_result_cnav_data
[
p_result_cnav_data
.
index
<
pd
.
to_datetime
(
cal_month_start_date
)][
row
[
"fund_id"
]]
.
dropna
()
if
len
(
last_month_cnav_serise
)
==
0
:
fund_hoding_info
[
"profit"
]
=
round
(
float
(
row
[
"confirm_share"
])
*
(
fund_basic_info
[
"cur_cnav"
]
-
confirm_cnav
)
/
10000
,
2
)
temp_profit
=
float
(
row
[
"confirm_share"
])
*
(
fund_basic_info
[
"cur_cnav"
]
-
confirm_cnav
)
temp_profit_ratio
=
(
fund_basic_info
[
"cur_cnav"
]
-
confirm_cnav
)
/
confirm_cnav
else
:
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
)
temp_profit
=
float
(
row
[
"confirm_share"
])
*
(
fund_basic_info
[
"cur_cnav"
]
-
last_month_cnav
)
temp_profit_ratio
=
(
fund_basic_info
[
"cur_cnav"
]
-
last_month_cnav
)
/
last_month_cnav
# 当月收益率
fund_hoding_info
[
"month_return_ratio"
]
=
"
%.2
f"
%
round
(
float
(
fund_hoding_info
[
"profit"
])
/
float
(
fund_hoding_info
[
"market_values"
])
*
100
,
2
)
# fund_hoding_info["month_return_ratio"] = "%.2f" % round(temp_profit / temp_market_values*100, 2)
fund_hoding_info
[
"month_return_ratio"
]
=
"
%.2
f"
%
round
(
temp_profit_ratio
*
100
,
2
)
# 累积收益
fund_hoding_info
[
"cum_profit"
]
=
"
%.2
f"
%
round
(
float
(
row
[
"confirm_share"
])
*
(
fund_basic_info
[
"cur_cnav"
]
-
confirm_cnav
)
/
10000
,
2
)
# 累积收益率
fund_hoding_info
[
"cum_profit_ratio"
]
=
"
%.2
f"
%
round
((
fund_basic_info
[
"cur_cnav"
]
-
confirm_cnav
)
/
confirm_cnav
*
100
,
2
)
cum_profit_ratio_temp
=
(
fund_basic_info
[
"cur_cnav"
]
-
confirm_cnav
)
/
confirm_cnav
# 累积年化收益率
cur_resample_df
=
resample_df
[[
row
[
"fund_id"
]]]
.
dropna
()
return_ratio_year
=
annual_return
(
float
(
fund_hoding_info
[
"cum_profit_ratio"
])
/
100.0
,
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"
]
=
"
%.2
f"
%
round
(
float
(
return_ratio_year
)
*
100
,
2
)
group_fund_hoding_info
.
append
(
fund_hoding_info
)
return
group_fund_basic_info
,
group_fund_hoding_info
...
...
app/templates/v2/monthReportV2.1.html
View file @
b2db96ec
...
...
@@ -1046,7 +1046,7 @@
{%endif%}
</td>
<td>
{%if (now_month_income| float) >=0%}
{%if (now_month_income
_temp
| float) >=0%}
本月收益:
<span
class=
"red"
>
{{now_month_income}}元
</span>
{%else%}
本月收益:
<span
class=
"green"
>
{{now_month_income}}元
</span>
...
...
@@ -1060,7 +1060,7 @@
{%endif%}
</td>
<td>
{%if (now_year_income|float)>=0%}
{%if (now_year_income
_temp
|float)>=0%}
今年累计收益:
<span
class=
"red"
>
{{now_year_income}}元
</span>
{%else%}
今年累计收益:
<span
class=
"green"
>
{{now_year_income}}元
</span>
...
...
@@ -1113,7 +1113,7 @@
</td>
<td>
{%if (total_profit|float)>=0%}
{%if (total_profit
_temp
|float)>=0%}
累计盈利:
<span
class=
"red"
>
{{total_profit}}元
</span>
{%else%}
累计盈利:
<span
class=
"green"
>
{{total_profit}}元
</span>
...
...
app/utils/jinjia2html_v2.py
View file @
b2db96ec
...
...
@@ -264,6 +264,8 @@ class DataIntegrate:
'now_withdrawal'
:
self
.
now_withdrawal
,
'index_withdrawal'
:
self
.
index_withdrawal
,
'expected_withdrawal'
:
20
,
'now_year_income'
:
'{:,}'
.
format
(
self
.
now_year_income
),
'now_month_income'
:
'{:,}'
.
format
(
self
.
now_month_income
),
'final_balance'
:
'{:,}'
.
format
(
self
.
final_balance
),
'total_profit'
:
'{:,}'
.
format
(
self
.
total_profit
),
'total_profit_temp'
:
self
.
total_profit
,
'now_year_income_temp'
:
self
.
now_year_income
,
'now_month_income_temp'
:
self
.
now_month_income
,
'monthly_return_performance_pic'
:
self
.
monthly_return_performance_pic
,
'month_rise'
:
self
.
month_rise
,
'year_totoal_rate_of_return'
:
self
.
year_totoal_rate_of_return
,
...
...
@@ -329,6 +331,6 @@ class DataIntegrate:
if
__name__
==
'__main__'
:
start
=
time
.
time
()
dt
=
DataIntegrate
(
ifa_id
=
'
USER_INFO15916072577875'
,
customer_id
=
'USER_INFO159178539249
96'
)
dt
=
DataIntegrate
(
ifa_id
=
'
212498904817250304'
,
customer_id
=
'CUSTOMER160864976623
96'
)
dt
.
render_data
()
print
(
'耗时{}秒'
.
format
(
round
(
time
.
time
()
-
start
,
2
)))
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment