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
f0f0f190
Commit
f0f0f190
authored
Dec 09, 2020
by
李宗熹
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'origin/dev' into dev
parents
416fd0a4
fbac2590
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
155 additions
and
68588 deletions
+155
-68588
fund_report.iml
.idea/fund_report.iml
+2
-0
modules.xml
.idea/modules.xml
+2
-0
vcs.xml
.idea/vcs.xml
+2
-1
data_service.py
app/service/data_service.py
+2
-2
portfolio_diagnose.py
app/service/portfolio_diagnose.py
+77
-8
result_service_v2.py
app/service/result_service_v2.py
+1
-1
monthReportV2.html
app/templates/v2/monthReportV2.html
+21
-17
draw.py
app/utils/draw.py
+5
-1
jinjia2html.py
app/utils/jinjia2html.py
+34
-24
timed_task.py
app/utils/timed_task.py
+9
-9
tamp_course_order.log
logs/tamp_course_order.log
+0
-68525
tamp_order.log
logs/tamp_order.log
+0
-0
No files found.
.idea/fund_report.iml
View file @
f0f0f190
...
@@ -4,6 +4,8 @@
...
@@ -4,6 +4,8 @@
<content
url=
"file://$MODULE_DIR$"
/>
<content
url=
"file://$MODULE_DIR$"
/>
<orderEntry
type=
"jdk"
jdkName=
"Python 3.7"
jdkType=
"Python SDK"
/>
<orderEntry
type=
"jdk"
jdkName=
"Python 3.7"
jdkType=
"Python SDK"
/>
<orderEntry
type=
"sourceFolder"
forTests=
"false"
/>
<orderEntry
type=
"sourceFolder"
forTests=
"false"
/>
<orderEntry
type=
"module"
module-name=
"tamp_course_order"
/>
<orderEntry
type=
"module"
module-name=
"tamp_app_scan"
/>
</component>
</component>
<component
name=
"TestRunnerService"
>
<component
name=
"TestRunnerService"
>
<option
name=
"PROJECT_TEST_RUNNER"
value=
"Unittests"
/>
<option
name=
"PROJECT_TEST_RUNNER"
value=
"Unittests"
/>
...
...
.idea/modules.xml
View file @
f0f0f190
...
@@ -3,6 +3,8 @@
...
@@ -3,6 +3,8 @@
<component
name=
"ProjectModuleManager"
>
<component
name=
"ProjectModuleManager"
>
<modules>
<modules>
<module
fileurl=
"file://$PROJECT_DIR$/.idea/fund_report.iml"
filepath=
"$PROJECT_DIR$/.idea/fund_report.iml"
/>
<module
fileurl=
"file://$PROJECT_DIR$/.idea/fund_report.iml"
filepath=
"$PROJECT_DIR$/.idea/fund_report.iml"
/>
<module
fileurl=
"file://$PROJECT_DIR$/../tamp_app_scan/.idea/tamp_app_scan.iml"
filepath=
"$PROJECT_DIR$/../tamp_app_scan/.idea/tamp_app_scan.iml"
/>
<module
fileurl=
"file://$PROJECT_DIR$/../tamp_course_order/.idea/tamp_course_order.iml"
filepath=
"$PROJECT_DIR$/../tamp_course_order/.idea/tamp_course_order.iml"
/>
</modules>
</modules>
</component>
</component>
</project>
</project>
\ No newline at end of file
.idea/vcs.xml
View file @
f0f0f190
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8"?>
<project
version=
"4"
>
<project
version=
"4"
>
<component
name=
"VcsDirectoryMappings"
>
<component
name=
"VcsDirectoryMappings"
>
<mapping
directory=
"$PROJECT_DIR$"
vcs=
"Git"
/>
<mapping
directory=
""
vcs=
"Git"
/>
<mapping
directory=
"$PROJECT_DIR$/../tamp_app_scan"
vcs=
"Git"
/>
</component>
</component>
</project>
</project>
\ No newline at end of file
app/service/data_service.py
View file @
f0f0f190
...
@@ -190,7 +190,7 @@ class UserCustomerDataAdaptor:
...
@@ -190,7 +190,7 @@ class UserCustomerDataAdaptor:
confirm_date_nav_data
=
p_nav_df
[
p_nav_df
.
index
==
confirm_share_date
][
cur_fund_id
]
.
tail
(
1
)
confirm_date_nav_data
=
p_nav_df
[
p_nav_df
.
index
==
confirm_share_date
][
cur_fund_id
]
.
tail
(
1
)
confirm_date_cnav_data
=
p_cnav_df
[
p_cnav_df
.
index
==
confirm_share_date
][
cur_fund_id
]
.
tail
(
1
)
confirm_date_cnav_data
=
p_cnav_df
[
p_cnav_df
.
index
==
confirm_share_date
][
cur_fund_id
]
.
tail
(
1
)
diff_nav
=
Decimal
(
row
[
"nav"
])
-
Decimal
(
confirm_date_nav_data
.
values
[
0
])
diff_nav
=
Decimal
(
row
[
"nav"
])
-
Decimal
(
confirm_date_nav_data
.
values
[
0
])
cur_cnav
=
confirm_date_cnav_data
.
values
[
0
]
+
diff_nav
cur_cnav
=
Decimal
(
confirm_date_cnav_data
.
values
[
0
])
+
diff_nav
cnav_df
.
loc
[
confirm_share_date
,
cur_fund_id
]
=
cur_cnav
cnav_df
.
loc
[
confirm_share_date
,
cur_fund_id
]
=
cur_cnav
cnav_df
=
cnav_df
.
dropna
(
axis
=
0
,
how
=
"all"
)
.
fillna
(
method
=
'ffill'
)
cnav_df
=
cnav_df
.
dropna
(
axis
=
0
,
how
=
"all"
)
.
fillna
(
method
=
'ffill'
)
...
@@ -285,7 +285,7 @@ class UserCustomerDataAdaptor:
...
@@ -285,7 +285,7 @@ class UserCustomerDataAdaptor:
confirm_date_nav_data
=
p_nav_df
[
p_nav_df
.
index
==
confirm_share_date
][
cur_fund_id
]
.
tail
(
1
)
confirm_date_nav_data
=
p_nav_df
[
p_nav_df
.
index
==
confirm_share_date
][
cur_fund_id
]
.
tail
(
1
)
confirm_date_cnav_data
=
p_cnav_df
[
p_cnav_df
.
index
==
confirm_share_date
][
cur_fund_id
]
.
tail
(
1
)
confirm_date_cnav_data
=
p_cnav_df
[
p_cnav_df
.
index
==
confirm_share_date
][
cur_fund_id
]
.
tail
(
1
)
diff_nav
=
Decimal
(
row
[
"nav"
])
-
Decimal
(
confirm_date_nav_data
.
values
[
0
])
diff_nav
=
Decimal
(
row
[
"nav"
])
-
Decimal
(
confirm_date_nav_data
.
values
[
0
])
cur_cnav
=
confirm_date_cnav_data
.
values
[
0
]
+
diff_nav
cur_cnav
=
Decimal
(
confirm_date_cnav_data
.
values
[
0
])
+
diff_nav
cnav_df
.
loc
[
confirm_share_date
,
cur_fund_id
]
=
cur_cnav
cnav_df
.
loc
[
confirm_share_date
,
cur_fund_id
]
=
cur_cnav
cnav_df
=
cnav_df
.
dropna
(
axis
=
0
,
how
=
"all"
)
.
fillna
(
method
=
'ffill'
)
cnav_df
=
cnav_df
.
dropna
(
axis
=
0
,
how
=
"all"
)
.
fillna
(
method
=
'ffill'
)
...
...
app/service/portfolio_diagnose.py
View file @
f0f0f190
...
@@ -707,9 +707,12 @@ class PortfolioDiagnose(object):
...
@@ -707,9 +707,12 @@ class PortfolioDiagnose(object):
# 覆盖的基金名称
# 覆盖的基金名称
strategy_name_evaluate
=
""
.
join
(
uniqe_strategy_name
)[:
-
1
]
strategy_name_evaluate
=
""
.
join
(
uniqe_strategy_name
)[:
-
1
]
if
len
(
uniqe_strategy
)
/
float
(
len
(
strategy_list
))
>
0.6
:
try
:
strategy_distribution_evaluate
=
"策略上有一定分散"
if
len
(
uniqe_strategy
)
/
float
(
len
(
strategy_list
))
>
0.6
:
else
:
strategy_distribution_evaluate
=
"策略上有一定分散"
else
:
strategy_distribution_evaluate
=
"策略分散程度不高"
except
ZeroDivisionError
:
strategy_distribution_evaluate
=
"策略分散程度不高"
strategy_distribution_evaluate
=
"策略分散程度不高"
# 相关性
# 相关性
if
len
(
self
.
abandon_fund_corr
)
>
0
:
if
len
(
self
.
abandon_fund_corr
)
>
0
:
...
@@ -749,7 +752,73 @@ class PortfolioDiagnose(object):
...
@@ -749,7 +752,73 @@ class PortfolioDiagnose(object):
ret
=
[]
ret
=
[]
for
k
,
v
in
data
.
items
():
for
k
,
v
in
data
.
items
():
ret
.
append
(
sentence
[
k
]
.
format
(
*
data
[
k
])
.
replace
(
",;"
,
";"
))
ret
.
append
(
sentence
[
k
]
.
format
(
*
data
[
k
])
.
replace
(
",;"
,
";"
))
return
ret
# 旧组合累积收益df
group_result_data
=
group_result
[
group_name
]
hold_info
=
group_result_data
[
"group_hoding_info"
]
hold_info_df
=
pd
.
DataFrame
(
hold_info
)
group_order_df
=
data_adaptor
.
user_customer_order_df
[
data_adaptor
.
user_customer_order_df
[
"folio_name"
]
==
group_name
]
group_order_start_date
=
pd
.
to_datetime
(
group_order_df
[
"confirm_share_date"
]
.
min
())
freq_max
=
group_order_df
[
"freq"
]
.
max
()
n_freq
=
freq_days
(
int
(
freq_max
))
old_return_df
=
group_result_data
[
"return_df"
]
old_return_df
[
"cum_return_ratio"
]
=
old_return_df
[
"cum_return_ratio"
]
-
1
# 原组合总市值, 区间收益, 年化收益, 波动率, 最大回撤, 夏普比率
total_asset
=
round
(
hold_info_df
[
"market_values"
]
.
sum
(),
2
)
old_return
=
group_result_data
[
"cumulative_return"
]
old_return_ratio_year
=
group_result_data
[
"return_ratio_year"
]
old_volatility
=
group_result_data
[
"volatility"
]
old_max_drawdown
=
group_result_data
[
"max_drawdown"
]
old_sharpe
=
group_result_data
[
"sharpe"
]
# 指数收益
index_data
=
get_index_daily
(
self
.
index_id
,
self
.
start_date
)
index_data
=
pd
.
merge
(
index_data
,
self
.
propose_portfolio
,
how
=
'inner'
,
left_index
=
True
,
right_index
=
True
)
index_return
=
index_data
.
iloc
[:,
:]
/
index_data
.
iloc
[
0
,
:]
-
1
# 指数收益
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"
],
n_freq
)
index_volatility
=
volatility
(
index_return
[
"new_index_return"
]
+
1
,
n_freq
)
index_drawdown
=
max_drawdown
(
index_return
[
"new_index_return"
]
+
1
)
index_sim
=
simple_return
(
index_return
[
"new_index_return"
]
+
1
)
index_exc
=
excess_return
(
index_sim
,
BANK_RATE
,
n_freq
)
index_sharpe
=
sharpe_ratio
(
index_exc
,
index_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
)
return_compare_df
[
"date"
]
=
return_compare_df
.
index
return_compare_df
[
"date"
]
=
return_compare_df
[
"date"
]
.
apply
(
lambda
x
:
x
.
strftime
(
"
%
Y-
%
m-
%
d"
))
return_compare_df
.
iloc
[
1
:
-
1
,
:][
"date"
]
=
""
old_return_compare_result
=
{
"index"
:
{
"name"
:
"中证500"
,
"data"
:
return_compare_df
[
"new_index_return"
]
.
values
*
100
},
"origin_combination"
:
{
"name"
:
"原组合"
,
"data"
:
return_compare_df
[
"cum_return_ratio"
]
.
values
*
100
},
"xlabels"
:
return_compare_df
[
"date"
]
.
values
}
# 指标对比
old_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
)}
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
)}
old_indicator_compare
=
[
old_indicator
,
index_indicator
]
return
ret
,
old_return_compare_result
,
old_indicator_compare
def
new_evaluation
(
self
,
group_name
,
group_result
,
data_adaptor
):
def
new_evaluation
(
self
,
group_name
,
group_result
,
data_adaptor
):
try
:
try
:
...
@@ -855,7 +924,7 @@ class PortfolioDiagnose(object):
...
@@ -855,7 +924,7 @@ class PortfolioDiagnose(object):
index_return_ratio_year
=
annual_return
(
index_return
[
"new_index_return"
]
.
values
[
-
1
],
index_return
[
"new_index_return"
],
n_freq
)
index_return_ratio_year
=
annual_return
(
index_return
[
"new_index_return"
]
.
values
[
-
1
],
index_return
[
"new_index_return"
],
n_freq
)
index_volatility
=
volatility
(
index_return
[
"new_index_return"
]
+
1
,
n_freq
)
index_volatility
=
volatility
(
index_return
[
"new_index_return"
]
+
1
,
n_freq
)
index_drawdown
=
max_drawdown
(
index_return
[
"new_index_return"
]
+
1
)
index_drawdown
=
max_drawdown
(
index_return
[
"new_index_return"
]
+
1
)
index_sim
=
simple_return
(
propose_fund_return_limit_data
[
"new
_return"
]
+
1
)
index_sim
=
simple_return
(
index_return
[
"new_index
_return"
]
+
1
)
index_exc
=
excess_return
(
index_sim
,
BANK_RATE
,
n_freq
)
index_exc
=
excess_return
(
index_sim
,
BANK_RATE
,
n_freq
)
index_sharpe
=
sharpe_ratio
(
index_exc
,
index_sim
,
n_freq
)
index_sharpe
=
sharpe_ratio
(
index_exc
,
index_sim
,
n_freq
)
...
@@ -868,9 +937,9 @@ class PortfolioDiagnose(object):
...
@@ -868,9 +937,9 @@ class PortfolioDiagnose(object):
return_compare_df
[
"date"
]
=
return_compare_df
[
"date"
]
.
apply
(
lambda
x
:
x
.
strftime
(
"
%
Y-
%
m-
%
d"
))
return_compare_df
[
"date"
]
=
return_compare_df
[
"date"
]
.
apply
(
lambda
x
:
x
.
strftime
(
"
%
Y-
%
m-
%
d"
))
return_compare_df
.
iloc
[
1
:
-
1
,:][
"date"
]
=
""
return_compare_df
.
iloc
[
1
:
-
1
,:][
"date"
]
=
""
return_compare_result
=
{
return_compare_result
=
{
"new_combination"
:
{
"name"
:
"新组合"
,
"data"
:
return_compare_df
[
"new_return"
]
.
values
},
"new_combination"
:
{
"name"
:
"新组合"
,
"data"
:
return_compare_df
[
"new_return"
]
.
values
*
100
},
"index"
:
{
"name"
:
"中证500"
,
"data"
:
return_compare_df
[
"new_index_return"
]
.
values
},
"index"
:
{
"name"
:
"中证500"
,
"data"
:
return_compare_df
[
"new_index_return"
]
.
values
*
100
},
"origin_combination"
:
{
"name"
:
"原组合"
,
"data"
:
return_compare_df
[
"cum_return_ratio"
]
.
values
},
"origin_combination"
:
{
"name"
:
"原组合"
,
"data"
:
return_compare_df
[
"cum_return_ratio"
]
.
values
*
100
},
"xlabels"
:
return_compare_df
[
"date"
]
.
values
"xlabels"
:
return_compare_df
[
"date"
]
.
values
}
}
...
...
app/service/result_service_v2.py
View file @
f0f0f190
...
@@ -369,8 +369,8 @@ class UserCustomerResultAdaptor(UserCustomerDataAdaptor):
...
@@ -369,8 +369,8 @@ class UserCustomerResultAdaptor(UserCustomerDataAdaptor):
fund_hoding_info
=
{
"fund_strategy_name"
:
dict_substrategy
[
int
(
row
[
"substrategy"
])],
"fund_name"
:
row
[
"fund_name"
]}
fund_hoding_info
=
{
"fund_strategy_name"
:
dict_substrategy
[
int
(
row
[
"substrategy"
])],
"fund_name"
:
row
[
"fund_name"
]}
fund_hoding_info
[
"confirm_date"
]
=
row
[
"confirm_share_date"
]
fund_hoding_info
[
"confirm_date"
]
=
row
[
"confirm_share_date"
]
fund_hoding_info
[
"hold_year"
]
=
round
((
self
.
end_date
-
pd
.
to_datetime
(
row
[
"confirm_share_date"
]))
.
days
/
365.0
,
2
)
# 存续年数
fund_hoding_info
[
"hold_year"
]
=
round
((
self
.
end_date
-
pd
.
to_datetime
(
row
[
"confirm_share_date"
]))
.
days
/
365.0
,
2
)
# 存续年数
fund_hoding_info
[
"weight"
]
=
round
(
float
(
row
[
"confirm_amount"
])
/
total_market_values
*
100
,
2
)
# 月末占比
fund_hoding_info
[
"market_values"
]
=
round
((
float
(
row
[
"confirm_share"
])
*
(
fund_basic_info
[
"cur_cnav"
]
-
confirm_cnav
)
+
float
(
row
[
"confirm_amount"
]))
/
10000
,
2
)
fund_hoding_info
[
"market_values"
]
=
round
((
float
(
row
[
"confirm_share"
])
*
(
fund_basic_info
[
"cur_cnav"
]
-
confirm_cnav
)
+
float
(
row
[
"confirm_amount"
]))
/
10000
,
2
)
fund_hoding_info
[
"weight"
]
=
round
(
fund_hoding_info
[
"market_values"
]
/
total_market_values
*
10000.0
*
100
,
2
)
# 月末占比
fund_hoding_info
[
"cost"
]
=
round
(
float
(
row
[
"confirm_amount"
])
/
10000
,
2
)
# 投资本金
fund_hoding_info
[
"cost"
]
=
round
(
float
(
row
[
"confirm_amount"
])
/
10000
,
2
)
# 投资本金
# 当月收益
# 当月收益
last_month_cnav_serise
=
p_result_cnav_data
[
p_result_cnav_data
.
index
<
pd
.
to_datetime
(
self
.
month_start_date
)][
row
[
"fund_id"
]]
.
dropna
()
last_month_cnav_serise
=
p_result_cnav_data
[
p_result_cnav_data
.
index
<
pd
.
to_datetime
(
self
.
month_start_date
)][
row
[
"fund_id"
]]
.
dropna
()
...
...
app/templates/v2/monthReportV2.html
View file @
f0f0f190
...
@@ -886,7 +886,11 @@
...
@@ -886,7 +886,11 @@
}
}
.financial_show
.financial_show_right
.financial_team
.financial_team_img
{
.financial_show
.financial_show_right
.financial_team
.financial_team_img
{
width
:
100%
;
/*width: 100%;*/
/*height: 100%;*/
/*-o-object-fit: cover;*/
/*object-fit: cover;*/
width
:
auto
;
height
:
100%
;
height
:
100%
;
-o-object-fit
:
cover
;
-o-object-fit
:
cover
;
object-fit
:
cover
;
object-fit
:
cover
;
...
@@ -1363,20 +1367,20 @@
...
@@ -1363,20 +1367,20 @@
<tr>
<tr>
<tr
class=
"yellow"
>
<tr
class=
"yellow"
>
<td>
{{
indicator_compare[1
]["group_name"]}}
</td>
<td>
{{
old_indicator_compare[0
]["group_name"]}}
</td>
<td>
{{
indicator_compare[1
]["return_ratio"]}}
</td>
<td>
{{
old_indicator_compare[0
]["return_ratio"]}}
</td>
<td>
{{
indicator_compare[1
]["return_ratio_year"]}}
</td>
<td>
{{
old_indicator_compare[0
]["return_ratio_year"]}}
</td>
<td>
{{
indicator_compare[1
]["volatility"]}}
</td>
<td>
{{
old_indicator_compare[0
]["volatility"]}}
</td>
<td>
{{
indicator_compare[1
]["max_drawdown"]}}
</td>
<td>
{{
old_indicator_compare[0
]["max_drawdown"]}}
</td>
<td>
{{
indicator_compare[1
]["sharpe"]}}
</td>
<td>
{{
old_indicator_compare[0
]["sharpe"]}}
</td>
</tr>
</tr>
<tr
>
<tr
>
<td>
{{
indicator_compare[2
]["group_name"]}}
</td>
<td>
{{
old_indicator_compare[1
]["group_name"]}}
</td>
<td>
{{
indicator_compare[2
]["return_ratio"]}}
</td>
<td>
{{
old_indicator_compare[1
]["return_ratio"]}}
</td>
<td>
{{
indicator_compare[2
]["return_ratio_year"]}}
</td>
<td>
{{
old_indicator_compare[1
]["return_ratio_year"]}}
</td>
<td>
{{
indicator_compare[2
]["volatility"]}}
</td>
<td>
{{
old_indicator_compare[1
]["volatility"]}}
</td>
<td>
{{
indicator_compare[2
]["max_drawdown"]}}
</td>
<td>
{{
old_indicator_compare[1
]["max_drawdown"]}}
</td>
<td>
{{
indicator_compare[2
]["sharpe"]}}
</td>
<td>
{{
old_indicator_compare[1
]["sharpe"]}}
</td>
</tr>
</tr>
</table>
</table>
...
@@ -1559,12 +1563,12 @@
...
@@ -1559,12 +1563,12 @@
<th>
基金简称
</th>
<th>
基金简称
</th>
<th>
买入时间
</th>
<th>
买入时间
</th>
<th>
存续年数
</th>
<th>
存续年数
</th>
<th>
投资本金 (万
元
)
</th>
<th>
投资本金 (万)
</th>
<th>
当月收益 (万
元
)
</th>
<th>
当月收益 (万)
</th>
<th>
当月收益率 (%)
</th>
<th>
当月收益率 (%)
</th>
<th>
月末市值 (万
元
)
</th>
<th>
月末市值 (万)
</th>
<th>
月末占比 (%)
</th>
<th>
月末占比 (%)
</th>
<th>
累计收益 (万
元
)
</th>
<th>
累计收益 (万)
</th>
<th>
累计收益率 (%)
</th>
<th>
累计收益率 (%)
</th>
<th>
年化收益率 (%)
</th>
<th>
年化收益率 (%)
</th>
</tr>
</tr>
...
...
app/utils/draw.py
View file @
f0f0f190
...
@@ -84,7 +84,7 @@ def draw_month_return_chart(xlabels, product_list, cumulative):
...
@@ -84,7 +84,7 @@ def draw_month_return_chart(xlabels, product_list, cumulative):
ax2
.
plot
(
loc
,
cumulative
[
'data'
],
color
=
'#D40000'
,
marker
=
'.'
,
linewidth
=
3
,
label
=
cumulative
[
'name'
])
ax2
.
plot
(
loc
,
cumulative
[
'data'
],
color
=
'#D40000'
,
marker
=
'.'
,
linewidth
=
3
,
label
=
cumulative
[
'name'
])
# 添加数字标签
# 添加数字标签
for
a
,
b
in
zip
(
range
(
len
(
xlabels
)),
cumulative
[
'data'
]):
for
a
,
b
in
zip
(
range
(
len
(
xlabels
)),
cumulative
[
'data'
]):
ax2
.
text
(
a
+
0.
2
,
b
+
0.1
,
'
%.2
f'
%
b
+
'
%
'
,
ha
=
'center'
,
va
=
'bottom'
,
fontsize
=
fontsize
,
color
=
'#D40000'
)
ax2
.
text
(
a
+
0.
1
,
b
+
0.1
,
'
%.2
f'
%
b
+
'
%
'
,
ha
=
'center'
,
va
=
'bottom'
,
fontsize
=
fontsize
,
color
=
'#D40000'
)
ax2
.
legend
(
loc
=
'upper center'
,
fontsize
=
fontsize
)
ax2
.
legend
(
loc
=
'upper center'
,
fontsize
=
fontsize
)
# plt.show()
# plt.show()
...
@@ -117,6 +117,7 @@ def draw_contribution_chart(xlabels, product_list, cumulative):
...
@@ -117,6 +117,7 @@ def draw_contribution_chart(xlabels, product_list, cumulative):
ax1
.
set_xticks
(
loc
)
ax1
.
set_xticks
(
loc
)
ax1
.
set_xticklabels
(
xlabels
)
ax1
.
set_xticklabels
(
xlabels
)
ax1
.
yaxis
.
set_major_formatter
(
FuncFormatter
(
to_percent
))
ax1
.
yaxis
.
set_major_formatter
(
FuncFormatter
(
to_percent
))
ax1
.
grid
(
axis
=
'y'
)
# temp_rate = np.zeros(max_x_count)
# temp_rate = np.zeros(max_x_count)
# for i in range(len(product_list)):
# for i in range(len(product_list)):
# temp_rate += product_list[i]['data']
# temp_rate += product_list[i]['data']
...
@@ -143,6 +144,9 @@ def draw_contribution_chart(xlabels, product_list, cumulative):
...
@@ -143,6 +144,9 @@ def draw_contribution_chart(xlabels, product_list, cumulative):
# 画折线图
# 画折线图
ax2
.
plot
(
loc
,
cumulative
[
'data'
],
color
=
'#B40A15'
,
marker
=
''
,
linewidth
=
3
,
label
=
cumulative
[
'name'
])
ax2
.
plot
(
loc
,
cumulative
[
'data'
],
color
=
'#B40A15'
,
marker
=
''
,
linewidth
=
3
,
label
=
cumulative
[
'name'
])
# 添加数字标签
for
a
,
b
in
zip
(
range
(
len
(
xlabels
)),
cumulative
[
'data'
]):
ax2
.
text
(
a
+
0.2
,
b
+
0.1
,
'
%.2
f'
%
b
+
'
%
'
,
ha
=
'center'
,
va
=
'bottom'
,
fontsize
=
fontsize
,
color
=
'#B40A15'
)
ax2
.
legend
(
loc
=
'upper left'
,
fontsize
=
fontsize
)
ax2
.
legend
(
loc
=
'upper left'
,
fontsize
=
fontsize
)
imgdata
=
BytesIO
()
imgdata
=
BytesIO
()
...
...
app/utils/jinjia2html.py
View file @
f0f0f190
...
@@ -37,20 +37,20 @@ class DataIntegrate:
...
@@ -37,20 +37,20 @@ class DataIntegrate:
self
.
comments_on_position_portfolio
()
self
.
comments_on_position_portfolio
()
# 贡献分解
# 贡献分解
self
.
contribution_deco
()
self
.
contribution_deco
()
# 个基点评
self
.
single_fund_comment
()
# 旧相关性
self
.
get_old_correlation
()
# 新相关性
self
.
get_new_correlation
()
# 新增基金
self
.
propose_fund
()
# 目标与业绩
# 目标与业绩
self
.
objectives_performance
(
self
.
group_result
)
self
.
objectives_performance
(
self
.
group_result
)
# 个基点评
self
.
single_fund_comment
()
# 旧收益比较
# 旧收益比较
self
.
get_old_compare_pic
()
self
.
get_old_compare_pic
()
# 新收益比较
# 旧相关性
self
.
get_transfer_suggestions
()
self
.
get_old_correlation
()
# # 新增基金
# self.propose_fund()
# # 新收益比较
# self.get_transfer_suggestions()
# # 新相关性
# self.get_new_correlation()
# 渲染模版
# 渲染模版
self
.
render_data
()
self
.
render_data
()
...
@@ -82,8 +82,8 @@ class DataIntegrate:
...
@@ -82,8 +82,8 @@ class DataIntegrate:
self
.
monthly_table_return
=
self
.
df
[
"month_return_data_dict"
]
self
.
monthly_table_return
=
self
.
df
[
"month_return_data_dict"
]
def
comments_on_position_portfolio
(
self
):
def
comments_on_position_portfolio
(
self
):
"""旧持仓组合点评."""
"""旧持仓组合点评.
旧贡献分解数据
"""
self
.
old_evaluation
=
self
.
portfolio_diagnose
.
old_evaluation
(
'default'
,
self
.
d
,
self
.
user_customer
)
self
.
old_evaluation
,
self
.
old_return_compare_data
,
self
.
old_indicator_compare
=
self
.
portfolio_diagnose
.
old_evaluation
(
'default'
,
self
.
d
,
self
.
user_customer
)
def
contribution_deco
(
self
):
def
contribution_deco
(
self
):
"""贡献分解."""
"""贡献分解."""
...
@@ -116,12 +116,14 @@ class DataIntegrate:
...
@@ -116,12 +116,14 @@ class DataIntegrate:
def
get_old_compare_pic
(
self
):
def
get_old_compare_pic
(
self
):
"""旧收益比较"""
"""旧收益比较"""
self
.
suggestions_result
,
self
.
suggestions_result_asset
,
self
.
return_compare_data
,
\
self
.
old_return_compare_pic
=
draw_old_combination_chart
(
self
.
old_return_compare_data
[
"xlabels"
],
self
.
old_return_compare_data
[
"origin_combination"
],
self
.
old_return_compare_data
[
"index"
])
self
.
indicator_compare
,
self
.
new_group_evaluation
=
self
.
portfolio_diagnose
.
new_evaluation
(
"default"
,
self
.
d
,
self
.
user_customer
)
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
):
def
get_transfer_suggestions
(
self
):
"""新收益比较,调仓建议"""
"""新收益比较,调仓建议"""
self
.
suggestions_result
,
self
.
suggestions_result_asset
,
self
.
return_compare_data
,
\
self
.
indicator_compare
,
self
.
new_group_evaluation
=
self
.
portfolio_diagnose
.
new_evaluation
(
"default"
,
self
.
d
,
self
.
user_customer
)
self
.
return_compare_pic
=
draw_combination_chart
(
self
.
return_compare_data
[
"xlabels"
],
self
.
return_compare_data
[
"new_combination"
],
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"
])
self
.
return_compare_data
[
"origin_combination"
],
self
.
return_compare_data
[
"index"
])
...
@@ -199,9 +201,9 @@ class DataIntegrate:
...
@@ -199,9 +201,9 @@ class DataIntegrate:
# 个基点评
# 个基点评
'box5'
:
'block'
,
'box5'
:
'block'
,
# 优化组合建议
# 优化组合建议
'box6'
:
'block'
,
'box6'
:
None
,
# 新增基金
# 新增基金
'box7'
:
'block'
,
'box7'
:
None
,
# 结尾
# 结尾
'box8'
:
'block'
,
'box8'
:
'block'
,
'cover_back'
:
template_folder
+
'/v2/img/cover-back.png'
,
'cover_back'
:
template_folder
+
'/v2/img/cover-back.png'
,
...
@@ -242,17 +244,25 @@ class DataIntegrate:
...
@@ -242,17 +244,25 @@ class DataIntegrate:
'group_hoding_info'
:
self
.
group_hoding_info
,
'group_hoding_info'
:
self
.
group_hoding_info
,
'group_hoding_info_total'
:
self
.
group_hoding_info_total
,
'group_hoding_info_total'
:
self
.
group_hoding_info_total
,
'old_evaluation'
:
self
.
old_evaluation
,
'old_evaluation'
:
self
.
old_evaluation
,
'old_indicator_compare'
:
self
.
old_indicator_compare
,
'contribution_decomposition'
:
self
.
contribution_decomposition
,
'contribution_decomposition'
:
self
.
contribution_decomposition
,
'single_fund_data_list'
:
self
.
single_fund_data_list
,
'single_fund_data_list'
:
self
.
single_fund_data_list
,
'old_correlation'
:
self
.
old_correlation
,
'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
,
'old_return_compare_pic'
:
self
.
old_return_compare_pic
,
'return_compare_pic'
:
self
.
return_compare_pic
,
# 'new_correlation': self.new_correlation,
'indicator_compare'
:
self
.
indicator_compare
,
# 'propose_fund_data_list': self.propose_fund_data_list,
'new_group_evaluation'
:
self
.
new_group_evaluation
# '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'
:
[]
}
}
# 开始渲染html模板
# 开始渲染html模板
...
...
app/utils/timed_task.py
View file @
f0f0f190
...
@@ -8,7 +8,7 @@
...
@@ -8,7 +8,7 @@
from
app.api.engine
import
tamp_user_engine
,
tamp_order_engine
,
TAMP_SQL
from
app.api.engine
import
tamp_user_engine
,
tamp_order_engine
,
TAMP_SQL
from
sqlalchemy.ext.declarative
import
declarative_base
from
sqlalchemy.ext.declarative
import
declarative_base
from
sqlalchemy
import
Column
,
String
,
Integer
from
sqlalchemy
import
Column
,
String
,
Integer
,
and_
from
app.utils.jinjia2html
import
DataIntegrate
from
app.utils.jinjia2html
import
DataIntegrate
Base
=
declarative_base
()
Base
=
declarative_base
()
...
@@ -36,26 +36,26 @@ class Customer(Base):
...
@@ -36,26 +36,26 @@ class Customer(Base):
def
call_month_report
(
ifauser_id
,
ifauser_name
,
customer_id
,
customer_name
):
def
call_month_report
(
ifauser_id
,
ifauser_name
,
customer_id
,
customer_name
):
print
(
'开始制作IFA: {}, 客户: {}的基金月报'
.
format
(
ifauser_name
,
customer_name
))
#
print('开始制作IFA: {}, 客户: {}的基金月报'.format(ifauser_name, customer_name))
try
:
#
try:
DataIntegrate
(
ifauser_id
,
customer_id
,
'{}_{}_.pdf'
.
format
(
ifauser_name
,
customer_name
))
DataIntegrate
(
ifauser_id
,
customer_id
,
'{}_{}_.pdf'
.
format
(
ifauser_name
,
customer_name
))
except
:
# except IndexError
:
print
(
"发生异常,下一个走起!"
)
#
print("发生异常,下一个走起!")
with
TAMP_SQL
(
tamp_user_engine
)
as
tamp_user
,
TAMP_SQL
(
tamp_order_engine
)
as
tamp_order
:
with
TAMP_SQL
(
tamp_user_engine
)
as
tamp_user
,
TAMP_SQL
(
tamp_order_engine
)
as
tamp_order
:
tamp_user_session
=
tamp_user
.
session
tamp_user_session
=
tamp_user
.
session
# 获取所有 ifauser
# 获取所有 ifauser
ifausers
=
tamp_user_session
.
query
(
IfaUser
)
.
all
()
ifausers
=
tamp_user_session
.
query
(
IfaUser
)
.
filter
(
IfaUser
.
id
.
in_
([
'USER_INFO15916072577875'
]))
.
all
()
tamp_order_session
=
tamp_order
.
session
tamp_order_session
=
tamp_order
.
session
# for ifauser in ifausers:
# for ifauser in ifausers:
for
ifauser
in
ifausers
:
for
ifauser
in
ifausers
:
# 获取某个 ifa 的所有 customer
# 获取某个 ifa 的所有 customer
customers
=
tamp_order_session
.
query
(
Ifa_Customer
)
.
\
customers
=
tamp_order_session
.
query
(
Ifa_Customer
)
.
\
filter
_by
(
ifa_id
=
ifauser
.
id
)
.
all
()
filter
(
and_
(
Ifa_Customer
.
ifa_id
==
ifauser
.
id
,
Ifa_Customer
.
customer_id
.
in_
([
'6716613804966817792'
]))
)
.
all
()
# 循环这个 ifa 的所有 customer
# 循环这个 ifa 的所有 customer
for
customer
in
customers
:
for
customer
in
customers
:
customer_full
=
tamp_order_session
.
query
(
Customer
)
.
\
customer_full
=
tamp_order_session
.
query
(
Customer
)
.
\
...
...
logs/tamp_course_order.log
deleted
100644 → 0
View file @
416fd0a4
This diff is collapsed.
Click to expand it.
logs/tamp_order.log
deleted
100644 → 0
View file @
416fd0a4
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