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
994714cb
Commit
994714cb
authored
Dec 04, 2020
by
李宗熹
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'origin/dev' into dev
parents
c618fbd1
c3f325e8
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
57 additions
and
22 deletions
+57
-22
result_service_v2.py
app/service/result_service_v2.py
+34
-4
monthReportV2.html
app/templates/v2/monthReportV2.html
+10
-10
html_to_pdf.py
app/utils/html_to_pdf.py
+3
-3
jinjia2html.py
app/utils/jinjia2html.py
+10
-5
No files found.
app/service/result_service_v2.py
View file @
994714cb
...
...
@@ -183,7 +183,9 @@ class UserCustomerResultAdaptor(UserCustomerDataAdaptor):
#
fund_id_list
=
list
(
cur_folio_order_data
[
"fund_id"
]
.
unique
())
fund_id_list_earn
=
[
i
+
"_earn"
for
i
in
fund_id_list
]
fund_id_list_amount
=
[
i
+
"_net_amount"
for
i
in
fund_id_list
]
profit_df
=
cur_folio_result_cnav_data
[
fund_id_list_earn
]
amount_df
=
cur_folio_result_cnav_data
[
fund_id_list_amount
]
.
copy
()
# 持仓周期
first_trade_date
=
cur_folio_order_data
[
"confirm_share_date"
]
.
min
()
...
...
@@ -282,6 +284,28 @@ class UserCustomerResultAdaptor(UserCustomerDataAdaptor):
month_result
.
sort_values
(
by
=
"datetime"
,
inplace
=
True
)
report_data
[
"month_return"
]
=
month_result
#
amount_df
[
"date"
]
=
amount_df
.
index
grouped_amount
=
amount_df
.
groupby
(
amount_df
[
"date"
]
.
apply
(
year_month
))
month_amount
=
grouped_amount
.
last
()
del
month_amount
[
"date"
]
month_amount_sum
=
month_amount
.
sum
(
axis
=
1
)
# 月度回报表格数据
start_year
=
self
.
start_date
.
year
now_year
=
datetime
.
datetime
.
now
()
.
year
month_return_data_dict
=
{}
for
i
in
range
(
now_year
-
start_year
+
1
):
month_return_data_dict
[
start_year
+
i
]
=
{
j
+
1
:
{
"profit"
:
0
,
"net_amount"
:
0
}
for
j
in
range
(
12
)}
for
d_index
,
d_row
in
month_sum
.
items
():
cur_year
=
int
(
d_index
[:
4
])
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
# 组合月度回报表
report_data
[
"month_return_data_dict"
]
=
month_return_data_dict
# # 贡献分解
# month_earn = sum_group.div(month_sum, axis='rows')
...
...
@@ -296,7 +320,7 @@ class UserCustomerResultAdaptor(UserCustomerDataAdaptor):
index_result
=
self
.
signal_fund_profit_result
(
index_df
[
index_df
.
index
>=
pd
.
to_datetime
(
first_trade_date
)],
"index"
)
report_data
[
"index_result"
]
=
index_result
self
.
__month_return
(
)
# self.__month_return(cur_folio_result_cnav_data, fund_id_list
)
self
.
total_result_data
=
report_data
return
report_data
...
...
@@ -490,6 +514,12 @@ class UserCustomerResultAdaptor(UserCustomerDataAdaptor):
def
get_group_data
(
self
):
return
self
.
group_result_data
def
__month_return
(
self
):
pass
# def __month_return(self, folio_cnav_data):
# # 月度回报
# def year_month(x):
# a = x.year
# b = x.month
# return str(a) + "-" + str(b)
# p_folio_cnav_data = folio_cnav_data.copy()
# p_folio_cnav_data["date"] = p_folio_cnav_data.index
# grouped_data = p_folio_cnav_data.groupby(p_folio_cnav_data["date"].apply(year_month))
app/templates/v2/monthReportV2.html
View file @
994714cb
...
...
@@ -1008,27 +1008,27 @@
<table
class=
"tss1_table"
>
<tr>
<td>
本月涨幅:
<span
class=
"red"
>
3.99
%
</span>
本月涨幅:
<span
class=
"red"
>
{{month_rise}}
%
</span>
</td>
<td>
本月收益:
<span
class=
"green"
>
94,477
元
</span>
本月收益:
<span
class=
"green"
>
{{now_month_income}}
元
</span>
</td>
<td>
今年累计收益率:
<span
class=
"red"
>
19.32
%
</span>
今年累计收益率:
<span
class=
"red"
>
{{year_totoal_rate_of_return}}
%
</span>
</td>
<td>
今年累计收益:
<span
class=
"green"
>
172,623
元
</span>
今年累计收益:
<span
class=
"green"
>
{{now_year_income}}
元
</span>
</td>
</tr>
<tr>
<td>
成立以来累计收益率:
<span
class=
"red"
>
19.99
%
</span>
成立以来累计收益率:
<span
class=
"red"
>
{{totoal_rate_of_return}}
%
</span>
</td>
<td>
年化收益率:
<span
class=
"green"
>
56.19
%
</span>
年化收益率:
<span
class=
"green"
>
{{annualised_return}}
%
</span>
</td>
<td>
最大回撤:
<span
class=
"red"
>
19.99
%
</span>
最大回撤:
<span
class=
"red"
>
{{max_withdrawal}}
%
</span>
</td>
<td>
</td>
...
...
@@ -1044,13 +1044,13 @@
<table
class=
"tss1_table"
>
<tr>
<td>
投资成本:
<span
class=
"red"
>
1,000,000
元
</span>
投资成本:
<span
class=
"red"
>
{{cost_of_investment}}
元
</span>
</td>
<td>
期末资产:
<span
class=
"green"
>
2,000,400
元
</span>
期末资产:
<span
class=
"green"
>
{{final_balance}}
元
</span>
</td>
<td>
累计盈利:
<span
class=
"red"
>
172,623
元
</span>
累计盈利:
<span
class=
"red"
>
{{total_profit}}
元
</span>
</td>
<td>
</td>
...
...
app/utils/html_to_pdf.py
View file @
994714cb
...
...
@@ -23,8 +23,8 @@ def html_to_pdf(source_path, target_path):
'margin-bottom'
:
'0mm'
,
'margin-left'
:
'0mm'
}
#
pdfkit.from_string(source_path, target_path, options=options)
pdfkit
.
from_file
(
source_path
,
target_path
,
options
=
options
)
pdfkit
.
from_string
(
source_path
,
target_path
,
options
=
options
)
#
pdfkit.from_file(source_path, target_path, options=options)
def
merge_pdf
(
pdfFiles
,
target_file
=
'/Users/pengxiong/Desktop/combine.pdf'
):
""""""
...
...
@@ -40,5 +40,5 @@ def merge_pdf(pdfFiles, target_file='/Users/pengxiong/Desktop/combine.pdf'):
if
__name__
==
'__main__'
:
html_to_pdf
(
'/Users/pengxiong/Desktop/fund_report/app/
templates
/v2/monthReportV2.html'
,
'/Users/pengxiong/Desktop/fund_report/app/pdf/
%
s.pdf'
%
str
(
uuid
.
uuid4
()))
html_to_pdf
(
'/Users/pengxiong/Desktop/fund_report/app/
html
/v2/monthReportV2.html'
,
'/Users/pengxiong/Desktop/fund_report/app/pdf/
%
s.pdf'
%
str
(
uuid
.
uuid4
()))
# merge_pdf(['/Users/pengxiong/Desktop/out1.pdf', '/Users/pengxiong/Desktop/out.pdf'])
app/utils/jinjia2html.py
View file @
994714cb
import
time
import
uuid
from
jinja2
import
PackageLoader
,
Environment
...
...
@@ -9,6 +10,7 @@ import numpy as np
# 准备数据
from
app.utils.draw
import
draw_month_return_chart
,
draw_contribution_chart
,
draw_combination_chart
,
\
draw_old_combination_chart
from
app.utils.html_to_pdf
import
html_to_pdf
from
app.utils.radar_chart
import
gen_radar_chart
...
...
@@ -137,8 +139,8 @@ class DataIntegrate:
"""目标与业绩"""
self
.
now_month_income
=
int
(
group_result
[
"cur_month_profit"
])
# 本月收益
self
.
now_year_income
=
int
(
group_result
[
"cur_year_profit"
])
# 今年累计收益
self
.
totoal_rate_of_return
=
round
((
group_result
[
'cumulative_return'
]
-
1
)
*
100
,
2
)
# 累计收益率
self
.
month_rise
=
round
(
group_result
[
"cur_month_profit_ratio"
]
*
100
,
2
)
# 本月涨幅
self
.
totoal_rate_of_return
=
round
((
group_result
[
'cumulative_return'
]
-
1
)
*
100
,
2
)
#
成立以来
累计收益率
self
.
month_rise
=
round
(
group_result
[
"cur_month_profit_ratio"
]
*
100
,
2
)
# 本月涨幅
s
self
.
year_totoal_rate_of_return
=
round
(
group_result
[
"cur_year_profit_ratio"
]
*
100
,
2
)
# 今年累计收益率
self
.
annualised_return
=
round
(
group_result
[
"return_ratio_year"
]
*
100
,
2
)
# 年化收益率
self
.
volatility
=
round
(
group_result
[
"volatility"
]
*
100
,
2
)
...
...
@@ -210,9 +212,12 @@ class DataIntegrate:
# with open(save_file, 'w', encoding="utf-8") as f:
# f.write(monthReport_html)
save_file
=
"app/html/v2/monthReportV2.html"
with
open
(
save_file
,
'w'
,
encoding
=
"utf-8"
)
as
f
:
f
.
write
(
monthReport_html
)
# save_file = "app/html/v2/monthReportV2.html"
# with open(save_file, 'w', encoding="utf-8") as f:
# f.write(monthReport_html)
html_to_pdf
(
monthReport_html
,
'/Users/pengxiong/Desktop/fund_report/app/pdf/
%
s.pdf'
%
str
(
uuid
.
uuid4
()))
if
__name__
==
'__main__'
:
start
=
time
.
time
()
...
...
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