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
1c6b5c23
Commit
1c6b5c23
authored
Jan 07, 2021
by
pengxiong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
持仓,诊断模版
parent
cf6e6059
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
251 additions
and
202 deletions
+251
-202
default_template_params.py
app/config/default_template_params.py
+67
-22
monthReportV2.1.html
app/templates/v2/monthReportV2.1.html
+120
-120
format_transfer.py
app/utils/format_transfer.py
+9
-1
jinjia2html_v2.py
app/utils/jinjia2html_v2.py
+55
-59
No files found.
app/config/default_template_params.py
View file @
1c6b5c23
...
@@ -7,47 +7,92 @@
...
@@ -7,47 +7,92 @@
# @Software : PyCharm
# @Software : PyCharm
# -----------------------------------------------------------------------------
# -----------------------------------------------------------------------------
from
app.api.engine
import
template_folder
from
app.api.engine
import
template_folder
from
app.utils.format_transfer
import
img_transfer
default_template
=
{
hold_
default_template
=
{
# 封面 值为None不不显示,为block显示
# 封面 值为None不不显示,为block显示
'box0'
:
'block'
,
'box0'
:
'block'
,
# 目录
# 目录
'box1'
:
'block'
,
'box1'
:
'block'
,
# 投资总览
# 投资总览
'box2'
:
'block'
,
'box2'
:
'block'
,
'box2
-section1'
:
'block'
,
'box2
_section1'
:
None
,
'box2
-
section2'
:
'block'
,
'box2
_
section2'
:
'block'
,
'box2
-
section3'
:
'block'
,
'box2
_
section3'
:
'block'
,
'box2
-
section4'
:
'block'
,
'box2
_
section4'
:
'block'
,
# 目标与业绩
# 目标与业绩
'box3'
:
'block'
,
'box3'
:
'block'
,
'box3
-
section1'
:
'block'
,
'box3
_
section1'
:
'block'
,
'box3
-
section2'
:
'block'
,
'box3
_
section2'
:
'block'
,
'box3
-
section3'
:
'block'
,
'box3
_
section3'
:
'block'
,
'box3
-
section4'
:
'block'
,
'box3
_
section4'
:
'block'
,
# 业绩的明细
# 业绩的明细
'box4'
:
'block'
,
'box4'
:
'block'
,
'box4
-
section1'
:
'block'
,
'box4
_
section1'
:
'block'
,
'box4
-
section2'
:
'block'
,
'box4
_
section2'
:
'block'
,
'box4
-
section3'
:
'block'
,
'box4
_
section3'
:
'block'
,
# 个基点评
# 个基点评
'box5'
:
None
,
'box5'
:
None
,
# 优化组合建议
# 优化组合建议
'box6'
:
None
,
'box6'
:
None
,
'box6
-
section1'
:
'block'
,
'box6
_
section1'
:
'block'
,
'box6
-
section2'
:
'block'
,
'box6
_
section2'
:
'block'
,
'box6
-
section3'
:
'block'
,
'box6
_
section3'
:
'block'
,
'box6
-
section4'
:
'block'
,
'box6
_
section4'
:
'block'
,
# 新增基金
# 新增基金
'box7'
:
None
,
'box7'
:
None
,
# 结尾
# 结尾
'box8'
:
'block'
,
'box8'
:
'block'
,
'logo'
:
template_folder
+
'/v2/img/logo.png'
,
'logo'
:
img_transfer
(
template_folder
+
'/v2/img/logo.png'
)
,
'brand_name'
:
'资产管<br>理中心'
,
'brand_name'
:
'资产管<br>理中心'
,
'cover_back'
:
template_folder
+
'/v2/img/cover-back.png'
,
'cover_back'
:
img_transfer
(
template_folder
+
'/v2/img/cover-back.png'
)
,
'scene'
:
template_folder
+
'/v2/img/scene.png'
,
'scene'
:
img_transfer
(
template_folder
+
'/v2/img/scene.png'
),
'team'
:
template_folder
+
'/v2/img/default-user.png'
,
'team'
:
img_transfer
(
template_folder
+
'/v2/img/default-user.png'
),
'red_rect'
:
template_folder
+
'/v2/img/red-rect.png'
,
'red_rect'
:
img_transfer
(
template_folder
+
'/v2/img/red-rect.png'
),
'sh'
:
template_folder
+
'/v2/img/sh.png'
,
'sh'
:
img_transfer
(
template_folder
+
'/v2/img/sh.png'
),
}
diagnose_default_template
=
{
# 封面 值为None不不显示,为block显示
'box0'
:
'block'
,
# 目录
'box1'
:
'block'
,
# 投资总览
'box2'
:
'block'
,
'box2_section1'
:
'block'
,
'box2_section2'
:
'block'
,
'box2_section3'
:
'block'
,
'box2_section4'
:
'block'
,
# 目标与业绩
'box3'
:
'block'
,
'box3_section1'
:
'block'
,
'box3_section2'
:
'block'
,
'box3_section3'
:
'block'
,
'box3_section4'
:
'block'
,
# 业绩的明细
'box4'
:
'block'
,
'box4_section1'
:
'block'
,
'box4_section2'
:
'block'
,
'box4_section3'
:
'block'
,
# 个基点评
'box5'
:
'block'
,
# 优化组合建议
'box6'
:
'block'
,
'box6_section1'
:
'block'
,
'box6_section2'
:
'block'
,
'box6_section3'
:
'block'
,
'box6_section4'
:
'block'
,
# 新增基金
'box7'
:
'block'
,
# 结尾
'box8'
:
'block'
,
'logo'
:
img_transfer
(
template_folder
+
'/v2/img/logo.png'
),
'brand_name'
:
'资产管<br>理中心'
,
'cover_back'
:
img_transfer
(
template_folder
+
'/v2/img/cover-back.png'
),
'scene'
:
img_transfer
(
template_folder
+
'/v2/img/scene.png'
),
'team'
:
img_transfer
(
template_folder
+
'/v2/img/default-user.png'
),
'red_rect'
:
img_transfer
(
template_folder
+
'/v2/img/red-rect.png'
),
'sh'
:
img_transfer
(
template_folder
+
'/v2/img/sh.png'
),
}
}
app/templates/v2/monthReportV2.1.html
View file @
1c6b5c23
This diff is collapsed.
Click to expand it.
app/utils/format_transfer.py
View file @
1c6b5c23
...
@@ -6,6 +6,7 @@
...
@@ -6,6 +6,7 @@
# @Email : acepengxiong@163.com
# @Email : acepengxiong@163.com
# @Software : PyCharm
# @Software : PyCharm
# -----------------------------------------------------------------------------
# -----------------------------------------------------------------------------
import
base64
import
decimal
import
decimal
import
json
import
json
import
numpy
as
np
import
numpy
as
np
...
@@ -16,4 +17,11 @@ class npEncoder(json.JSONEncoder):
...
@@ -16,4 +17,11 @@ class npEncoder(json.JSONEncoder):
return
obj
.
tolist
()
return
obj
.
tolist
()
elif
isinstance
(
obj
,
decimal
.
Decimal
):
elif
isinstance
(
obj
,
decimal
.
Decimal
):
return
obj
.
__str__
()
return
obj
.
__str__
()
return
json
.
JSONEncoder
.
default
(
self
,
obj
)
return
json
.
JSONEncoder
.
default
(
self
,
obj
)
\ No newline at end of file
def
img_transfer
(
url
):
""""""
img_content
=
'data:image/png;base64,'
with
open
(
url
,
'rb'
)
as
f
:
img_content
+=
base64
.
b64encode
(
f
.
read
())
.
decode
(
'utf-8'
)
return
img_content
app/utils/jinjia2html_v2.py
View file @
1c6b5c23
...
@@ -4,7 +4,7 @@ import uuid
...
@@ -4,7 +4,7 @@ import uuid
from
jinja2
import
PackageLoader
,
Environment
from
jinja2
import
PackageLoader
,
Environment
from
app.api.engine
import
work_dir
,
pdf_folder
,
template_folder
from
app.api.engine
import
work_dir
,
pdf_folder
,
template_folder
from
app.config.default_template_params
import
default_template
from
app.config.default_template_params
import
hold_default_template
,
diagnose_
default_template
from
app.service.portfolio_diagnose
import
PortfolioDiagnose
from
app.service.portfolio_diagnose
import
PortfolioDiagnose
from
app.service.result_service_v2
import
UserCustomerResultAdaptor
from
app.service.result_service_v2
import
UserCustomerResultAdaptor
import
numpy
as
np
import
numpy
as
np
...
@@ -19,12 +19,14 @@ from app.utils.radar_chart import gen_radar_chart
...
@@ -19,12 +19,14 @@ from app.utils.radar_chart import gen_radar_chart
class
DataIntegrate
:
class
DataIntegrate
:
def
__init__
(
self
,
ifa_id
=
'USER_INFO15914346866762'
,
customer_id
=
'202009281545001'
,
pdf_name
=
str
(
uuid
.
uuid4
())
+
'.pdf'
):
def
__init__
(
self
,
ifa_id
=
'USER_INFO15914346866762'
,
customer_id
=
'202009281545001'
,
pdf_name
=
str
(
uuid
.
uuid4
())
+
'.pdf'
,
type
=
1
):
self
.
user_customer
=
UserCustomerResultAdaptor
(
ifa_id
,
customer_id
)
self
.
user_customer
=
UserCustomerResultAdaptor
(
ifa_id
,
customer_id
)
self
.
customer_name
=
self
.
user_customer
.
customer_real_name
self
.
customer_name
=
self
.
user_customer
.
customer_real_name
self
.
ifa_name
=
self
.
user_customer
.
ifa_real_name
self
.
ifa_name
=
self
.
user_customer
.
ifa_real_name
# self.pdf_name = self.ifa_name + "_" + self.customer_name + "_" + '.pdf'
# self.pdf_name = self.ifa_name + "_" + self.customer_name + "_" + '.pdf'
self
.
pdf_name
=
pdf_name
self
.
pdf_name
=
pdf_name
# 1持仓报告2诊断报告
self
.
type
=
type
# 全部数据
# 全部数据
self
.
df
=
self
.
user_customer
.
calculate_total_data
()
self
.
df
=
self
.
user_customer
.
calculate_total_data
()
# 组合结果数据
# 组合结果数据
...
@@ -41,11 +43,6 @@ class DataIntegrate:
...
@@ -41,11 +43,6 @@ class DataIntegrate:
# 月度回报表格
# 月度回报表格
self
.
get_month_table_return
()
self
.
get_month_table_return
()
# 合并数据
self
.
get_template_data
()
# # 渲染模版
# self.render_data()
# 分组和计算个基点评以及新增基金等结果
# 分组和计算个基点评以及新增基金等结果
def
get_group_result
(
self
):
def
get_group_result
(
self
):
...
@@ -73,12 +70,13 @@ class DataIntegrate:
...
@@ -73,12 +70,13 @@ class DataIntegrate:
self
.
get_old_compare_pic
(
cur_group_portfolio_result
)
self
.
get_old_compare_pic
(
cur_group_portfolio_result
)
# 旧相关性
# 旧相关性
self
.
get_old_correlation
(
portfolio_diagnose
,
cur_group_portfolio_result
)
self
.
get_old_correlation
(
portfolio_diagnose
,
cur_group_portfolio_result
)
# # 新增基金
if
self
.
type
==
2
:
# self.propose_fund(portfolio_diagnose, cur_group_portfolio_result)
# 新增基金
# # 新收益比较
self
.
propose_fund
(
portfolio_diagnose
,
cur_group_portfolio_result
)
# self.get_transfer_suggestions(portfolio_diagnose, group_name, cur_group_portfolio_result)
# 新收益比较
# # 新相关性
self
.
get_transfer_suggestions
(
portfolio_diagnose
,
group_name
,
cur_group_portfolio_result
)
# self.get_new_correlation(portfolio_diagnose, cur_group_portfolio_result)
# 新相关性
self
.
get_new_correlation
(
portfolio_diagnose
,
cur_group_portfolio_result
)
self
.
all_folio_result
[
group_name
]
=
cur_group_portfolio_result
self
.
all_folio_result
[
group_name
]
=
cur_group_portfolio_result
...
@@ -226,7 +224,9 @@ class DataIntegrate:
...
@@ -226,7 +224,9 @@ class DataIntegrate:
def
get_template_data
(
self
):
def
get_template_data
(
self
):
""""""
""""""
data
=
{
if
self
.
type
==
1
:
# 持仓报告数据
data
=
{
# 全局数据
# 全局数据
'customer_name'
:
self
.
customer_name
,
'customer_name'
:
self
.
customer_name
,
'year_month'
:
self
.
user_customer
.
month_start_date
.
strftime
(
"
%
Y-
%
m"
),
'year_month'
:
self
.
user_customer
.
month_start_date
.
strftime
(
"
%
Y-
%
m"
),
...
@@ -235,10 +235,13 @@ class DataIntegrate:
...
@@ -235,10 +235,13 @@ class DataIntegrate:
'latest_worth_day'
:
self
.
user_customer
.
last_nav_date
,
'latest_worth_day'
:
self
.
user_customer
.
last_nav_date
,
'customer_level'
:
'平衡型'
,
'customer_level'
:
'平衡型'
,
# 综述数据
# 综述数据
'now_allocation_amount'
:
'{:,}'
.
format
(
self
.
total_cost
),
'now_yield'
:
self
.
now_yield
,
'index_yield'
:
self
.
index_yield
,
'now_allocation_amount'
:
'{:,}'
.
format
(
self
.
total_cost
),
'now_yield'
:
self
.
now_yield
,
'index_yield'
:
self
.
index_yield
,
'now_annualised_return'
:
self
.
now_annualised_return
,
'now_annualised_return'
:
self
.
now_annualised_return
,
'now_withdrawal'
:
self
.
now_withdrawal
,
'index_withdrawal'
:
self
.
index_withdrawal
,
'expected_withdrawal'
:
20
,
'now_withdrawal'
:
self
.
now_withdrawal
,
'index_withdrawal'
:
self
.
index_withdrawal
,
'now_year_income'
:
'{:,}'
.
format
(
self
.
now_year_income
),
'now_month_income'
:
'{:,}'
.
format
(
self
.
now_month_income
),
'expected_withdrawal'
:
20
,
'now_year_income'
:
'{:,}'
.
format
(
self
.
now_year_income
),
'now_month_income'
:
'{:,}'
.
format
(
self
.
now_month_income
),
'final_balance'
:
'{:,}'
.
format
(
self
.
final_balance
),
'total_profit'
:
'{:,}'
.
format
(
self
.
total_profit
),
'final_balance'
:
'{:,}'
.
format
(
self
.
final_balance
),
'total_profit'
:
'{:,}'
.
format
(
self
.
total_profit
),
'total_profit_temp'
:
self
.
total_profit
,
'total_profit_temp'
:
self
.
total_profit
,
'now_year_income_temp'
:
self
.
now_year_income
,
'now_month_income_temp'
:
self
.
now_month_income
,
'now_year_income_temp'
:
self
.
now_year_income
,
'now_month_income_temp'
:
self
.
now_month_income
,
...
@@ -250,46 +253,38 @@ class DataIntegrate:
...
@@ -250,46 +253,38 @@ class DataIntegrate:
# 组合数据
# 组合数据
'all_folio_result'
:
self
.
all_folio_result
,
'all_folio_result'
:
self
.
all_folio_result
,
}
self
.
data
=
{
**
hold_default_template
,
**
data
}
elif
self
.
type
==
2
:
# 诊断报告数据
data
=
{
# 全局数据
'customer_name'
:
self
.
customer_name
,
'year_month'
:
self
.
user_customer
.
month_start_date
.
strftime
(
"
%
Y-
%
m"
),
'month'
:
self
.
user_customer
.
month_start_date
.
strftime
(
"
%
m"
),
'start_date'
:
self
.
user_customer
.
start_date
.
strftime
(
"
%
Y-
%
m-
%
d"
),
'latest_worth_day'
:
self
.
user_customer
.
last_nav_date
,
'customer_level'
:
'平衡型'
,
# 综述数据
'now_allocation_amount'
:
'{:,}'
.
format
(
self
.
total_cost
),
'now_yield'
:
self
.
now_yield
,
'index_yield'
:
self
.
index_yield
,
'now_annualised_return'
:
self
.
now_annualised_return
,
'now_withdrawal'
:
self
.
now_withdrawal
,
'index_withdrawal'
:
self
.
index_withdrawal
,
'expected_withdrawal'
:
20
,
'now_year_income'
:
'{:,}'
.
format
(
self
.
now_year_income
),
'now_month_income'
:
'{:,}'
.
format
(
self
.
now_month_income
),
'final_balance'
:
'{:,}'
.
format
(
self
.
final_balance
),
'total_profit'
:
'{:,}'
.
format
(
self
.
total_profit
),
'total_profit_temp'
:
self
.
total_profit
,
'now_year_income_temp'
:
self
.
now_year_income
,
'now_month_income_temp'
:
self
.
now_month_income
,
'monthly_return_performance_pic'
:
self
.
monthly_return_performance_pic
,
'month_rise'
:
self
.
month_rise
,
'year_totoal_rate_of_return'
:
self
.
year_totoal_rate_of_return
,
'monthly_table_return'
:
self
.
monthly_table_return
,
# 'totoal_rate_of_return': self.totoal_rate_of_return,
# 组合数据
# 'annualised_return': self.annualised_return, 'cost_of_investment': self.cost_of_investment,
'all_folio_result'
:
self
.
all_folio_result
,
#
}
#
self
.
data
=
{
**
diagnose_default_template
,
**
data
}
# 'index_comparison': {'section_return': self.totoal_rate_of_return, 'annualized_returns': self.annualised_return,
# 'volatility': self.volatility, 'max_withdrawal': self.max_withdrawal,
# 'sharpe_ratio': self.sharpe_ratio},
# 'index_comparison_500': {'section_return': self.index_section_return,
# 'annualized_returns': self.index_annualised_return,
# 'volatility': self.index_volatility, 'max_withdrawal': self.index_max_withdrawal,
# 'sharpe_ratio': self.index_sharpe_ratio},
#
# 'group_nav_info': self.group_nav_info,
# 'group_hoding_info': self.group_hoding_info,
# 'group_hoding_info_total': self.group_hoding_info_total,
# 'old_evaluation': self.old_evaluation,
# 'old_indicator_compare': self.old_indicator_compare,
# 'contribution_decomposition': self.contribution_decomposition,
# 'single_fund_data_list': self.single_fund_data_list,
# 'old_correlation': self.old_correlation,
# 'old_return_compare_pic': self.old_return_compare_pic,
# # 'new_correlation': self.new_correlation,
# # 'propose_fund_data_list': self.propose_fund_data_list,
# # 'suggestions_result': self.suggestions_result,
# # 'suggestions_result_asset': self.suggestions_result_asset,
# # 'return_compare_pic': self.return_compare_pic,
# # 'indicator_compare': self.indicator_compare,
# # 'new_group_evaluation': self.new_group_evaluation
# 'new_correlation': [],
# 'propose_fund_data_list': [],
# 'suggestions_result': {},
# 'suggestions_result_asset': {},
# 'return_compare_pic': [],
# 'indicator_compare': [],
# 'new_group_evaluation': []
}
self
.
data
=
{
**
default_template
,
**
data
}
return
self
.
data
return
self
.
data
def
render_data
(
self
):
def
render_data
(
self
):
...
@@ -300,9 +295,9 @@ class DataIntegrate:
...
@@ -300,9 +295,9 @@ class DataIntegrate:
template
=
env
.
get_template
(
'/v2/monthReportV2.1.html'
)
# 获取一个模板文件
template
=
env
.
get_template
(
'/v2/monthReportV2.1.html'
)
# 获取一个模板文件
monthReport_html
=
template
.
render
(
self
.
data
)
# 渲染
monthReport_html
=
template
.
render
(
self
.
data
)
# 渲染
# 保存 monthReport_html
# 保存 monthReport_html
save_file
=
"app/html/monthReport.html"
#
save_file = "app/html/monthReport.html"
with
open
(
save_file
,
'w'
,
encoding
=
"utf-8"
)
as
f
:
#
with open(save_file, 'w', encoding="utf-8") as f:
f
.
write
(
monthReport_html
)
#
f.write(monthReport_html)
# save_file = "app/html/v2/monthReportV2.html"
# save_file = "app/html/v2/monthReportV2.html"
# with open(save_file, 'w', encoding="utf-8") as f:
# with open(save_file, 'w', encoding="utf-8") as f:
...
@@ -312,6 +307,7 @@ class DataIntegrate:
...
@@ -312,6 +307,7 @@ class DataIntegrate:
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
start
=
time
.
time
()
start
=
time
.
time
()
dt
=
DataIntegrate
(
ifa_id
=
'USER_INFO1591785
3924996'
,
customer_id
=
'6741679287251775488'
)
dt
=
DataIntegrate
(
ifa_id
=
'USER_INFO1591785
0824287'
,
customer_id
=
'6716613802534121472'
,
type
=
1
)
data
=
dt
.
get_template_data
()
data
=
dt
.
get_template_data
()
dt
.
render_data
()
print
(
'耗时{}秒'
.
format
(
round
(
time
.
time
()
-
start
,
2
)))
print
(
'耗时{}秒'
.
format
(
round
(
time
.
time
()
-
start
,
2
)))
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