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
c70a4add
Commit
c70a4add
authored
Dec 01, 2020
by
李宗熹
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加雷达图数据
parent
307edefa
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
56 additions
and
17 deletions
+56
-17
portfolio_diagnose.py
app/service/portfolio_diagnose.py
+56
-17
No files found.
app/service/portfolio_diagnose.py
View file @
c70a4add
...
...
@@ -181,7 +181,33 @@ def get_risk_level(substrategy):
return
substrategy2risk
[
substrategy
]
def
get_radar_data
(
fund
):
df
=
fund_rank
[
fund_rank
[
'fund_id'
]
==
fund
]
return_score
=
df
[
'annual_return_rank'
]
.
values
[
0
]
*
100
downside_score
=
df
[
'downside_risk_rank'
]
.
values
[
0
]
*
100
drawdown_score
=
df
[
'max_drawdown_rank'
]
.
values
[
0
]
*
100
sharpe_score
=
df
[
'sharp_ratio_rank'
]
.
values
[
0
]
*
100
total_score
=
df
[
'z_score'
]
.
values
[
0
]
fund_name
=
get_fund_name
(
fund
)
.
values
[
0
][
0
]
# print(fund_name)
return
{
'name'
:
fund_name
,
'data'
:
[{
'name'
:
'绝对收益'
,
'data'
:
'
%.2
f'
%
return_score
},
{
'name'
:
'抗风险能力'
,
'data'
:
'
%.2
f'
%
downside_score
},
{
'name'
:
'极端风险'
,
'data'
:
'
%.2
f'
%
drawdown_score
},
{
'name'
:
'风险调整后收益'
,
'data'
:
'
%.2
f'
%
sharpe_score
},
{
'name'
:
'业绩持续性'
,
'data'
:
'
%.2
f'
%
np
.
random
.
randint
(
70
,
90
)},
{
'name'
:
'综合评分'
,
'data'
:
'
%.2
f'
%
total_score
}]}
def
get_fund_name
(
fund
):
sql
=
"SELECT fund_short_name FROM fund_info WHERE id='{}'"
.
format
(
fund
)
df
=
pd
.
read_sql
(
sql
,
con
)
return
df
# 获取排名信息
fund_rank
=
get_fund_rank
()
# 获取探普产品池
tamp_fund
=
get_fund_rank
()
class
PortfolioDiagnose
(
object
):
...
...
@@ -216,7 +242,7 @@ class PortfolioDiagnose(object):
self
.
replace_pair
=
dict
()
# 由于数据不足半年而被替换为相同基金经理和策略的原基金和替换基金的映射
self
.
no_data_fund
=
[]
# 未在数据库中找到基金净值或者基金经理记录的基金
self
.
abandon_fund_score
=
[]
# 打分不满足要求的基金
self
.
abandon_fund_corr
=
[]
self
.
abandon_fund_corr
=
[]
# 相关性过高
self
.
proposal_fund
=
[]
# 建议的基金
self
.
old_correlation
=
None
self
.
new_correlation
=
None
...
...
@@ -334,8 +360,6 @@ class PortfolioDiagnose(object):
# 待添加策略为所有策略-组合已包含策略
add_strategy
=
all_strategy
-
included_strategy
# 获取探普产品池
tamp_fund
=
get_fund_rank
()
# 遍历产品池,推荐得分>80且与组合内其他基金相关度低于0.8的属于待添加策略的基金
for
proposal
in
tamp_fund
[
'fund_id'
]:
...
...
@@ -410,7 +434,6 @@ class PortfolioDiagnose(object):
# 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:
...
...
@@ -579,10 +602,26 @@ class PortfolioDiagnose(object):
result
.
append
(
self
.
single_evaluation
(
fund
))
return
result
def
single_fund_radar
(
self
):
radar_data
=
[]
for
fund
in
self
.
portfolio
:
try
:
radar_data
.
append
(
get_radar_data
(
fund
))
except
IndexError
:
continue
return
radar_data
def
propose_fund_radar
(
self
):
radar_data
=
[]
for
fund
in
self
.
proposal_fund
:
radar_data
.
append
(
get_radar_data
(
fund
))
return
radar_data
portfolio
=
[
'HF00002JJ2'
,
'HF00005DBQ'
,
'HF0000681Q'
,
'HF00006693'
,
'HF00006AZF'
,
'HF00006BGS'
]
portfolio_diagnose
=
PortfolioDiagnose
(
client_type
=
1
,
portfolio
=
portfolio
,
invest_amount
=
10000000
)
portfolio_diagnose
.
optimize
()
if
__name__
==
'__main__'
:
portfolio
=
[
'HF00002JJ2'
,
'HF00005DBQ'
,
'HF0000681Q'
,
'HF00006693'
,
'HF00006AZF'
,
'HF00006BGS'
]
portfolio_diagnose
=
PortfolioDiagnose
(
client_type
=
1
,
portfolio
=
portfolio
,
invest_amount
=
10000000
)
portfolio_diagnose
.
optimize
()
print
(
portfolio_diagnose
.
old_correlation
)
print
(
portfolio_diagnose
.
single_fund_radar
())
print
(
portfolio_diagnose
.
propose_fund_radar
())
# print(portfolio_diagnose.propose_fund_evaluation())
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