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
f7fbc3cd
Commit
f7fbc3cd
authored
Feb 06, 2021
by
赵杰
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
新增基金的数据联动
parent
84d2e44c
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
66 additions
and
4 deletions
+66
-4
folio_comment_service.py
app/service/folio_comment_service.py
+47
-0
portfolio_diagnose.py
app/service/portfolio_diagnose.py
+16
-3
result_service_v2.py
app/service/result_service_v2.py
+2
-0
jinjia2html_v2.py
app/utils/jinjia2html_v2.py
+1
-1
No files found.
app/service/folio_comment_service.py
0 → 100644
View file @
f7fbc3cd
from
app.service.portfolio_diagnose
import
PortfolioDiagnose
from
app.service.result_service_v2
import
UserCustomerResultAdaptor
import
datetime
from
app.utils.draw
import
draw_combination_chart
def
recalculation_fund_comment
(
ifa_id
,
customer_id
,
folio
,
suggest_result
):
suggest_fund_dict
=
{}
suggest_fund_list
=
[]
suggest_amount_list
=
[]
for
key
,
value_list
in
suggest_result
.
items
():
for
value
in
value_list
:
if
value
[
"after_optimization"
]
<=
0
:
continue
suggest_fund_dict
[
value
[
"fund_id"
]]
=
value
[
"fund_type"
]
suggest_fund_list
.
append
(
value
[
"fund_id"
])
suggest_amount_list
.
append
(
value
[
"after_optimization"
])
sum_amount
=
sum
(
suggest_amount_list
)
suggest_weight_list
=
[
round
(
amount
/
sum_amount
,
4
)
for
amount
in
suggest_amount_list
]
user_customer
=
UserCustomerResultAdaptor
(
ifa_id
,
customer_id
,
end_date
=
datetime
.
datetime
.
now
()
.
strftime
(
"
%
Y-
%
m-
%
d"
))
group_result
=
user_customer
.
calculate_group_result_data
()
cur_folio_result
=
group_result
[
folio
]
portfolio_diagnose
=
PortfolioDiagnose
(
client_type
=
1
,
portfolio
=
user_customer
.
all_fund_type_dict
,
invest_amount
=
float
(
cur_folio_result
[
"total_cost"
]),
start_date
=
user_customer
.
start_date
)
portfolio_diagnose
.
proposal_customize
(
suggest_fund_list
,
suggest_weight_list
,
suggest_fund_dict
)
abandon_fund
=
list
(
set
(
cur_folio_result
[
"fund_id_list"
])
-
set
(
suggest_fund_list
))
portfolio_diagnose
.
abandon_fund_score
=
abandon_fund
finall_reslut
=
{}
finall_reslut
[
"suggestions_result"
],
finall_reslut
[
"suggestions_result_asset"
],
\
finall_reslut
[
"return_compare_data"
],
\
finall_reslut
[
"indicator_compare"
],
finall_reslut
[
"new_group_evaluation"
]
=
\
portfolio_diagnose
.
new_evaluation
(
folio
,
group_result
,
user_customer
,
suggest_fund_dict
)
finall_reslut
[
"return_compare_pic"
]
=
draw_combination_chart
(
finall_reslut
[
"return_compare_data"
][
"xlabels"
],
finall_reslut
[
"return_compare_data"
][
"new_combination"
],
finall_reslut
[
"return_compare_data"
][
"origin_combination"
],
finall_reslut
[
"return_compare_data"
][
"index"
])
return
finall_reslut
\ No newline at end of file
app/service/portfolio_diagnose.py
View file @
f7fbc3cd
...
...
@@ -737,6 +737,10 @@ class PortfolioDiagnose(object):
prod
.
ffill
(
inplace
=
True
)
prod
=
prod
[
prod
.
index
>=
self
.
start_date
]
prod
=
resample
(
prod
,
get_trade_cal
(),
min
(
self
.
freq_list
))
if
'cal_date'
in
prod
.
columns
:
prod
.
drop
(
labels
=
'cal_date'
,
inplace
=
True
,
axis
=
1
)
if
'end_date'
in
prod
.
columns
:
prod
.
drop
(
labels
=
'end_date'
,
inplace
=
True
,
axis
=
1
)
self
.
new_correlation
=
cal_correlation
(
prod
)
prod
.
dropna
(
how
=
'all'
,
inplace
=
True
)
...
...
@@ -1092,7 +1096,6 @@ class PortfolioDiagnose(object):
product_df
=
pd
.
DataFrame
(
list
(
data
)
+
list
(
data2
),
columns
=
[
'fund_id'
,
'fund_name'
,
'freq'
,
'substrategy'
])
propose_fund_df
=
product_df
[
product_df
[
"fund_id"
]
.
isin
(
propose_fund_id_list
)]
for
index
,
row
in
propose_fund_df
.
iterrows
():
if
math
.
isnan
(
row
[
"freq"
]):
propose_fund_df
.
loc
[
index
,
"freq"
]
=
2
...
...
@@ -1100,6 +1103,7 @@ class PortfolioDiagnose(object):
propose_fund_df
.
loc
[
index
,
"substrategy"
]
=
5010
# 基金名称,策略分级
propose_fund_type_list
=
[
2
for
fund_id
in
propose_fund_id_list
]
propose_fund_id_name_list
=
[
propose_fund_df
[
propose_fund_df
[
"fund_id"
]
==
fund_id
][
"fund_name"
]
.
values
[
0
]
for
...
...
@@ -1112,6 +1116,7 @@ class PortfolioDiagnose(object):
propose_fund_asset
=
[
round
(
self
.
new_weights
[
i
]
*
total_asset
,
2
)
for
i
in
range
(
len
(
propose_fund_id_name_list
))]
else
:
propose_fund_type_list
=
[
fund_tye_dict
[
fund_id
]
for
fund_id
in
propose_fund_id_list
]
propose_fund_id_name_list
=
[
get_fund_name
(
fund_id
,
fund_tye_dict
[
fund_id
])
.
values
[
0
][
0
]
for
fund_id
in
propose_fund_id_list
]
propose_fund_id_strategy_name_list
=
[
...
...
@@ -1123,7 +1128,10 @@ class PortfolioDiagnose(object):
propose_info
=
{
propose_fund_id_strategy_name_list
[
i
]:
{
"fund_name"
:
propose_fund_id_name_list
[
i
],
"substrategy"
:
propose_fund_id_strategy_name_list
[
i
],
"asset"
:
propose_fund_asset
[
i
]}
"asset"
:
propose_fund_asset
[
i
],
"fund_id"
:
propose_fund_id_list
[
i
],
"fund_type"
:
propose_fund_type_list
[
i
]
}
for
i
in
range
(
len
(
propose_fund_id_list
))}
# 调仓建议
suggestions_result
=
{}
...
...
@@ -1136,6 +1144,8 @@ class PortfolioDiagnose(object):
suggestions
[
"fund_name"
]
=
hold
[
"fund_name"
]
suggestions
[
"before_optimization"
]
=
hold
[
"market_values"
]
suggestions
[
"after_optimization"
]
=
0
suggestions
[
"fund_id"
]
=
hold
[
"fund_id"
]
suggestions
[
"fund_type"
]
=
hold
[
"fund_type"
]
if
suggestions
[
"fund_strategy_name"
]
in
propose_fund_id_strategy_name_list
:
suggestions
[
"after_optimization"
]
=
0
suggestions_result
[
hold
[
"fund_strategy_name"
]][
suggestions
[
"fund_name"
]]
=
suggestions
...
...
@@ -1149,6 +1159,8 @@ class PortfolioDiagnose(object):
suggestions
[
"fund_name"
]
=
value
[
"fund_name"
]
suggestions
[
"before_optimization"
]
=
0
suggestions
[
"after_optimization"
]
=
value
[
"asset"
]
suggestions
[
"fund_id"
]
=
value
[
"fund_id"
]
suggestions
[
"fund_type"
]
=
value
[
"fund_type"
]
suggestions_result
[
key
][
suggestions
[
"fund_name"
]]
=
suggestions
else
:
suggestions_result
[
key
][
value
[
"fund_name"
]][
"after_optimization"
]
=
value
[
"asset"
]
...
...
@@ -1235,7 +1247,8 @@ class PortfolioDiagnose(object):
hold_fund_name
=
[
get_fund_name
(
x
,
self
.
portfolio_dict
[
x
])
.
values
[
0
][
0
]
for
x
in
hold_fund
]
abandon_fund
=
(
self
.
abandon_fund_score
+
self
.
abandon_fund_corr
)
abandon_fund_name
=
[
get_fund_name
(
x
,
self
.
portfolio_dict
[
x
])
.
values
[
0
][
0
]
for
x
in
abandon_fund
]
proposal_fund
=
self
.
proposal_fund
# proposal_fund = self.proposal_fund
proposal_fund
=
[
item
for
item
in
self
.
proposal_fund
if
item
not
in
list
(
fund_tye_dict
.
keys
())]
proposal_fund_name
=
[
get_fund_name
(
x
,
fund_tye_dict
[
x
])
.
values
[
0
][
0
]
for
x
in
proposal_fund
]
sentence
=
[]
...
...
app/service/result_service_v2.py
View file @
f7fbc3cd
...
...
@@ -503,6 +503,8 @@ class UserCustomerResultAdaptor(UserCustomerDataAdaptor):
fund_hoding_info
[
"cum_profit"
]
=
"
%.2
f"
%
round
(
cum_profit
/
10000
,
2
)
# 累积收益率
fund_hoding_info
[
"cum_profit_ratio"
]
=
"
%.2
f"
%
round
(
cum_profit
/
temp_cost
*
100
,
2
)
fund_hoding_info
[
"fund_id"
]
=
cur_fund_id
fund_hoding_info
[
"fund_type"
]
=
row
[
"type"
]
cum_profit_ratio_temp
=
cum_profit
/
temp_cost
# 累积年化收益率
cur_resample_df
=
resample_df
[[
row
[
"fund_id"
]]]
...
...
app/utils/jinjia2html_v2.py
View file @
f7fbc3cd
...
...
@@ -87,7 +87,7 @@ class DataIntegrate:
self
.
all_folio_result
[
group_name
]
=
cur_group_portfolio_result
def
get_portfolio_diagnose
(
self
,
portfolio
,
client_type
=
1
,
invest_amount
=
10000000
,
weight_dict
=
{}
):
def
get_portfolio_diagnose
(
self
,
portfolio
,
client_type
=
1
,
invest_amount
=
10000000
,
weight_dict
=
None
):
if
invest_amount
<
10000000
:
invest_amount
=
10000000
folio_fund_dict
=
{}
...
...
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