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
40a4da53
Commit
40a4da53
authored
Dec 10, 2020
by
pengxiong
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'dev' of
http://47.100.44.39:10001/pengxiong/fund_report
into dev
parents
e7123994
0520154c
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
87 additions
and
10 deletions
+87
-10
portfolio_diagnose.py
app/service/portfolio_diagnose.py
+15
-0
draw.py
app/utils/draw.py
+51
-0
jinjia2html_v2.py
app/utils/jinjia2html_v2.py
+21
-10
No files found.
app/service/portfolio_diagnose.py
View file @
40a4da53
...
@@ -1165,6 +1165,21 @@ class PortfolioDiagnose(object):
...
@@ -1165,6 +1165,21 @@ class PortfolioDiagnose(object):
radar_data
.
append
(
get_radar_data
(
fund
))
radar_data
.
append
(
get_radar_data
(
fund
))
return
radar_data
return
radar_data
def
original_fund_index_compare
(
self
,
total_fund_cnav_df
):
compare_data
=
[]
for
fund
in
self
.
portfolio
:
data_df
=
total_fund_cnav_df
[[
fund
,
"index"
]]
.
dropna
()
data_df
[
fund
+
"_return_ratio"
]
=
(
data_df
[
fund
]
/
data_df
[
fund
]
.
iloc
[
0
]
-
1
)
*
100
data_df
[
"index_return_ratio"
]
=
(
data_df
[
"index"
]
/
data_df
[
"index"
]
.
iloc
[
0
]
-
1
)
*
100
xlabels
=
[
""
for
i
in
range
(
len
(
data_df
))]
com_data
=
{
"xlabels"
:
xlabels
,
"index"
:
{
'name'
:
'中证500'
,
'data'
:
data_df
[
"index_return_ratio"
]
.
values
},
"fund"
:
{
'name'
:
fund
,
'data'
:
data_df
[
fund
+
"_return_ratio"
]
.
values
},
}
compare_data
.
append
(
com_data
)
return
compare_data
# portfolio = ['HF00002JJ2', 'HF00005DBQ', 'HF0000681Q', 'HF00006693', 'HF00006AZF', 'HF00006BGS']
# portfolio = ['HF00002JJ2', 'HF00005DBQ', 'HF0000681Q', 'HF00006693', 'HF00006AZF', 'HF00006BGS']
# portfolio_diagnose = PortfolioDiagnose(client_type=1, portfolio=portfolio, invest_amount=10000000)
# portfolio_diagnose = PortfolioDiagnose(client_type=1, portfolio=portfolio, invest_amount=10000000)
...
...
app/utils/draw.py
View file @
40a4da53
...
@@ -342,6 +342,57 @@ def draw_combination_chart(xlabels, new_combination, origin_combination, index):
...
@@ -342,6 +342,57 @@ def draw_combination_chart(xlabels, new_combination, origin_combination, index):
return
return_compare_img
return
return_compare_img
def
draw_index_combination_chart
(
compare_data
):
"""基金和指数对比图"""
xlabels
,
origin_combination
,
index
=
compare_data
[
"xlabels"
],
compare_data
[
"fund"
],
compare_data
[
"index"
]
figsize
=
(
20
,
12
)
# 标签文字大小
fontsize
=
22
# 初始化
fig
=
plt
.
figure
(
figsize
=
figsize
)
ax1
=
fig
.
add_subplot
(
111
)
ax3
=
ax1
.
twiny
()
ax1
.
spines
[
'top'
]
.
set_visible
(
False
)
ax1
.
spines
[
'right'
]
.
set_visible
(
False
)
ax1
.
spines
[
'bottom'
]
.
set_visible
(
False
)
ax1
.
spines
[
'left'
]
.
set_visible
(
False
)
ax3
.
spines
[
'top'
]
.
set_visible
(
False
)
ax3
.
spines
[
'right'
]
.
set_visible
(
False
)
ax3
.
spines
[
'bottom'
]
.
set_visible
(
False
)
ax3
.
spines
[
'left'
]
.
set_visible
(
False
)
# ax = plt.gca() # gca:get current axis得到当前轴
# ax.spines['bottom'].set_position(('data', 0)) # data表示通过值来设置x轴的位置,将x轴绑定在y=0的位置
product_list
=
[
origin_combination
,
index
]
max_x_count
=
max
([
x
[
'data'
]
.
size
for
x
in
product_list
])
loc
=
np
.
arange
(
max_x_count
)
# the x locations for the groups
# 坐标轴
ax1
.
tick_params
(
labelsize
=
fontsize
)
ax3
.
tick_params
(
labelsize
=
fontsize
)
ax1
.
set_xticks
(
loc
)
ax1
.
set_xticklabels
(
xlabels
)
# ax1.yaxis.set_major_formatter(FuncFormatter(to_percent))
ax1
.
set_yticks
([])
ax3
.
set_yticks
([])
ax3
.
set_xticks
([])
ax1
.
axis
(
'off'
)
ax3
.
axis
(
'off'
)
# 基金折线图
ax1
.
plot
(
loc
,
origin_combination
[
'data'
],
color
=
'#D40000'
,
marker
=
''
,
linewidth
=
3
)
ax1
.
legend
(
loc
=
'upper left'
,
fontsize
=
fontsize
)
# 指数折线图
ax3
.
plot
(
loc
,
index
[
'data'
],
color
=
'grey'
,
marker
=
''
,
linewidth
=
3
)
ax3
.
legend
(
loc
=
'upper right'
,
fontsize
=
fontsize
)
# plt.show()
imgdata
=
BytesIO
()
fig
.
savefig
(
imgdata
,
format
=
'png'
,
bbox_inches
=
'tight'
)
imgdata
.
seek
(
0
)
# rewind the data
return_compare_img
=
'data:image/png;base64,'
+
base64
.
b64encode
(
imgdata
.
getvalue
())
.
decode
(
'utf-8'
)
return
return_compare_img
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
# xlabels = ('2020-1', '2020-2', '2020-3', '2020-4', '2020-5', '2020-6', '2020-7', '2020-8', '2020-9', '2020-10', '2020-11', '2020-12')
# xlabels = ('2020-1', '2020-2', '2020-3', '2020-4', '2020-5', '2020-6', '2020-7', '2020-8', '2020-9', '2020-10', '2020-11', '2020-12')
# product = {'name': '月度回报率', 'data': np.array([10, 20, 30, 40, 50, 10, 20, 30, 40, 50, 40, 50])}
# product = {'name': '月度回报率', 'data': np.array([10, 20, 30, 40, 50, 10, 20, 30, 40, 50, 40, 50])}
...
...
app/utils/jinjia2html_v2.py
View file @
40a4da53
...
@@ -12,7 +12,7 @@ import os
...
@@ -12,7 +12,7 @@ import os
# 准备数据
# 准备数据
from
app.utils.draw
import
draw_month_return_chart
,
draw_contribution_chart
,
draw_combination_chart
,
\
from
app.utils.draw
import
draw_month_return_chart
,
draw_contribution_chart
,
draw_combination_chart
,
\
draw_old_combination_chart
draw_old_combination_chart
,
draw_index_combination_chart
from
app.utils.html_to_pdf
import
html_to_pdf
from
app.utils.html_to_pdf
import
html_to_pdf
from
app.utils.radar_chart
import
gen_radar_chart
from
app.utils.radar_chart
import
gen_radar_chart
...
@@ -48,7 +48,15 @@ class DataIntegrate:
...
@@ -48,7 +48,15 @@ class DataIntegrate:
def
get_group_result
(
self
):
def
get_group_result
(
self
):
for
group_name
,
group_result
in
self
.
d
.
items
():
for
group_name
,
group_result
in
self
.
d
.
items
():
portfolio_diagnose
=
self
.
get_portfolio_diagnose
(
group_result
[
"fund_id_list"
],
invest_amount
=
group_result
[
"total_cost"
])
portfolio_diagnose
=
self
.
get_portfolio_diagnose
(
group_result
[
"fund_id_list"
],
invest_amount
=
group_result
[
"total_cost"
])
cur_group_portfolio_result
=
{}
cur_group_portfolio_result
=
{
'new_correlation'
:
[],
'propose_fund_data_list'
:
[],
'suggestions_result'
:
{},
'suggestions_result_asset'
:
{},
'return_compare_pic'
:
[],
'indicator_compare'
:
[],
'new_group_evaluation'
:
[]
}
# 旧持仓组合点评
# 旧持仓组合点评
self
.
comments_on_position_portfolio
(
portfolio_diagnose
,
group_name
,
cur_group_portfolio_result
)
self
.
comments_on_position_portfolio
(
portfolio_diagnose
,
group_name
,
cur_group_portfolio_result
)
...
@@ -62,12 +70,12 @@ class DataIntegrate:
...
@@ -62,12 +70,12 @@ class DataIntegrate:
self
.
get_old_compare_pic
(
cur_group_portfolio_result
)
self
.
get_old_compare_pic
(
cur_group_portfolio_result
)
# 旧相关性
# 旧相关性
self
.
get_old_correlation
(
portfolio_diagnose
,
cur_group_portfolio_result
)
self
.
get_old_correlation
(
portfolio_diagnose
,
cur_group_portfolio_result
)
# # 新增基金
# #
#
新增基金
self
.
propose_fund
(
portfolio_diagnose
,
cur_group_portfolio_result
)
#
self.propose_fund(portfolio_diagnose, cur_group_portfolio_result)
# # 新收益比较
# #
#
新收益比较
self
.
get_transfer_suggestions
(
portfolio_diagnose
,
group_name
,
cur_group_portfolio_result
)
#
self.get_transfer_suggestions(portfolio_diagnose, group_name, cur_group_portfolio_result)
# # 新相关性
# #
#
新相关性
self
.
get_new_correlation
(
portfolio_diagnose
,
cur_group_portfolio_result
)
#
self.get_new_correlation(portfolio_diagnose, cur_group_portfolio_result)
self
.
all_folio_result
[
group_name
]
=
cur_group_portfolio_result
self
.
all_folio_result
[
group_name
]
=
cur_group_portfolio_result
...
@@ -117,9 +125,12 @@ class DataIntegrate:
...
@@ -117,9 +125,12 @@ class DataIntegrate:
"""个基点评."""
"""个基点评."""
single_fund_data_list
=
[]
single_fund_data_list
=
[]
portfolio_evaluation
=
portfolio_diagnose
.
old_portfolio_evaluation
()
portfolio_evaluation
=
portfolio_diagnose
.
old_portfolio_evaluation
()
radar_chart_data
=
portfolio_diagnose
.
single_fund_radar
()
# radar_chart_data = portfolio_diagnose.single_fund_radar()
# with futures.ProcessPoolExecutor(os.cpu_count()) as executor:
# res = executor.map(gen_radar_chart, radar_chart_data)
index_compare_chart_data
=
portfolio_diagnose
.
original_fund_index_compare
(
self
.
user_customer
.
fund_cnav_total
)
with
futures
.
ProcessPoolExecutor
(
os
.
cpu_count
())
as
executor
:
with
futures
.
ProcessPoolExecutor
(
os
.
cpu_count
())
as
executor
:
res
=
executor
.
map
(
gen_radar_chart
,
radar
_chart_data
)
res
=
executor
.
map
(
draw_index_combination_chart
,
index_compare
_chart_data
)
res
=
list
(
res
)
res
=
list
(
res
)
for
i
in
range
(
len
(
portfolio_evaluation
)):
for
i
in
range
(
len
(
portfolio_evaluation
)):
if
portfolio_evaluation
[
i
][
'status'
]
==
'保留'
:
if
portfolio_evaluation
[
i
][
'status'
]
==
'保留'
:
...
...
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