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
e85fed5b
Commit
e85fed5b
authored
Dec 02, 2020
by
李宗熹
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
评价修改
parent
a12f0fb3
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
13 deletions
+21
-13
portfolio_diagnose.py
app/service/portfolio_diagnose.py
+21
-13
No files found.
app/service/portfolio_diagnose.py
View file @
e85fed5b
...
@@ -373,7 +373,7 @@ class PortfolioDiagnose(object):
...
@@ -373,7 +373,7 @@ class PortfolioDiagnose(object):
if
proposal
in
fund_rank
[
'fund_id'
]
.
to_list
():
if
proposal
in
fund_rank
[
'fund_id'
]
.
to_list
():
proposal_z_score
=
search_rank
(
fund_rank
,
proposal
,
metric
=
'z_score'
)
proposal_z_score
=
search_rank
(
fund_rank
,
proposal
,
metric
=
'z_score'
)
proposal_strategy
=
fund_rank
[
fund_rank
[
'fund_id'
]
==
proposal
][
'substrategy'
]
.
values
[
0
]
#
proposal_strategy = fund_rank[fund_rank['fund_id'] == proposal]['substrategy'].values[0]
else
:
else
:
continue
continue
...
@@ -430,24 +430,32 @@ class PortfolioDiagnose(object):
...
@@ -430,24 +430,32 @@ class PortfolioDiagnose(object):
mu
=
expected_returns
.
mean_historical_return
(
propose_portfolio
,
frequency
=
min
(
self
.
freq_list
))
mu
=
expected_returns
.
mean_historical_return
(
propose_portfolio
,
frequency
=
min
(
self
.
freq_list
))
S
=
risk_models
.
sample_cov
(
propose_portfolio
,
frequency
=
min
(
self
.
freq_list
))
S
=
risk_models
.
sample_cov
(
propose_portfolio
,
frequency
=
min
(
self
.
freq_list
))
dd
=
expected_returns
.
drawdown_from_prices
(
propose_portfolio
)
dd
=
expected_returns
.
drawdown_from_prices
(
propose_portfolio
)
# if self.client_type == 1:
# if self.client_type == 1:
# proposal_risk = [[x, get_risk_level(search_rank(fund_rank, x, metric='substrategy'))] for x in
# proposal_risk = [[x, get_risk_level(search_rank(fund_rank, x, metric='substrategy'))] for x in
# self.proposal_fund]
# propose_portfolio.columns]
# self.proposal_fund = list(filter(lambda x: x[1] != 3, proposal_risk))
# self.proposal_fund = list(filter(lambda x: x[1] != 'H', proposal_risk))
# proposal_portfolio = list((set(self.portfolio) - set(self.no_data_fund) - set(self.replace_pair.keys())) | \
# (set(self.proposal_fund) | set(self.replace_pair.values())))
# drop_fund_list = list(filter(lambda x: x[1] = 'H', proposal_risk))
# proposal_portfolio = list((set(self.portfolio) - set(self.no_data_fund) - set(self.replace_pair.keys())) | \
# (set(self.proposal_fund) | set(self.replace_pair.values())))
# propose_portfolio.drop()
propose_risk_mapper
=
dict
()
propose_risk_mapper
=
dict
()
for
fund
in
propose_portfolio
.
columns
:
for
fund
in
propose_portfolio
.
columns
:
propose_risk_mapper
[
fund
]
=
str
(
get_risk_level
(
search_rank
(
fund_rank
,
fund
,
metric
=
'substrategy'
)))
propose_risk_mapper
[
fund
]
=
str
(
get_risk_level
(
search_rank
(
fund_rank
,
fund
,
metric
=
'substrategy'
)))
risk_upper
=
{
"H"
:
0.0
}
risk_lower
=
{
"L"
:
0.6
,
"M"
:
0.4
}
# risk_upper = {"H": 0.0}
# risk_lower = {"L": 0.6, "M": 0.4}
w_low
=
1e6
/
self
.
invest_amount
ef
=
EfficientFrontier
(
mu
,
S
,
expected_drawdown
=
dd
)
ef
=
EfficientFrontier
(
mu
,
S
,
expected_drawdown
=
dd
)
ef
.
add_sector_constraints
(
propose_risk_mapper
,
risk_lower
,
risk_upper
)
#
ef.add_sector_constraints(propose_risk_mapper, risk_lower, risk_upper)
# weights = ef.nonconvex_objective(deviation_risk_parity, ef.cov_matrix)
# weights = ef.nonconvex_objective(deviation_risk_parity, ef.cov_matrix)
ef
.
efficient_
drawdown
(
drawdown_limit
=
0.5
)
ef
.
efficient_
return
(
0.3
)
clean_weights
=
ef
.
clean_weights
()
clean_weights
=
ef
.
clean_weights
()
#
ef.portfolio_performance(verbose=True)
ef
.
portfolio_performance
(
verbose
=
True
)
self
.
new_weights
=
np
.
array
(
list
(
clean_weights
.
values
()))
self
.
new_weights
=
np
.
array
(
list
(
clean_weights
.
values
()))
print
(
clean_weights
)
print
(
clean_weights
)
end4
=
time
.
time
()
end4
=
time
.
time
()
...
@@ -607,10 +615,10 @@ class PortfolioDiagnose(object):
...
@@ -607,10 +615,10 @@ class PortfolioDiagnose(object):
else
:
else
:
evaluation
=
choose_bad_evaluation
(
data
)
evaluation
=
choose_bad_evaluation
(
data
)
ret
=
""
ret
=
[]
for
k
,
v
in
evaluation
.
items
():
for
k
,
v
in
evaluation
.
items
():
# print(translate_single(content[k], v))
# print(translate_single(content[k], v))
ret
=
ret
+
sentence
[
k
]
%
translate_single
(
content
[
k
],
v
)
ret
.
append
(
sentence
[
k
]
%
translate_single
(
content
[
k
],
v
)
)
fund_name
=
get_fund_name
(
fund_id
)
.
values
[
0
][
0
]
fund_name
=
get_fund_name
(
fund_id
)
.
values
[
0
][
0
]
return
{
'name'
:
fund_name
,
'data'
:
ret
}
return
{
'name'
:
fund_name
,
'data'
:
ret
}
...
...
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