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
6848b979
Commit
6848b979
authored
Dec 04, 2020
by
赵杰
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'origin/dev' into dev
parents
7ebc83ed
994714cb
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
23 additions
and
8 deletions
+23
-8
portfolio_diagnose.py
app/service/portfolio_diagnose.py
+12
-2
html_to_pdf.py
app/utils/html_to_pdf.py
+3
-3
jinjia2html.py
app/utils/jinjia2html.py
+8
-3
No files found.
app/service/portfolio_diagnose.py
View file @
6848b979
...
...
@@ -719,6 +719,13 @@ class PortfolioDiagnose(object):
index_return
=
index_return
[
index_return
.
index
>=
group_order_start_date
]
start_index_return
=
index_return
[
" close"
]
.
values
[
0
]
index_return
[
"new_index_return"
]
=
(
index_return
[
" close"
]
-
start_index_return
)
/
(
1
+
start_index_return
)
index_return_ratio
=
index_return
[
"new_index_return"
]
.
values
[
-
1
]
index_return_ratio_year
=
annual_return
(
index_return
[
"new_index_return"
]
.
values
[
-
1
],
index_return
[
"new_index_return"
],
250
)
index_volatility
=
volatility
(
index_return
[
"new_index_return"
]
+
1
,
250
)
index_drawdown
=
max_drawdown
(
index_return
[
"new_index_return"
]
+
1
)
index_sim
=
simple_return
(
propose_fund_return_limit_data
[
"new_return"
]
+
1
)
index_exc
=
excess_return
(
index_sim
,
BANK_RATE
,
250
)
index_sharpe
=
sharpe_ratio
(
index_exc
,
index_sim
,
250
)
# 新组合累积收益
new_return_ratio
=
propose_fund_return_limit_data
[
"new_return"
]
.
values
[
-
1
]
...
...
@@ -738,6 +745,7 @@ class PortfolioDiagnose(object):
exc
=
excess_return
(
sim
,
BANK_RATE
,
n_freq
)
new_sharpe
=
sharpe_ratio
(
exc
,
sim
,
n_freq
)
# 收益对比数据
return_compare_df
=
pd
.
merge
(
index_return
[[
"new_index_return"
]],
old_return_df
[[
"cum_return_ratio"
]],
right_index
=
True
,
left_index
=
True
)
...
...
@@ -754,11 +762,13 @@ class PortfolioDiagnose(object):
}
# 指标对比
o
dl
_indicator
=
{
"group_name"
:
"现有持仓组合"
,
"return_ratio"
:
round
((
old_return
-
1
)
*
100
,
2
),
"return_ratio_year"
:
round
(
old_return_ratio_year
*
100
,
2
),
o
ld
_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
]
index_indicator
=
{
"group_name"
:
"中证500"
,
"return_ratio"
:
round
(
index_return_ratio
*
100
,
2
),
"return_ratio_year"
:
round
(
index_return_ratio_year
*
100
,
2
),
"volatility"
:
round
(
index_volatility
*
100
,
2
),
"max_drawdown"
:
round
(
index_drawdown
[
0
]
*
100
,
2
),
"sharpe"
:
round
(
index_sharpe
,
2
)}
indicator_compare
=
[
new_indicator
,
old_indicator
,
index_indicator
]
# 在保留{}的基础上,建议赎回{},并增配{}后,整体组合波动率大幅降低,最大回撤从{}降到不足{},年化收益率提升{}个点
...
...
app/utils/html_to_pdf.py
View file @
6848b979
...
...
@@ -23,8 +23,8 @@ def html_to_pdf(source_path, target_path):
'margin-bottom'
:
'0mm'
,
'margin-left'
:
'0mm'
}
#
pdfkit.from_string(source_path, target_path, options=options)
pdfkit
.
from_file
(
source_path
,
target_path
,
options
=
options
)
pdfkit
.
from_string
(
source_path
,
target_path
,
options
=
options
)
#
pdfkit.from_file(source_path, target_path, options=options)
def
merge_pdf
(
pdfFiles
,
target_file
=
'/Users/pengxiong/Desktop/combine.pdf'
):
""""""
...
...
@@ -40,5 +40,5 @@ def merge_pdf(pdfFiles, target_file='/Users/pengxiong/Desktop/combine.pdf'):
if
__name__
==
'__main__'
:
html_to_pdf
(
'/Users/pengxiong/Desktop/fund_report/app/
templates
/v2/monthReportV2.html'
,
'/Users/pengxiong/Desktop/fund_report/app/pdf/
%
s.pdf'
%
str
(
uuid
.
uuid4
()))
html_to_pdf
(
'/Users/pengxiong/Desktop/fund_report/app/
html
/v2/monthReportV2.html'
,
'/Users/pengxiong/Desktop/fund_report/app/pdf/
%
s.pdf'
%
str
(
uuid
.
uuid4
()))
# merge_pdf(['/Users/pengxiong/Desktop/out1.pdf', '/Users/pengxiong/Desktop/out.pdf'])
app/utils/jinjia2html.py
View file @
6848b979
import
time
import
uuid
from
jinja2
import
PackageLoader
,
Environment
...
...
@@ -9,6 +10,7 @@ import numpy as np
# 准备数据
from
app.utils.draw
import
draw_month_return_chart
,
draw_contribution_chart
,
draw_combination_chart
,
\
draw_old_combination_chart
from
app.utils.html_to_pdf
import
html_to_pdf
from
app.utils.radar_chart
import
gen_radar_chart
...
...
@@ -216,9 +218,12 @@ class DataIntegrate:
# with open(save_file, 'w', encoding="utf-8") as f:
# f.write(monthReport_html)
save_file
=
"app/html/v2/monthReportV2.html"
with
open
(
save_file
,
'w'
,
encoding
=
"utf-8"
)
as
f
:
f
.
write
(
monthReport_html
)
# save_file = "app/html/v2/monthReportV2.html"
# with open(save_file, 'w', encoding="utf-8") as f:
# f.write(monthReport_html)
html_to_pdf
(
monthReport_html
,
'/Users/pengxiong/Desktop/fund_report/app/pdf/
%
s.pdf'
%
str
(
uuid
.
uuid4
()))
if
__name__
==
'__main__'
:
start
=
time
.
time
()
...
...
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