Commit 39279e4f authored by 李宗熹's avatar 李宗熹

py

parent c676f4ca
......@@ -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
......@@ -57,9 +57,9 @@ tamp_user_engine = create_engine(
),
echo=True
)
tamp_product_session = scoped_session(sessionmaker(bind=tamp_product_engine))()
tamp_order_session = scoped_session(sessionmaker(bind=tamp_order_engine))()
tamp_user_session = scoped_session(sessionmaker(bind=tamp_user_engine))()
# tamp_product_session = scoped_session(sessionmaker(bind=tamp_product_engine))()
# tamp_order_session = scoped_session(sessionmaker(bind=tamp_order_engine))()
# tamp_user_session = scoped_session(sessionmaker(bind=tamp_user_engine))()
# redis = redis.StrictRedis(
# host=config[env]['redis']['host'],
......@@ -74,3 +74,28 @@ logging.basicConfig(level=logging.INFO,
datefmt=config[env]['log']['datefmt']
)
class TAMP_SQL(object):
"""[sqlalchemy 封装]
Args:
object ([type]): [description]
Returns:
[type]: [description]
"""
def __init__(self, db_engine):
# 创建DBSession类型:
self.DBSession = scoped_session(sessionmaker(bind=db_engine))
self.session = self.DBSession()
def __enter__(self):
return self
def __exit__(self, exc_type, exc_val, exc_tb):
try:
self.session.commit()
except:
self.session.rollback()
finally:
self.session.close()
\ No newline at end of file
This diff is collapsed.
......@@ -2345,35 +2345,14 @@
<div class="comment_tri"></div>
</div>
<div class="comment_content">
{% for eval in old_evaluation %}
<div class="comment_item">
<div class="comment_dot"></div>
<div class="comment_text">
1、组合构建于XXXX年XX月,至今已运行XX个月。投入成本为XXXX万元,截止XXXX年XX月XX日,整体盈利XX万元,整体表现
<span class="comment_tag_red">优秀</span>/
<span class="comment_tag_red">良好</span>/
<span class="comment_tag_green">一般</span>/
<span class="comment_tag_green">合格</span>/
<span class="comment_tag_green">较差</span>
回撤控制能力
<span class="comment_tag_red">优秀</span>/
<span class="comment_tag_red">良好</span>/
<span class="comment_tag_green">一般</span>/
<span class="comment_tag_green">合格</span>/
<span class="comment_tag_green">较差</span>
</div>
</div>
<div class="comment_item">
<div class="comment_dot"></div>
<div class="comment_text">
2、组合共持有7只基金,XX和XX两只产品收益稳健,对组合的收益率贡献明显,6只基金取得正收益【根据情况变化】,2只基金综合得分较低建议更换,1只基金因为成立时间较短,暂不做评价;
</div>
</div>
<div class="comment_item">
<div class="comment_dot"></div>
<div class="comment_text">
3、策略角度来看,组合涵盖了管理期货及全市场套利策略【说明:二级分类】,以管理期货【说明:二级分类】为主,策略上有一定分散【根据情况变化】,从组合的相关性矩阵来看,XX和XX相关性较高,建议调整组合配比;
{{eval}}
</div>
</div>
{% endfor %}
</div>
</div>
</div>
......@@ -2480,7 +2459,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>
......@@ -2505,6 +2484,7 @@
</div>
<div class="content_wrap">
<ul class="geji_list_wrap">
{% for single_fund in single_fund_data_list %}
<li class="self_item">
<table>
<tr>
......@@ -2512,62 +2492,18 @@
<div class="self_item_left">
<div class="self_header">
<div class="self_title">
远澜银杏 1 号
{{single_fund.fund_name}}
<div class="self_title_tri"></div>
</div>
<div class="self_type yellow">
保留
{{single_fund.status}}
</div>
</div>
<div class="self_description">
<div class="self_description_item">
<div class="self_description_dot"></div>
<div class="self_description_text">
1、该基金整体表现
<span class="self_description_red">优秀</span>/
<span class="self_description_red">良好</span>/
<span class="self_description_green">一般</span>/
<span class="self_description_green">合格</span>/
<span class="self_description_green">较差</span>
收益能力
<span class="self_description_red">优秀</span>/
<span class="self_description_red">良好</span>/
<span class="self_description_green">一般</span>/
<span class="self_description_green">合格</span>/
<span class="self_description_green">较差</span>
回撤控制能力
<span class="self_description_red">优秀</span>/
<span class="self_description_red">良好</span>/
<span class="self_description_green">一般</span>/
<span class="self_description_green">合格</span>/
<span class="self_description_green">较差</span>
风险收益比例
<span class="self_description_red">优秀</span>/
<span class="self_description_red">良好</span>/
<span class="self_description_green">一般</span>/
<span class="self_description_green">合格</span>/
<span class="self_description_green">较差</span>;
</div>
</div>
<div class="self_description_item">
<div class="self_description_dot"></div>
<div class="self_description_text">
2、在收益方面,该基金年化收益能力
<span class="self_description_red">高于</span>/
<span class="self_description_green">持平</span>/
<span class="self_description_green">低于</span>
同类基金平均水平,有x%区间跑赢大盘/指数,绝对收益能力
<span class="self_description_red">优秀</span>/
<span class="self_description_red">良好</span>/
<span class="self_description_green">一般</span>/
<span class="self_description_green">合格</span>/
<span class="self_description_green">较差</span>
</div>
</div>
<div class="self_description_item">
<div class="self_description_dot"></div>
<div class="self_description_text">
3、在风险方面,该基金抵御风险能力优秀,在同类基金中处于中等水平,最大回撤为x%,低于同类基金平均水平;
{{single_fund.evaluation}}
</div>
</div>
</div>
......@@ -2575,12 +2511,13 @@
</td>
<td style="padding: 0;text-align: left;vertical-align: middle;">
<div class="self_item_right">
<img src="./img/logo-blue.png" alt="" class="self_img">
<img src={{single_fund.radar_chart_path}} alt="" class="self_img">
</div>
</td>
</tr>
</table>
</li>
{% endfor %}
<li class="self_item">
<table>
<tr>
......
......@@ -89,7 +89,7 @@ def draw_month_return_chart(xlabels, product_list, cumulative):
# plt.show()
imgdata = BytesIO()
fig.savefig(imgdata, format='png')
fig.savefig(imgdata, format='png', bbox_inches='tight')
imgdata.seek(0) # rewind the data
month_return_img = 'data:image/png;base64,' + base64.b64encode(imgdata.getvalue()).decode('utf-8')
return month_return_img
......@@ -100,7 +100,7 @@ def draw_contribution_chart(xlabels, product_list, cumulative):
# plt.title('Scores by group and gender')
# plt.ylabel('Scores')
figsize = (20, 12)
figsize = (25, 12)
# 标签文字大小
fontsize = 22
# 初始化
......@@ -117,12 +117,12 @@ def draw_contribution_chart(xlabels, product_list, cumulative):
ax1.set_xticks(loc)
ax1.set_xticklabels(xlabels)
ax1.yaxis.set_major_formatter(FuncFormatter(to_percent))
temp_rate = np.zeros(max_x_count)
for i in range(len(product_list)):
temp_rate += product_list[i]['data']
max_rate = np.max(np.hstack((temp_rate, cumulative['data'])))
# temp_rate = np.zeros(max_x_count)
# for i in range(len(product_list)):
# temp_rate += product_list[i]['data']
# max_rate = np.max(np.hstack((temp_rate, cumulative['data'])))
ax2.set_xticks([])
ax2.set_ylim(0, max_rate + 10)
# ax2.set_ylim(0, max_rate + 10)
# 堆叠柱状图
prod_legend = []
......@@ -139,13 +139,83 @@ def draw_contribution_chart(xlabels, product_list, cumulative):
else:
ax = ax1.bar(loc, product_list[i]['data'], width, bottom=bottom, alpha=0.8)
prod_legend.append(ax[0])
ax1.legend(prod_legend, [prod['name'] for prod in product_list], bbox_to_anchor=(0.8, -0.1), ncol=4, fontsize=fontsize)
ax1.legend(prod_legend, [prod['name'] for prod in product_list], bbox_to_anchor=(0.9, -0.1), ncol=4, fontsize=fontsize)
# 画折线图
ax2.plot(loc, cumulative['data'], color='#C6A774', marker='', linewidth=3, label=cumulative['name'])
ax2.legend(loc='upper left', fontsize=fontsize)
plt.show()
imgdata = BytesIO()
fig.savefig(imgdata, format='png', bbox_inches='tight')
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_contribution_chart(xlabels, product_list, cumulative):
# """贡献分解图"""
#
# # plt.title('Scores by group and gender')
# # plt.ylabel('Scores')
# figsize = (25, 12)
# # 标签文字大小
# fontsize = 22
# # 初始化
# fig = plt.figure(figsize=figsize)
# ax1 = fig.add_subplot()
# 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
# width = 0.35 # the width of the bars: can also be len(x) sequence
# color_list = ['#222A77', '#6C71AA', '#E1BC95', '#F9DBB8']
#
# # 坐标轴
# ax1.tick_params(labelsize=fontsize)
# ax1.set_xticks(loc)
# ax1.set_xticklabels(xlabels)
# ax1.yaxis.set_major_formatter(FuncFormatter(to_percent))
# # temp_rate = np.zeros(max_x_count)
# # for i in range(len(product_list)):
# # temp_rate += product_list[i]['data']
# # max_rate = np.max(np.hstack((temp_rate, cumulative['data'])))
# ax2.set_xticks([])
# # ax2.set_ylim(0, max_rate + 10)
#
# # 堆叠柱状图
# prod_legend = []
# for i in range(len(product_list)):
# ax = None
# for j in range(len(product_list[i]['data'])):
# product_list[i]['bottom'] = product_list[i].get('bottom', 0)
# product_list[i]['bottom_neg'] = product_list[i].get('bottom_neg', 0)
# if j > 0:
# product_list[i]['bottom'] += product_list[i].get('bottom', 0)
# product_list[i]['bottom_neg'] += product_list[i].get('bottom_neg', 0)
# if i < len(color_list):
# for x in loc:
# if product_list[i]['data'][x] >= 0:
# ax = ax1.bar(x, product_list[i]['data'][x], width, bottom=product_list[i]['bottom'], color=color_list[i], alpha=0.8)
# else:
# ax = ax1.bar(x, product_list[i]['data'][x], width, bottom=product_list[i]['bottom_neg'],
# color=color_list[i], alpha=0.8)
# else:
# for x in loc:
# if product_list[i]['data'][x] >= 0:
# ax = ax1.bar(x, product_list[i]['data'][x], width, bottom=product_list[i]['bottom'], alpha=0.8)
# else:
# ax = ax1.bar(x, product_list[i]['data'][x], width, bottom=product_list[i]['bottom_neg'], alpha=0.8)
# prod_legend.append(ax[0])
# # ax1.legend(prod_legend, [prod['name'] for prod in product_list], bbox_to_anchor=(0.9, -0.1), ncol=4, fontsize=fontsize)
#
# # 画折线图
# ax2.plot(loc, cumulative['data'], color='#C6A774', marker='', linewidth=3, label=cumulative['name'])
# ax2.legend(loc='upper left', fontsize=fontsize)
#
# plt.show()
# # imgdata = BytesIO()
# # fig.savefig(imgdata, format='png', bbox_inches='tight')
# # 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):
......@@ -235,26 +305,26 @@ if __name__ == '__main__':
# contrast = {'name': '同比上涨', 'data': np.array([10, 50, 120, 100, 36, 0, 50, 120, 100, 36, 23, 98])}
# draw_month_return_chart(xlabels, [product], contrast)
# 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')
# product1 = {'name': '塞亚成长1号', 'data': np.array([10, 20, 30, 40, 50, 10, 20, 30, 40, 50, 40, 50])}
# product2 = {'name': '塞亚成长2号', 'data': np.array([10, 20, 30, 40, 50, 10, 20, 30, 40, 50, 40, 50])}
# product3 = {'name': '塞亚成长3号', 'data': np.array([10, 20, 30, 40, 50, 10, 20, 30, 40, 50, 40, 50])}
# product4 = {'name': '塞亚成长4号', 'data': np.array([10, 20, 30, 40, 50, 10, 20, 30, 40, 50, 40, 50])}
# product5 = {'name': '塞亚成长5号', 'data': np.array([10, 20, 30, 40, 50, 10, 20, 30, 40, 50, 40, 50])}
# product6 = {'name': '塞亚成长6号', 'data': np.array([10, 20, 30, 40, 50, 10, 20, 30, 40, 50, 40, 50])}
# product7 = {'name': '塞亚成长7号', 'data': np.array([10, 20, 30, 40, 50, 10, 20, 30, 40, 50, 40, 50])}
# product8 = {'name': '塞亚成长8号', 'data': np.array([10, 20, 30, 40, 50, 10, 20, 30, 40, 50, 40, 50])}
# product_list = [product1, product2, product3, product4, product5, product6, product7, product8]
# cumulative = {'name': '总收益', 'data': np.array([10, 50, 120, 100, 36, 0, 50, 120, 100, 36, 23, 98])}
# draw_contribution_chart(xlabels, product_list, cumulative)
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')
product1 = {'name': '塞亚成长1号', 'data': np.array([-10, 20, 30, 40, 50, 10, 20, 30, 40, 50, 40, 50])}
product2 = {'name': '塞亚成长2号', 'data': np.array([10, 20, 30, 40, 50, 10, 20, 30, 40, 50, 40, 50])}
product3 = {'name': '塞亚成长3号', 'data': np.array([10, 20, 30, 40, 50, 10, 20, 30, 40, 50, 40, 50])}
product4 = {'name': '塞亚成长4号', 'data': np.array([10, 20, 30, 40, 50, 10, 20, 30, 40, 50, 40, 50])}
product5 = {'name': '塞亚成长5号', 'data': np.array([10, 20, 30, 40, 50, 10, 20, 30, 40, 50, 40, 50])}
product6 = {'name': '塞亚成长6号', 'data': np.array([10, 20, 30, 40, 50, 10, 20, 30, 40, 50, 40, 50])}
product7 = {'name': '塞亚成长7号', 'data': np.array([10, 20, 30, 40, 50, 10, 20, 30, 40, 50, 40, 50])}
product8 = {'name': '塞亚成长8号', 'data': np.array([10, 20, 30, 40, 50, 10, 20, 30, 40, 50, 40, 50])}
product_list = [product1, product2, product3, product4, product5, product6, product7, product8]
cumulative = {'name': '总收益', 'data': np.array([10, 50, 120, 100, 36, 0, 50, 120, 100, 36, 23, 98])}
draw_contribution_chart(xlabels, product_list, cumulative)
# 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')
# source_prod = {'name': '远澜银杏1号', 'data': np.array([10, 20, 30, 40, 50, 10, 20, 30, 40, 50, 40, 50])}
# target_prod = {'name': '上证指数', 'data': np.array([-10, 10, 5, 55, 24, 10, 20, 8, 10, 31, 40, 32])}
# draw_comment_chart(xlabels, source_prod, target_prod)
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')
new_combination = {'name': '新组合', 'data': np.array([20, 30, 40, 50, 60, 20, 30, 40, 50, 60, 50, 60])}
origin_combination = {'name': '原组合', 'data': np.array([10, 20, 30, 40, 50, 10, 20, 30, 40, 50, 40, 50])}
index = {'name': '上证指数', 'data': np.array([-10, 10, 5, 55, 24, 10, 20, 8, 10, 31, 40, 32])}
draw_combination_chart(xlabels, new_combination, origin_combination, index)
# 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')
# new_combination = {'name': '新组合', 'data': np.array([20, 30, 40, 50, 60, 20, 30, 40, 50, 60, 50, 60])}
# origin_combination = {'name': '原组合', 'data': np.array([10, 20, 30, 40, 50, 10, 20, 30, 40, 50, 40, 50])}
# index = {'name': '上证指数', 'data': np.array([-10, 10, 5, 55, 24, 10, 20, 8, 10, 31, 40, 32])}
# draw_combination_chart(xlabels, new_combination, origin_combination, index)
from jinja2 import PackageLoader, Environment
from app.service.result_service import UserCustomerResultAdaptor
from app.service.portfolio_diagnose import portfolio_diagnose
from app.service.result_service import UserCustomerResultAdaptor
import numpy as np
# 准备数据
from app.utils.draw import draw_month_return_chart
from app.utils.draw import draw_month_return_chart, draw_contribution_chart
from app.utils.radar_chart import gen_radar_chart
ifa_id = 'USER_INFO15914346866762'
customer_id = '202009281545001'
......@@ -13,27 +16,48 @@ 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)
# 持仓组合点评
old_evaluation = portfolio_diagnose.old_evaluation('default', group_result, user_customer)
# 贡献分解
g_data = group_result["contribution_decomposition"]
contribution_decomposition = draw_contribution_chart(g_data['xlabels'], g_data['product_list'], g_data['cumulative'])
# 个基点评
single_fund_data_list = []
portfolio_evaluation = portfolio_diagnose.old_portfolio_evaluation()
radar_chart_data = portfolio_diagnose.single_fund_radar()
# for one in radar_chart_data:
# print(gen_radar_chart(one))
radar_chart_path = gen_radar_chart(radar_chart_data[0])
single_fund_data_list.append({
'fund_name': radar_chart_data[0]['name'],
'status': '保留',
'evaluation': portfolio_evaluation[0]['data'],
'radar_chart_path': radar_chart_path
})
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 +97,10 @@ 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,
'old_evaluation': old_evaluation,
'contribution_decomposition': contribution_decomposition,
'single_fund_data_list': single_fund_data_list
}
......
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