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
7cca54ea
Commit
7cca54ea
authored
Dec 04, 2020
by
赵杰
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
调仓建议,指标对比
parent
1bc1d63c
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
52 additions
and
45 deletions
+52
-45
portfolio_diagnose.py
app/service/portfolio_diagnose.py
+15
-5
monthReport.html
app/templates/monthReport.html
+31
-38
jinjia2html.py
app/utils/jinjia2html.py
+6
-2
No files found.
app/service/portfolio_diagnose.py
View file @
7cca54ea
...
...
@@ -702,12 +702,14 @@ class PortfolioDiagnose(object):
suggestions
[
"before_optimization"
]
=
0
suggestions
[
"after_optimization"
]
=
value
[
"asset"
]
suggestions_result
[
key
][
suggestions
[
"fund_name"
]]
=
suggestions
for
key
,
value
in
suggestions_result
.
items
():
suggestions_result
[
key
]
=
list
(
value
.
values
())
suggestions_result_asset
=
{
"before"
:
total_asset
,
"after"
:
total_asset
}
# 旧组合累积收益
# 旧组合累积收益
df
old_return_df
=
group_result_data
[
"return_df"
]
old_return_df
[
"cum_return_ratio"
]
=
old_return_df
[
"cum_return_ratio"
]
-
1
# 新组合累积收益
# 新组合累积收益
df
propose_fund_return_limit_data
=
propose_fund_return
[
propose_fund_return
.
index
>=
group_order_start_date
]
start_return
=
propose_fund_return_limit_data
[
'return'
]
.
values
[
0
]
propose_fund_return_limit_data
[
"new_return"
]
=
(
propose_fund_return_limit_data
[
"return"
]
-
start_return
)
/
(
1
+
start_return
)
...
...
@@ -716,13 +718,15 @@ class PortfolioDiagnose(object):
start_index_return
=
index_return
[
" close"
]
.
values
[
0
]
index_return
[
"new_index_return"
]
=
(
index_return
[
" close"
]
-
start_index_return
)
/
(
1
+
start_index_return
)
# 新组合累积收益
new_return_ratio
=
propose_fund_return_limit_data
[
"new_return"
]
.
values
[
-
1
]
# 新组合区间年化收益率
freq_max
=
group_order_df
[
"freq"
]
.
max
()
n_freq
=
freq_days
(
int
(
freq_max
))
new_return_ratio_year
=
annual_return
(
propose_fund_return_limit_data
[
"new_return"
]
.
values
[
-
1
],
propose_fund_return_limit_data
,
n_freq
)
# 新组合波动率
new_volatility
_
=
volatility
(
propose_fund_return_limit_data
[
"new_return"
]
+
1
,
n_freq
)
new_volatility
=
volatility
(
propose_fund_return_limit_data
[
"new_return"
]
+
1
,
n_freq
)
# 新组合最大回撤
new_drawdown
=
max_drawdown
(
propose_fund_return_limit_data
[
"new_return"
]
+
1
)
...
...
@@ -732,7 +736,13 @@ class PortfolioDiagnose(object):
exc
=
excess_return
(
sim
,
BANK_RATE
,
n_freq
)
new_sharpe
=
sharpe_ratio
(
exc
,
sim
,
n_freq
)
propose_fund_id_list_name
=
[]
# 基金名称,策略分级
# 指标对比
odl_indicator
=
{
"group_name"
:
"现有持仓组合"
,
"return_ratio"
:
round
((
old_return
-
1
)
*
100
,
2
),
"return_ratio_year"
:
round
(
old_return_ratio_year
*
100
,
2
),
"volatility"
:
round
(
old_volatility
*
100
,
2
),
"max_drawdown"
:
round
(
old_max_drawdown
[
0
]
*
100
,
2
),
"sharpe"
:
round
(
old_sharpe
,
2
)}
new_indicator
=
{
"group_name"
:
"建议优化组合"
,
"return_ratio"
:
round
(
new_return_ratio
*
100
,
2
),
"return_ratio_year"
:
round
(
new_return_ratio_year
*
100
,
2
),
"volatility"
:
round
(
new_volatility
*
100
,
2
),
"max_drawdown"
:
round
(
new_drawdown
[
0
]
*
100
,
2
),
"sharpe"
:
round
(
new_sharpe
,
2
)}
indicator_compare
=
[
new_indicator
,
odl_indicator
]
sentence
=
"在保留{}的基础上,建议赎回{},并增配{}后,整体组合波动率大幅降低,最大回撤从{}降到不足{},年化收益率提升{}个点"
hold_fund
=
set
(
self
.
portfolio
)
-
set
(
self
.
abandon_fund_score
+
self
.
abandon_fund_corr
)
...
...
@@ -750,7 +760,7 @@ class PortfolioDiagnose(object):
sentence
.
join
(
"整体组合波动率大幅降低,"
)
if
new_return_ratio_year
>
old_return_ratio_year
:
sentence
.
join
(
"年化收益率提升{}个点。"
.
format
(
round
(
new_return_ratio_year
-
old_return_ratio_year
,
1
)))
return
suggestions_result
,
suggestions_result_asset
,
sentence
return
suggestions_result
,
suggestions_result_asset
,
indicator_compare
,
sentence
def
single_evaluation
(
self
,
fund_id
):
"""
...
...
app/templates/monthReport.html
View file @
7cca54ea
...
...
@@ -2561,26 +2561,26 @@
<th>
优化前(万元)
</th>
<th>
优化后(万元)
</th>
</tr>
<!-- <dl>-->
{% for key, value in suggestions_result.items() %}
{% for i in range(value|length) %}
<tr>
<td
rowspan=
"3"
>
宏观策略
</td>
<td>
半夏宏观对冲
</td>
<td
class=
"font_red"
>
200
</td>
<td
class=
"font_green"
>
1000
</td>
</tr>
<tr>
<td>
半夏宏观对冲
</td>
<td
class=
"font_red"
>
200
</td>
<td
class=
"font_green"
>
1000
</td>
</tr>
<tr>
<td>
半夏宏观对冲
</td>
<td
class=
"font_red"
>
200
</td>
<td
class=
"font_green"
>
1000
</td>
{% if i == 0%}
<td
rowspan=
{{value|length
}}
>
{{key}}
</td>
{% endif %}
<td>
{{value[i]["fund_name"]}}
</td>
<td
class=
"font_red"
>
{{value[i]["before_optimization"]}}
</td>
<td
class=
"font_green"
>
{{value[i]["after_optimization"]}}
</td>
</tr>
{% endfor %}
{% endfor %}
<tr>
<td
colspan=
"2"
class=
"back_gray font_bold"
>
总市值(万元)
</td>
<td
class=
"font_bold"
>
1200
</td>
<td
class=
"font_bold"
>
1000
</td>
<td
class=
"font_bold"
>
{{suggestions_result_asset["before"]}}
</td>
<td
class=
"font_bold"
>
{{suggestions_result_asset["after"]}}
</td>
</tr>
</table>
...
...
@@ -2721,30 +2721,23 @@
<th>
最大回撤(%)
</th>
<th>
夏普比率
</th>
</tr>
{%for i in range(indicator_compare|length)%}
{%if i
<
(
indicator_compare
|
length
)
-1
%}
{%
if
i
%
2=
=0
%}
<
tr
class=
"back_yellow1"
>
<td>
建议优化组合
</td>
<td>
5.75
</td>
<td>
0.40
</td>
<td>
2.29
</td>
<td>
2.15
</td>
<td>
3.05
</td>
</tr>
{%endif%}
{%if i%2==1 %}
<tr
class=
"back_yellow2"
>
<td>
建议优化组合
</td>
<td>
5.75
</td>
<td>
0.40
</td>
<td>
2.29
</td>
<td>
2.15
</td>
<td>
3.05
</td>
</tr>
<tr>
<td>
现有持仓组合
</td>
<td>
5.75
</td>
<td>
0.40
</td>
<td>
2.29
</td>
<td>
2.15
</td>
<td>
3.05
</td>
{%endif%}
{%endif%}
<td>
{{indicator_compare[i]["group_name"]}}
</td>
<td>
{{indicator_compare[i]["return_ratio"]}}
</td>
<td>
{{indicator_compare[i]["return_ratio_year"]}}
</td>
<td>
{{indicator_compare[i]["volatility"]}}
</td>
<td>
{{indicator_compare[i]["max_drawdown"]}}
</td>
<td>
{{indicator_compare[i]["sharpe"]}}
</td>
</tr>
{%endfor%}
</table>
<div
class=
"aim_foot"
>
...
...
@@ -2761,7 +2754,7 @@
<div
class=
"all_item"
>
<div
class=
"all_dot"
></div>
<div
class=
"all_text"
>
在保留综合性基金(富国创新,鹏华匠心,汇添富中盘)并增配申毅套利基金后,整体组合的波动率大幅降低,最大回撤从26%降到不足4%,年化收益提升1个点。
{{new_group_evaluation}}
</div>
</div>
</div>
...
...
app/utils/jinjia2html.py
View file @
7cca54ea
...
...
@@ -76,7 +76,8 @@ class DataIntegrate:
# 调仓建议
def
get_transfer_suggestions
(
self
):
self
.
suggestions_result
,
self
.
suggestions_result_asset
=
portfolio_diagnose
.
new_evaluation
(
"default"
,
self
.
d
,
self
.
user_customer
)
self
.
suggestions_result
,
self
.
suggestions_result_asset
,
\
self
.
indicator_compare
,
self
.
new_group_evaluation
=
portfolio_diagnose
.
new_evaluation
(
"default"
,
self
.
d
,
self
.
user_customer
)
# 收益比较
...
...
@@ -161,7 +162,10 @@ class DataIntegrate:
'old_correlation'
:
self
.
old_correlation
,
'propose_fund_data_list'
:
self
.
propose_fund_data_list
,
'suggestions_result'
:
self
.
suggestions_result
,
'suggestions_result_asset'
:
self
.
suggestions_result_asset
'suggestions_result_asset'
:
self
.
suggestions_result_asset
,
'indicator_compare'
:
self
.
indicator_compare
,
'new_group_evaluation'
:
self
.
new_group_evaluation
}
# 开始渲染html模板
env
=
Environment
(
loader
=
PackageLoader
(
'app'
,
'templates'
))
# 创建一个包加载器对象
...
...
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