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
83512303
Commit
83512303
authored
Jan 04, 2021
by
赵杰
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
新版本持仓月报
parent
d71cd876
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
22 additions
and
19 deletions
+22
-19
data_service_v2_1.py
app/service/data_service_v2_1.py
+7
-7
portfolio_diagnose.py
app/service/portfolio_diagnose.py
+4
-4
result_service_v2.py
app/service/result_service_v2.py
+7
-4
monthReportV2.1.html
app/templates/v2/monthReportV2.1.html
+1
-1
jinjia2html_v2.py
app/utils/jinjia2html_v2.py
+3
-3
No files found.
app/service/data_service_v2_1.py
View file @
83512303
...
...
@@ -32,17 +32,17 @@ class UserCustomerDataAdaptor:
all_fund_distribution
=
{}
all_fund_performance
=
{}
def
__init__
(
self
,
user_id
,
customer_id
,
end_date
=
str
(
datetime
.
date
.
today
()
),
index_id
=
"IN0000007M"
):
def
__init__
(
self
,
user_id
,
customer_id
,
end_date
=
str
(
"2020-12-31"
),
index_id
=
"IN0000007M"
):
self
.
user_id
=
user_id
self
.
customer_id
=
customer_id
self
.
compare_index_id
=
index_id
p_end_date
=
pd
.
to_datetime
(
end_date
)
.
date
()
p_end_date
=
datetime
.
date
(
year
=
p_end_date
.
year
,
month
=
p_end_date
.
month
,
day
=
1
)
-
datetime
.
timedelta
(
days
=
1
)
self
.
end_date
=
pd
.
to_datetime
(
str
(
p_end_date
))
self
.
end_date
=
pd
.
to_datetime
(
"2020-12-18
"
)
# self.end_date = pd.to_datetime("2020-12-25
")
p_start_date
=
datetime
.
date
(
year
=
p_end_date
.
year
,
month
=
p_end_date
.
month
,
day
=
1
)
self
.
month_start_date
=
p_start_date
self
.
month_start_date
=
pd
.
to_datetime
(
"2020-12-01"
)
#
self.month_start_date = pd.to_datetime("2020-12-01")
self
.
user_customer_order_df
=
self
.
get_user_customer_order_data
()
self
.
fund_nav_total
,
self
.
fund_cnav_total
=
self
.
get_customer_fund_nav_data
()
self
.
index_df
=
self
.
get_customer_index_nav_data
()
...
...
@@ -256,8 +256,8 @@ class UserCustomerDataAdaptor:
# 根据确认净值日查看是否含有累积净值的数据,如果没有按照前后差值推算当天累积净值
if
pd
.
isnull
(
p_nav_df
.
loc
[
confirm_share_date
,
cur_fund_id
]):
last_nav_data
=
p_nav_df
[
p_nav_df
.
index
<
confirm_share_date
][
cur_fund_id
]
.
dropna
()
.
tail
(
1
)
last_cnav_data
=
p_cnav_df
[
p_cnav_df
.
index
<
confirm_share_date
][
cur_fund_id
]
.
dropna
()
.
tail
(
1
)
last_nav_data
=
p_nav_df
[
p_nav_df
.
index
>
confirm_share_date
][
cur_fund_id
]
.
dropna
()
.
head
(
1
)
last_cnav_data
=
p_cnav_df
[
p_cnav_df
.
index
>
confirm_share_date
][
cur_fund_id
]
.
dropna
()
.
head
(
1
)
# 判断上个净值日和当前确认日之中是否存在分红日
"""need add judge"""
...
...
@@ -351,8 +351,8 @@ class UserCustomerDataAdaptor:
# 根据确认净值日查看是否含有累积净值的数据,如果没有按照前后差值推算当天累积净值
if
pd
.
isnull
(
p_nav_df
.
loc
[
confirm_share_date
,
cur_fund_id
]):
last_nav_data
=
p_nav_df
[
p_nav_df
.
index
<
confirm_share_date
][
cur_fund_id
]
.
dropna
()
.
tail
(
1
)
last_cnav_data
=
p_cnav_df
[
p_cnav_df
.
index
<
confirm_share_date
][
cur_fund_id
]
.
dropna
()
.
tail
(
1
)
last_nav_data
=
p_nav_df
[
p_nav_df
.
index
>
confirm_share_date
][
cur_fund_id
]
.
dropna
()
.
head
(
1
)
last_cnav_data
=
p_cnav_df
[
p_cnav_df
.
index
>
confirm_share_date
][
cur_fund_id
]
.
dropna
()
.
head
(
1
)
# 判断上个净值日和当前确认日之中是否存在分红日
"""need add judge"""
...
...
app/service/portfolio_diagnose.py
View file @
83512303
...
...
@@ -873,12 +873,12 @@ class PortfolioDiagnose(object):
index_return
[
"new_index_return"
]
=
(
index_return
[
"index"
]
-
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_return
[
"new_index_return"
],
250
)
index_volatility
=
volatility
(
index_return
[
"new_index_return"
]
+
1
,
250
)
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
)
index_exc
=
excess_return
(
index_sim
,
BANK_RATE
,
250
)
index_sharpe
=
sharpe_ratio
(
index_exc
,
index_sim
,
250
)
# 收益对比数据
return_compare_df
=
pd
.
merge
(
index_return
[[
"new_index_return"
]],
old_return_df
[[
"cum_return_ratio"
]],
...
...
app/service/result_service_v2.py
View file @
83512303
...
...
@@ -178,7 +178,7 @@ class UserCustomerResultAdaptor(UserCustomerDataAdaptor):
"return_ratio_year"
:
"
%.2
f"
%
round
(
return_ratio_year
*
100
,
2
)}
# 对应指数数据
index_df
=
self
.
get_customer_index_nav_data
()
index_df
=
self
.
get_customer_index_nav_data
()
.
dropna
()
index_result
=
self
.
signal_fund_profit_result
(
index_df
[
index_df
.
index
>=
pd
.
to_datetime
(
first_trade_date
)],
"index"
)
folio_report_data
[
"index_result"
]
=
index_result
...
...
@@ -317,7 +317,7 @@ class UserCustomerResultAdaptor(UserCustomerDataAdaptor):
# 月度回报表格数据
start_year
=
self
.
start_date
.
year
now_year
=
datetime
.
datetime
.
now
()
.
year
now_year
=
self
.
end_date
.
year
month_return_data_dict
=
{}
for
i
in
range
(
now_year
-
start_year
+
1
):
month_return_data_dict
[
start_year
+
i
]
=
{
j
+
1
:
{
"profit"
:
"-"
,
"net_amount"
:
"-"
}
for
j
in
range
(
12
)}
...
...
@@ -340,7 +340,7 @@ class UserCustomerResultAdaptor(UserCustomerDataAdaptor):
report_data
[
"cumulative_return"
]
=
float
(
cumulative_return
)
# 对应指数数据
index_df
=
self
.
get_customer_index_nav_data
()
index_df
=
self
.
get_customer_index_nav_data
()
.
dropna
()
index_result
=
self
.
signal_fund_profit_result
(
index_df
[
index_df
.
index
>=
pd
.
to_datetime
(
first_trade_date
)],
"index"
)
report_data
[
"index_result"
]
=
index_result
...
...
@@ -415,7 +415,10 @@ class UserCustomerResultAdaptor(UserCustomerDataAdaptor):
# 基金持仓数据
total_market_values
=
p_sum_profit
+
p_total_amount
# 月末总市值
fund_hoding_info
=
{
"fund_strategy_name"
:
dict_substrategy
[
int
(
row
[
"substrategy"
])],
"fund_name"
:
row
[
"fund_name"
]}
fund_strategy_name
=
dict_substrategy
[
int
(
row
[
"substrategy"
])]
if
"长富"
in
row
[
"fund_name"
]
or
"盈沛"
in
row
[
"fund_name"
]
:
fund_strategy_name
=
"FOF"
fund_hoding_info
=
{
"fund_strategy_name"
:
fund_strategy_name
,
"fund_name"
:
row
[
"fund_name"
]}
fund_hoding_info
[
"confirm_date"
]
=
row
[
"confirm_share_date"
]
.
strftime
(
"
%
Y-
%
m-
%
d"
)
fund_hoding_info
[
"hold_year"
]
=
"
%.2
f"
%
round
((
self
.
end_date
-
pd
.
to_datetime
(
row
[
"confirm_share_date"
]))
.
days
/
365.0
,
2
)
# 存续年数
fund_hoding_info
[
"market_values"
]
=
round
((
float
(
row
[
"confirm_share"
])
*
(
fund_basic_info
[
"cur_cnav"
]
-
confirm_cnav
)
+
float
(
row
[
"confirm_amount"
]))
/
10000
,
2
)
...
...
app/templates/v2/monthReportV2.1.html
View file @
83512303
...
...
@@ -466,7 +466,7 @@
}
.par
.par_item
.par_content.relative_chart
table
td
{
padding
:
14px
0
14
px
0
;
padding
:
7px
0
7
px
0
;
text-align
:
center
;
}
...
...
app/utils/jinjia2html_v2.py
View file @
83512303
...
...
@@ -318,9 +318,9 @@ class DataIntegrate:
template
=
env
.
get_template
(
'/v2/monthReportV2.1.html'
)
# 获取一个模板文件
monthReport_html
=
template
.
render
(
data
)
# 渲染
# 保存 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/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:
...
...
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