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
a7967f6b
Commit
a7967f6b
authored
Nov 27, 2020
by
赵杰
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
综述数据接口返回
parent
66be88e5
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
39 additions
and
35 deletions
+39
-35
engine.py
app/api/engine.py
+4
-5
data_service.py
app/service/data_service.py
+2
-2
result_service.py
app/service/result_service.py
+33
-28
No files found.
app/api/engine.py
View file @
a7967f6b
...
...
@@ -14,8 +14,7 @@ import os
import
sys
import
yaml
from
sqlalchemy
import
create_engine
from
sqlalchemy.orm
import
sessionmaker
from
sqlalchemy.orm
import
sessionmaker
,
scoped_session
env
=
sys
.
argv
[
-
1
]
work_dir
=
os
.
getcwd
()
...
...
@@ -56,9 +55,9 @@ tamp_user_engine = create_engine(
),
echo
=
True
)
tamp_product_session
=
s
essionmaker
(
bind
=
tamp_product_engine
,
autocommit
=
True
)()
tamp_order_session
=
s
essionmaker
(
bind
=
tamp_order_engine
,
autocommit
=
True
)()
tamp_user_session
=
s
essionmaker
(
bind
=
tamp_user_engine
,
autocommit
=
True
)()
tamp_product_session
=
s
coped_session
(
sessionmaker
(
bind
=
tamp_product_engine
)
)()
tamp_order_session
=
s
coped_session
(
sessionmaker
(
bind
=
tamp_order_engine
)
)()
tamp_user_session
=
s
coped_session
(
sessionmaker
(
bind
=
tamp_user_engine
)
)()
# redis = redis.StrictRedis(
# host=config[env]['redis']['host'],
...
...
app/service/data_service.py
View file @
a7967f6b
...
...
@@ -22,7 +22,7 @@ class UserCustomerDataAdaptor:
month_date
=
""
end_date
=
""
group_data
=
{}
trade_cal
=
None
trade_cal
_date
=
None
all_fund_distribution
=
{}
all_fund_performance
=
{}
...
...
@@ -83,7 +83,7 @@ class UserCustomerDataAdaptor:
def
get_customer_fund_nav_data
(
self
):
now_date
=
datetime
.
datetime
.
now
()
.
strftime
(
"
%
Y
%
m
%
d"
)
trade_date_df
=
self
.
get_trade_cal
(
"20000101"
,
now_date
)
self
.
trade_cal
=
trade_date_df
self
.
trade_cal
_date
=
trade_date_df
all_fund_nav
=
pd
.
DataFrame
(
index
=
trade_date_df
[
"datetime"
])
all_fund_cnav
=
pd
.
DataFrame
(
index
=
trade_date_df
[
"datetime"
])
...
...
app/service/result_service.py
View file @
a7967f6b
...
...
@@ -67,7 +67,7 @@ class UserCustomerResultAdaptor(UserCustomerDataAdaptor):
super
()
.
__init__
(
user_id
,
customer_id
,
end_date
)
# 组合结果数据
def
get
_group_result_data
(
self
):
def
calculate
_group_result_data
(
self
):
for
folio
in
self
.
group_data
.
keys
():
folio_report_data
=
{}
...
...
@@ -83,7 +83,7 @@ class UserCustomerResultAdaptor(UserCustomerDataAdaptor):
# 组合收益率数组
return_ratio_df
=
self
.
combination_yield
(
cur_folio_result_cnav_data
,
fund_id_list
)
resample_df
=
resample
(
return_ratio_df
,
self
.
trade_cal
,
freq_max
)
resample_df
=
resample
(
return_ratio_df
,
self
.
trade_cal
_date
,
freq_max
)
# 总成本
total_cost
=
float
(
cur_folio_order_data
[
cur_folio_order_data
[
"order_type"
]
==
1
][
"confirm_amount"
]
.
sum
()
-
\
...
...
@@ -94,7 +94,7 @@ class UserCustomerResultAdaptor(UserCustomerDataAdaptor):
cumulative_profit
=
profit_df
.
sum
()
.
sum
()
folio_report_data
[
"cumulative_profit"
]
=
float
(
cumulative_profit
)
# 区间年化收益
# 区间年化收益
率
n_freq
=
freq_days
(
int
(
freq_max
))
return_ratio_year
=
annual_return
((
resample_df
[
"cum_return_ratio"
]
.
values
[
-
1
]
-
1
),
resample_df
,
n_freq
)
folio_report_data
[
"return_ratio_year"
]
=
float
(
return_ratio_year
)
...
...
@@ -146,28 +146,12 @@ class UserCustomerResultAdaptor(UserCustomerDataAdaptor):
cur_year_profit_ratio
=
(
cur_profit_ratio
[
-
1
]
-
last_profit_ratio
[
-
1
])
/
last_profit_ratio
[
-
1
]
folio_report_data
[
"cur_year_profit_ratio"
]
=
float
(
cur_year_profit_ratio
)
# # 月度回报
# def year_month(x):
# a = x.year
# b = x.month
# return str(a) + "/" + str(b)
# profit_df_cp = profit_df.copy()
# profit_df_cp["date"] = profit_df_cp.index
# grouped = profit_df_cp.groupby(profit_df_cp["date"].apply(year_month))
# sum_group = grouped.agg(np.sum)
# month_sum = sum_group.sum(axis=1)
# folio_report_data["month_return"] = month_sum
#
# # 贡献分解
# month_earn = sum_group.div(month_sum, axis='rows')
# folio_report_data["contribution_decomposition"] = month_earn
#
# # 累积收益率
# cumulative_return= return_ratio_df["cum_return_ratio"].values[-1]
# folio_report_data["contribution_decomposition"] = float(cumulative_return)
# 累积收益率
cumulative_return
=
return_ratio_df
[
"cum_return_ratio"
]
.
values
[
-
1
]
folio_report_data
[
"contribution_decomposition"
]
=
float
(
cumulative_return
)
# 组合内单个基金净值数据 组合内基金持仓数据
result_fund_nav_info
,
result_fund_hoding_info
=
self
.
group_fund_basic_info_data
(
fund_id_list
,
cur_folio_order_data
,
cur_folio_result_cnav_data
,
cumulative_profit
,
total_cost
)
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
)
# 拼接组合以及综合结果数据
folio_report_data
[
"group_nav_info"
]
=
result_fund_nav_info
...
...
@@ -178,7 +162,7 @@ class UserCustomerResultAdaptor(UserCustomerDataAdaptor):
return
self
.
group_result_data
# 综述数据
def
get
_total_data
(
self
):
def
calculate
_total_data
(
self
):
report_data
=
{}
cur_folio_result_cnav_data
=
self
.
total_customer_order_cnav_df
...
...
@@ -191,12 +175,12 @@ class UserCustomerResultAdaptor(UserCustomerDataAdaptor):
# 持仓周期
first_trade_date
=
cur_folio_order_data
[
"confirm_share_date"
]
.
min
()
hold_days
=
self
.
end_date
-
pd
.
to_datetime
(
first_trade_date
)
.
days
hold_days
=
(
self
.
end_date
-
pd
.
to_datetime
(
first_trade_date
)
)
.
days
report_data
[
"hold_days"
]
=
hold_days
# 组合收益率数组
return_ratio_df
=
self
.
combination_yield
(
cur_folio_result_cnav_data
,
fund_id_list
)
resample_df
=
resample
(
return_ratio_df
,
self
.
trade_cal
,
freq_max
)
resample_df
=
resample
(
return_ratio_df
,
self
.
trade_cal
_date
,
freq_max
)
# 总成本
total_cost
=
float
(
cur_folio_order_data
[
cur_folio_order_data
[
"order_type"
]
==
1
][
"confirm_amount"
]
.
sum
()
-
\
...
...
@@ -271,7 +255,15 @@ class UserCustomerResultAdaptor(UserCustomerDataAdaptor):
grouped
=
profit_df_cp
.
groupby
(
profit_df_cp
[
"date"
]
.
apply
(
year_month
))
sum_group
=
grouped
.
agg
(
np
.
sum
)
month_sum
=
sum_group
.
sum
(
axis
=
1
)
report_data
[
"month_return"
]
=
month_sum
return_ratio_df
[
"date"
]
=
return_ratio_df
.
index
return_group
=
return_ratio_df
.
groupby
(
return_ratio_df
[
"date"
]
.
apply
(
year_month
))
month_last_return_ratio
=
return_group
.
last
()[
"cum_return_ratio"
]
month_result
=
pd
.
DataFrame
({
"date"
:
month_sum
.
index
,
"profit"
:
month_sum
.
values
,
"ratio"
:
month_last_return_ratio
.
values
})
month_result
[
"datetime"
]
=
pd
.
to_datetime
(
month_result
[
"date"
])
month_result
.
sort_values
(
by
=
"datetime"
,
inplace
=
True
)
report_data
[
"month_return"
]
=
month_result
# # 贡献分解
# month_earn = sum_group.div(month_sum, axis='rows')
...
...
@@ -284,7 +276,7 @@ class UserCustomerResultAdaptor(UserCustomerDataAdaptor):
self
.
total_result_data
=
report_data
return
report_data
#
组合基金净值
数据
#
基金净值数据,持仓
数据
def
group_fund_basic_info_data
(
self
,
p_order_df
,
p_result_cnav_data
,
p_sum_profit
,
p_total_amount
):
group_fund_basic_info
=
[]
group_fund_hoding_info
=
[]
...
...
@@ -373,3 +365,16 @@ class UserCustomerResultAdaptor(UserCustomerDataAdaptor):
def
signal_fund_profit_result
():
pass
def
get_month_return_chart
(
self
):
res
=
self
.
total_result_data
[
"month_return"
]
xlabels
=
res
[
"date"
]
.
values
res
[
"profit"
]
=
res
[
"profit"
]
.
apply
(
lambda
x
:
round
(
x
/
100.0
,
2
))
res
[
"ratio"
]
=
res
[
"ratio"
]
.
apply
(
lambda
x
:
round
((
x
-
1
)
*
100
,
2
))
product_list
=
{
'name'
:
'月度回报'
,
'data'
:
res
[
"profit"
]
.
values
}
cumulative
=
{
'name'
:
'累积收益'
,
'data'
:
res
[
"ratio"
]
.
values
}
return
xlabels
,
[
product_list
],
cumulative
def
get_total_basic_data
(
self
):
return
self
.
total_result_data
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