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
b04cf3b2
Commit
b04cf3b2
authored
Dec 03, 2020
by
李宗熹
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
评价修改
parent
f73b3277
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
23 deletions
+28
-23
portfolio_diagnose.py
app/service/portfolio_diagnose.py
+28
-23
No files found.
app/service/portfolio_diagnose.py
View file @
b04cf3b2
...
...
@@ -233,7 +233,7 @@ def get_radar_data(fund):
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
},
...
...
@@ -285,7 +285,8 @@ class PortfolioDiagnose(object):
self
.
end_date
=
end_date
if
self
.
end_date
is
None
:
self
.
end_date
=
datetime
.
datetime
.
now
()
-
datetime
.
timedelta
(
days
=
1
)
self
.
end_date
=
datetime
.
datetime
(
datetime
.
date
.
today
()
.
year
,
datetime
.
date
.
today
()
.
month
,
1
)
-
datetime
.
timedelta
(
1
)
self
.
start_date
=
cal_date
(
self
.
end_date
,
'Y'
,
1
)
self
.
replace_pair
=
dict
()
# 由于数据不足半年而被替换为相同基金经理和策略的原基金和替换基金的映射
...
...
@@ -534,9 +535,7 @@ class PortfolioDiagnose(object):
index_return
=
index_data
.
iloc
[:,
:]
/
index_data
.
iloc
[
0
,
:]
-
1
# origin_fund_return = origin_portfolio.iloc[:, :] / origin_portfolio.iloc[0, :] - 1
propose_fund_return
=
propose_portfolio
.
iloc
[:,
:]
/
propose_portfolio
.
iloc
[
0
,
:]
-
1
print
(
self
.
new_weights
)
propose_fund_return
[
'return'
]
=
propose_fund_return
.
T
.
iloc
[:,
:]
.
apply
(
lambda
x
:
np
.
dot
(
self
.
new_weights
,
x
))
propose_fund_return
.
to_csv
(
'new_port.csv'
,
encoding
=
'gbk'
)
return
index_return
,
propose_fund_return
def
old_evaluation
(
self
,
group_name
,
group_result
,
data_adaptor
):
...
...
@@ -548,9 +547,9 @@ class PortfolioDiagnose(object):
past_month
=
(
current_year
-
start_year
)
*
12
+
current_month
-
start_month
# 投入成本(万元)
input_cost
=
round
(
group_result
[
group_name
][
"total_cost"
]
/
10000
,
2
)
input_cost
=
round
(
group_result
[
group_name
][
"total_cost"
]
/
10000
,
2
)
# 整体盈利(万元)
total_profit
=
round
(
group_result
[
group_name
][
"cumulative_profit"
]
/
10000
,
2
)
total_profit
=
round
(
group_result
[
group_name
][
"cumulative_profit"
]
/
10000
,
2
)
# 整体表现 回撤能力
fund_rank_data
=
fund_rank
[
fund_rank
[
"fund_id"
]
.
isin
(
self
.
portfolio
)]
z_score
=
fund_rank_data
[
"z_score"
]
.
mean
()
...
...
@@ -671,11 +670,13 @@ class PortfolioDiagnose(object):
propose_fund_df
=
product_df
[
product_df
[
"fund_id"
]
.
isin
(
propose_fund_id_list
)]
propose_fund_id_list_name
=
[]
# 基金名称,策略分级
# hold_fund = set(self.portfolio) - set(self.abandon_fund)
# abandon_fund = self.abandon_fund
# proposal_fund = self.proposal_fund
# data = [hold_fund, abandon_fund, proposal_fund]
# return data
sentence
=
"在保留{}的基础上,建议赎回{},并增配{}后,整体组合波动率大幅降低,最大回撤从{}降到不足{},年化收益率提升{}个点"
hold_fund
=
""
.
join
(
set
(
self
.
portfolio
)
-
set
(
self
.
abandon_fund_score
+
self
.
abandon_fund_corr
))
abandon_fund
=
""
.
join
(
self
.
abandon_fund_score
+
self
.
abandon_fund_corr
)
proposal_fund
=
""
.
join
(
self
.
proposal_fund
)
data
=
[
hold_fund
,
abandon_fund
,
proposal_fund
,
old_max_drawdown
]
return
sentence
%
data
def
single_evaluation
(
self
,
fund_id
):
"""
...
...
@@ -779,12 +780,16 @@ class PortfolioDiagnose(object):
ret
=
[]
i
=
1
for
k
,
v
in
evaluation
.
items
():
print
(
k
,
v
)
single_sentence
=
str
(
i
)
+
"."
+
sentence
[
k
]
%
translate_single
(
content
,
k
,
v
)
single_sentence
=
str
(
i
)
+
"、"
+
sentence
[
k
]
%
translate_single
(
content
,
k
,
v
)
ret
.
append
(
single_sentence
)
i
+=
1
fund_name
=
get_fund_name
(
fund_id
)
.
values
[
0
][
0
]
return
{
'name'
:
fund_name
,
'data'
:
ret
}
evaluation_dict
=
{
'name'
:
fund_name
,
'data'
:
ret
}
if
fund_id
in
self
.
abandon_fund_score
+
self
.
abandon_fund_corr
:
evaluation_dict
[
'status'
]
=
"换仓"
elif
fund_id
in
self
.
portfolio
:
evaluation_dict
[
'status'
]
=
"保留"
return
evaluation_dict
def
old_portfolio_evaluation
(
self
,
):
result
=
[]
...
...
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