月度回报更新3

parent 307edefa
......@@ -2,7 +2,7 @@
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="jdk" jdkName="Python 3.6" 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.6" 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
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -580,9 +580,10 @@ class PortfolioDiagnose(object):
return result
portfolio = ['HF00002JJ2', 'HF00005DBQ', 'HF0000681Q', 'HF00006693', 'HF00006AZF', 'HF00006BGS']
portfolio_diagnose = PortfolioDiagnose(client_type=1, portfolio=portfolio, invest_amount=10000000)
portfolio_diagnose.optimize()
if __name__ == '__main__':
portfolio = ['HF00002JJ2', 'HF00005DBQ', 'HF0000681Q', 'HF00006693', 'HF00006AZF', 'HF00006BGS']
portfolio_diagnose = PortfolioDiagnose(client_type=1, portfolio=portfolio, invest_amount=10000000)
portfolio_diagnose.optimize()
print(portfolio_diagnose.old_correlation)
# print(portfolio_diagnose.propose_fund_evaluation())
......@@ -143,7 +143,7 @@ class UserCustomerResultAdaptor(UserCustomerDataAdaptor):
col = list(month_earn.columns)
col_ = {x: x.replace('_earn', '') for x in list(col)}
month_earn.rename(columns=col_, inplace=True)
folio_report_data["contribution_decomposition"] = month_earn
# folio_report_data["contribution_decomposition"] = month_earn
# 组合内单个基金净值数据 组合内基金持仓数据
result_fund_nav_info, result_fund_hoding_info = self.group_fund_basic_info_data(cur_folio_order_data, cur_folio_result_cnav_data, cumulative_profit, total_cost)
......
......@@ -2480,7 +2480,7 @@
<div>
<h4 class="item_title">【贡献分解】</h4>
<div class="gongxianfenjie">
<img src="./img/logo-blue.png" alt="" class="contribute_img">
<img src={{contribution_decomposition}} alt="" class="contribute_img">
</div>
</div>
</div>
......
......@@ -105,7 +105,7 @@ def draw_contribution_chart(xlabels, product_list, cumulative):
fontsize = 22
# 初始化
fig = plt.figure(figsize=figsize)
ax1 = fig.add_subplot()
ax1 = fig.add_subplot(111)
ax2 = ax1.twiny()
max_x_count = max([x['data'].size for x in product_list])
loc = np.arange(max_x_count) # the x locations for the groups
......@@ -145,7 +145,12 @@ def draw_contribution_chart(xlabels, product_list, cumulative):
ax2.plot(loc, cumulative['data'], color='#C6A774', marker='', linewidth=3, label=cumulative['name'])
ax2.legend(loc='upper left', fontsize=fontsize)
plt.show()
# plt.show()
imgdata = BytesIO()
fig.savefig(imgdata, format='png')
imgdata.seek(0) # rewind the data
month_return_img = 'data:image/png;base64,' + base64.b64encode(imgdata.getvalue()).decode('utf-8')
return month_return_img
def draw_comment_chart(xlabels, source_prod, target_prod):
......
# -*- encoding: utf-8 -*-
# -----------------------------------------------------------------------------
# @File Name : radar_chart.py
# @Time : 2020/12/1 下午4:50
# @Author : X. Peng
# @Email : acepengxiong@163.com
# @Software : PyCharm
# -----------------------------------------------------------------------------
import pyecharts.options as opts
from pyecharts.charts import Radar, Bar
from snapshot_phantomjs import snapshot
from pyecharts.render import make_snapshot
def gen_radar_chart():
"""
Gallery 使用 pyecharts 1.1.0
参考地址: https://echarts.apache.org/examples/editor.html?c=radar
目前无法实现的功能:
1、雷达图周围的图例的 textStyle 暂时无法设置背景颜色
"""
v1 = [[4300, 10000, 28000, 35000, 50000]]
(
Radar(
init_opts=opts.InitOpts(bg_color="#fff", animation_opts=opts.AnimationOpts(animation=False)))
.add_schema(
schema=[
opts.RadarIndicatorItem(name="绝对收益", max_=6500),
opts.RadarIndicatorItem(name="业绩持续性", max_=16000),
opts.RadarIndicatorItem(name="风险调整后收益", max_=30000),
opts.RadarIndicatorItem(name="极端风险", max_=38000),
opts.RadarIndicatorItem(name="抗风险能力", max_=52000),
],
splitarea_opt=opts.SplitAreaOpts(
is_show=True, areastyle_opts=opts.AreaStyleOpts(opacity=1, color=[
'rgba(198, 167, 116, 0.5)',
'rgba(198, 167, 116, 0.4)',
'rgba(198, 167, 116, 0.3)',
'rgba(198, 167, 116, 0.2)',
'rgba(198, 167, 116, 0.1)',
])
),
textstyle_opts=opts.TextStyleOpts(color="#000", font_size=16),
)
.add(
series_name="预算分配(Allocated Budget)",
data=v1,
linestyle_opts=opts.LineStyleOpts(width=2, color="#C6A774"),
tooltip_opts=None
)
.set_series_opts(label_opts=opts.LabelOpts(is_show=False))
.set_global_opts(
title_opts=opts.TitleOpts(
title="综合评分", subtitle="66.32", pos_top="center", pos_left="46%",
title_textstyle_opts={'color': '#333',
'fontSize': 18,
'lineHeight': 20,
'fontWeight': 'normal'
},
subtitle_textstyle_opts={'color': '#222A77',
'fontSize': 20,
'lineHeight': 23,
'fontWeight': 'bolder',
}),
legend_opts=opts.LegendOpts(selected_mode=False, is_show=False)
)
.render("basic_radar_chart.html")
)
make_snapshot(snapshot, "basic_radar_chart.html", "basic_radar_chart.png", delay=2)
if __name__ == '__main__':
gen_radar_chart()
\ No newline at end of file
......@@ -3,7 +3,7 @@ from app.service.result_service import UserCustomerResultAdaptor
# 准备数据
from app.utils.draw import draw_month_return_chart
from app.utils.draw import draw_month_return_chart, draw_contribution_chart
ifa_id = 'USER_INFO15914346866762'
customer_id = '202009281545001'
......@@ -13,27 +13,33 @@ user_customer = UserCustomerResultAdaptor(ifa_id, customer_id)
df = user_customer.calculate_total_data()
d = user_customer.calculate_group_result_data()
print(d)
# print(d)
# 几月综述部分
total_cost = df["total_cost"]/10000
now_yield = round((df['contribution_decomposition']-1)*100,2)
now_yield = round((df['cumulative_return']-1)*100,2)
index_yield = round((df["index_result"]["return_ratio"]-1)*100, 2)
now_withdrawal = round(df["max_drawdown"][0]*100,2)
index_withdrawal = round(df["index_result"]["max_drawdown"][0]*100, 2)
# monthly_return_performance_pic = '_'.join((ifa_id, customer_id, '20201109', 'monthly_return_performance.png'))
# image_dir = './img/'
# monthly_return_performance_pic = image_dir + monthly_return_performance_pic
# 月度回报
xlabels, product_list, cumulative = user_customer.get_month_return_chart()
monthly_return_performance_pic = draw_month_return_chart(xlabels, product_list, cumulative)
# 组合数据
group_result = d["default"]
print(group_result)
# 贡献分解
g_data = group_result["contribution_decomposition"]
contribution_decomposition = draw_contribution_chart(g_data['xlabels'], g_data['product_list'], g_data['cumulative'])
now_month_income = int(group_result["cur_month_profit"]) # 本月收益
now_year_income = int(group_result["cur_year_profit"]) # 今年累计收益
totoal_rate_of_return = round((group_result['contribution_decomposition']-1)*100, 2) # 累计收益率
totoal_rate_of_return = round((group_result['cumulative_return']-1)*100, 2) # 累计收益率
month_rise = round(group_result["cur_month_profit_ratio"]*100, 2) # 本月涨幅
year_totoal_rate_of_return = round(group_result["cur_year_profit_ratio"]*100, 2) # 今年累计收益率
annualised_return = round(group_result["return_ratio_year"]*100, 2) # 年化收益率
......@@ -73,7 +79,8 @@ data = {'customer_name':'成龙', 'customer_gender':'女',
'volatility':index_volatility, 'max_withdrawal':index_max_withdrawal, 'sharpe_ratio':index_sharpe_ratio},
'monthly_return_performance_pic':monthly_return_performance_pic,
'group_nav_info': group_nav_info,
'group_hoding_info': group_hoding_info
'group_hoding_info': group_hoding_info,
'contribution_decomposition': contribution_decomposition
}
......
This source diff could not be displayed because it is too large. You can view the blob instead.
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