新模版2

parent 47199025
......@@ -2,7 +2,7 @@
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="jdk" jdkName="Python 3.8" jdkType="Python SDK" />
<orderEntry type="jdk" jdkName="Python 3.7" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
<component name="TestRunnerService">
......
......@@ -3,5 +3,5 @@
<component name="JavaScriptSettings">
<option name="languageLevel" value="ES6" />
</component>
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.8" project-jdk-type="Python SDK" />
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.7" project-jdk-type="Python SDK" />
</project>
\ No newline at end of file
......@@ -2561,8 +2561,6 @@
<th>优化前(万元)</th>
<th>优化后(万元)</th>
</tr>
<!-- <dl>-->
{% for key, value in suggestions_result.items() %}
{% for i in range(value|length) %}
<tr>
......@@ -2574,9 +2572,7 @@
<td class="font_green">{{value[i]["after_optimization"]}}</td>
</tr>
{% endfor %}
{% endfor %}
{% endfor %}
<tr>
<td colspan="2" class="back_gray font_bold">总市值(万元)</td>
<td class="font_bold">{{suggestions_result_asset["before"]}}</td>
......@@ -2816,88 +2812,6 @@
</div>
</div>
<!-- 新组合对比 -->
<div class="mr_block6-1 have_sub_tb">
<!--标题-->
<div class="head_wrap clearfix">
<div class="head_title fl">
新组合对比
</div>
<div class="head_logo_wrap fr">
<img src="./img/logo-blue.png" alt="">
<span class="com_brand_line"></span>
<span class="com_brand_name">
飞度工作室
</span>
</div>
</div>
<div class="new_compare_content">
<div class="profit_chart margin0">
<div class="profit_chart_item" style="width: 100%;">
<div class="profit_chart_title">
【收益比较】
</div>
<div class="profit_chart_graphic">
<img src="./img/logo-blue.png" alt="" class="profit_chart_img">
</div>
</div>
</div>
<div class="aim_table">
<div class="aim_head clearfix">
<div class="aim_title fl">
【指标对比】
</div>
<div class="aim_time fr">
截止日:最新净值日(2020-11-05)
</div>
</div>
<table border="1">
<tr>
<th>类型</th>
<th>区间收益(%)</th>
<th>年化收益(%)</th>
<th>波动率(%)</th>
<th>最大回撤(%)</th>
<th>夏普比率</th>
</tr>
<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>
<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>
</tr>
</table>
<div class="aim_foot">
注:以上指标自持仓首日开始计算,结果仅供参考,如果持仓时间过短会造成指标失真的情况。
</div>
</div>
</div>
</div>
<!-- 尾部 -->
<div class="mr_block_end have_sub_tb">
<!--标题-->
......
This diff is collapsed.
......@@ -253,8 +253,47 @@ def draw_comment_chart(xlabels, source_prod, target_prod):
plt.show()
def draw_old_combination_chart(xlabels, origin_combination, index):
"""旧组合对比图"""
figsize = (20, 12)
# 标签文字大小
fontsize = 22
# 初始化
fig = plt.figure(figsize=figsize)
ax1 = fig.add_subplot(111)
ax3 = ax1.twiny()
# ax = plt.gca() # gca:get current axis得到当前轴
# ax.spines['bottom'].set_position(('data', 0)) # data表示通过值来设置x轴的位置,将x轴绑定在y=0的位置
product_list = [origin_combination, index]
max_x_count = max([x['data'].size for x in product_list])
loc = np.arange(max_x_count) # the x locations for the groups
# 坐标轴
ax1.tick_params(labelsize=fontsize)
ax3.tick_params(labelsize=fontsize)
ax1.set_xticks(loc)
ax1.set_xticklabels(xlabels)
ax1.yaxis.set_major_formatter(FuncFormatter(to_percent))
ax3.set_xticks([])
# 新组合折线图
ax1.plot(loc, origin_combination['data'], color='#C6A774', marker='', linewidth=3, label=origin_combination['name'])
ax1.legend(loc='upper left', fontsize=fontsize)
# 指数折线图
ax3.plot(loc, index['data'], color='black', marker='', linewidth=3, label=index['name'])
ax3.legend(loc='upper right', fontsize=fontsize)
# plt.show()
imgdata = BytesIO()
fig.savefig(imgdata, format='png', bbox_inches='tight')
imgdata.seek(0) # rewind the data
return_compare_img = 'data:image/png;base64,' + base64.b64encode(imgdata.getvalue()).decode('utf-8')
return return_compare_img
def draw_combination_chart(xlabels, new_combination, origin_combination, index):
"""组合对比图"""
"""组合对比图"""
figsize = (20, 12)
# 标签文字大小
fontsize = 22
......@@ -280,11 +319,11 @@ def draw_combination_chart(xlabels, new_combination, origin_combination, index):
ax3.set_xticks([])
# 新组合折线图
ax1.plot(loc, new_combination['data'], color='#C6A774', marker='', linewidth=3, label=origin_combination['name'])
ax1.plot(loc, new_combination['data'], color='#C6A774', marker='', linewidth=3, label=new_combination['name'])
ax1.legend(loc='upper left', fontsize=fontsize)
# 原组合折线图
ax2.plot(loc, origin_combination['data'], color='#222A77', marker='', linewidth=3, label=new_combination['name'])
ax2.plot(loc, origin_combination['data'], color='#222A77', marker='', linewidth=3, label=origin_combination['name'])
ax2.legend(loc='upper center', fontsize=fontsize)
# 指数折线图
......@@ -298,10 +337,6 @@ def draw_combination_chart(xlabels, new_combination, origin_combination, index):
return_compare_img = 'data:image/png;base64,' + base64.b64encode(imgdata.getvalue()).decode('utf-8')
return return_compare_img
def draw_correlation_chart():
"""相关性分析图"""
pass
if __name__ == '__main__':
# xlabels = ('2020-1', '2020-2', '2020-3', '2020-4', '2020-5', '2020-6', '2020-7', '2020-8', '2020-9', '2020-10', '2020-11', '2020-12')
......
......@@ -9,6 +9,7 @@
import pdfkit
from PyPDF2 import PdfFileMerger, PdfFileReader, PdfFileWriter
import uuid
def html_to_pdf(source_path, target_path):
options = {
......@@ -16,16 +17,15 @@ def html_to_pdf(source_path, target_path):
'encoding': "utf-8",
# 'page-size': 'A5',
# 'page-width': '300mm',
# 'page-height': '200mm',
# 'page-height': 'auto',
'margin-top': '0mm',
'margin-right': '0mm',
'margin-bottom': '0mm',
'margin-left': '0mm'
}
url1 = 'http://www.qimontech.com'
# pdfkit.from_url(url1, '/Users/pengxiong/Desktop/out5.pdf', options=options)
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'):
""""""
merger = PdfFileMerger()
......@@ -40,5 +40,5 @@ def merge_pdf(pdfFiles, target_file='/Users/pengxiong/Desktop/combine.pdf'):
if __name__ == '__main__':
html_to_pdf()
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()))
# merge_pdf(['/Users/pengxiong/Desktop/out1.pdf', '/Users/pengxiong/Desktop/out.pdf'])
......@@ -7,7 +7,8 @@ from app.service.result_service import UserCustomerResultAdaptor
import numpy as np
# 准备数据
from app.utils.draw import draw_month_return_chart, draw_contribution_chart, draw_combination_chart
from app.utils.draw import draw_month_return_chart, draw_contribution_chart, draw_combination_chart, \
draw_old_combination_chart
from app.utils.radar_chart import gen_radar_chart
......@@ -30,10 +31,15 @@ class DataIntegrate:
self.single_fund_comment()
# 旧相关性
self.get_old_correlation()
# 新相关性
self.get_new_correlation()
# 新增基金
self.propose_fund()
# 目标与业绩
self.objectives_performance(self.group_result)
# 旧收益比较
self.get_old_compare_pic()
# 新收益比较
self.get_transfer_suggestions()
# 渲染模版
self.render_data()
......@@ -74,14 +80,16 @@ class DataIntegrate:
'radar_chart_path': gen_radar_chart(radar_chart_data[i])
})
# 调仓建议
def get_transfer_suggestions(self):
self.suggestions_result, self.suggestions_result_asset, return_compare_data,\
def get_old_compare_pic(self):
"""旧收益比较"""
self.suggestions_result, self.suggestions_result_asset, self.return_compare_data,\
self.indicator_compare, self.new_group_evaluation = portfolio_diagnose.new_evaluation("default", self.d, self.user_customer)
self.return_compare_pic = draw_combination_chart(return_compare_data["xlabels"], return_compare_data["new_combination"],
return_compare_data["origin_combination"], return_compare_data["index"])
self.old_return_compare_pic = draw_old_combination_chart(self.return_compare_data["xlabels"], self.return_compare_data["origin_combination"], self.return_compare_data["index"])
# 收益比较
def get_transfer_suggestions(self):
"""新收益比较,调仓建议"""
self.return_compare_pic = draw_combination_chart(self.return_compare_data["xlabels"], self.return_compare_data["new_combination"],
self.return_compare_data["origin_combination"], self.return_compare_data["index"])
def get_old_correlation(self):
......@@ -92,6 +100,14 @@ class DataIntegrate:
self.old_correlation = list(zip(range(1, len(old_correlation_columns)+1), old_correlation_columns, old_correlation_values))
def get_new_correlation(self):
"""新相关性分析."""
new_correlation = portfolio_diagnose.new_correlation
new_correlation_columns = new_correlation.columns.tolist()
new_correlation_values = new_correlation.values.tolist()
self.new_correlation = list(zip(range(1, len(new_correlation_columns)+1), new_correlation_columns, new_correlation_values))
def propose_fund(self):
"""新增基金"""
# 优化组合建议1 -- 新增基金
......@@ -101,7 +117,7 @@ class DataIntegrate:
for i in range(len(propose_fund_evaluation)):
self.propose_fund_data_list.append({
'fund_name': propose_fund_evaluation[i]['name'],
'status': '保留',
'status': '增仓',
'evaluation': propose_fund_evaluation[i]['data'],
'radar_chart_path': gen_radar_chart(propose_radar_chart_data[i])
})
......@@ -162,9 +178,11 @@ class DataIntegrate:
'contribution_decomposition': self.contribution_decomposition,
'single_fund_data_list': self.single_fund_data_list,
'old_correlation': self.old_correlation,
'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,
'old_return_compare_pic': self.old_return_compare_pic,
'return_compare_pic': self.return_compare_pic,
'indicator_compare': self.indicator_compare,
'new_group_evaluation': self.new_group_evaluation
......@@ -172,11 +190,16 @@ class DataIntegrate:
}
# 开始渲染html模板
env = Environment(loader=PackageLoader('app', 'templates')) # 创建一个包加载器对象
template = env.get_template('monthReport.html') # 获取一个模板文件
# template = env.get_template('monthReport.html') # 获取一个模板文件
template = env.get_template('/v2/monthReportV2.html') # 获取一个模板文件
monthReport_html = template.render(data) # 渲染
# 保存 monthReport_html
save_file = "app/html/monthReport.html"
# save_file = "app/html/monthReport.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)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment