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
4770717b
Commit
4770717b
authored
Nov 23, 2020
by
赵杰
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加结果数据类
parent
4f2e99b9
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
63 additions
and
5 deletions
+63
-5
data_service.py
app/service/data_service.py
+37
-5
result_service.py
app/service/result_service.py
+26
-0
No files found.
app/service/data_service.py
View file @
4770717b
...
...
@@ -12,19 +12,23 @@ from sqlalchemy import and_
import
tushare
as
ts
import
datetime
from
app.api.engine
import
tamp_user_session
,
tamp_product_session
from
app.model.tamp_user_models
import
t_customer_order
,
t_customer_info
from
app.model.tamp_product_models
import
t_fund_info
#
from app.model.tamp_user_models import t_customer_order, t_customer_info
#
from app.model.tamp_product_models import t_fund_info
class
UserCustomerDataAdaptor
:
user_id
=
""
customer_id
=
""
start_date
=
""
end_date
=
""
group_data
=
{}
def
__init__
(
self
,
user_id
,
customer_id
):
def
__init__
(
self
,
user_id
,
customer_id
,
end_date
=
str
(
datetime
.
date
.
today
())
):
self
.
user_id
=
user_id
self
.
customer_id
=
customer_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
.
user_customer_order_df
=
self
.
get_user_customer_order_data
()
self
.
fund_nav_total
=
self
.
get_customer_fund_nav_data
()
self
.
get_customer_index_nav_data
()
...
...
@@ -69,7 +73,6 @@ 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(str(self.start_date).replace("-", ""), now_date)
trade_date_df
=
self
.
get_trade_cal
(
"20000101"
,
now_date
)
all_fund_nav
=
pd
.
DataFrame
(
index
=
trade_date_df
[
"datetime"
])
...
...
@@ -88,9 +91,10 @@ class UserCustomerDataAdaptor:
# cur_fund_distribution_df = pd.DataFrame(list(data), columns=['price_date', 'distribution'])
cur_fund_nav_df
[
"price_date"
]
=
pd
.
to_datetime
(
cur_fund_nav_df
[
"price_date"
])
cur_fund_nav_df
.
set_index
(
"price_date"
,
inplace
=
True
)
all_fund_nav
[
cur_fund_id
]
=
cur_fund_nav_df
[
"cnav"
]
all_fund_nav
=
all_fund_nav
[
all_fund_nav
.
index
<=
self
.
end_date
]
return
all_fund_nav
# 获取客户对比指数净值数据
...
...
@@ -114,6 +118,34 @@ class UserCustomerDataAdaptor:
fund_id_list
=
list
(
self
.
user_customer_order_df
[
"fund_id"
]
.
unique
())
fund_id_list
.
append
(
"index"
)
cur_folio_nav_df
=
self
.
fund_nav_total
[
fund_id_list
]
self
.
signal_folio_operate
(
folio
,
cur_folio_order_df
,
cur_folio_nav_df
)
continue
# 单个组合数据操作
def
signal_folio_operate
(
self
,
p_folio
,
p_order_df
,
p_nav_df
):
start_date
=
pd
.
to_datetime
(
p_order_df
[
"confirm_share_date"
]
.
min
())
nav_df
=
p_nav_df
[
p_nav_df
.
index
>=
start_date
]
.
copy
()
for
index
,
row
in
p_order_df
.
iterrows
():
cur_fund_id
=
str
(
row
[
"fund_id"
])
confirm_share_date
=
pd
.
to_datetime
(
row
[
"confirm_share_date"
])
if
cur_fund_id
+
"_amount"
not
in
nav_df
:
nav_df
[
cur_fund_id
+
"_profit"
]
=
(
nav_df
[
cur_fund_id
]
.
dropna
()
-
nav_df
[
cur_fund_id
]
.
dropna
()
.
shift
(
1
))
nav_df
[
cur_fund_id
+
"_amount"
]
=
0
nav_df
[
cur_fund_id
+
"_earn"
]
=
0
nav_df
[
cur_fund_id
+
"_share"
]
=
0
# buy
if
row
[
'order_type'
]
==
1
:
nav_df
.
loc
[
confirm_share_date
:,
cur_fund_id
+
"_amount"
]
+=
row
[
"confirm_amount"
]
nav_df
.
loc
[
confirm_share_date
:,
cur_fund_id
+
"_share"
]
+=
row
[
"confirm_share"
]
# sell
elif
row
[
'order_type'
]
==
2
:
nav_df
.
loc
[
confirm_share_date
:,
cur_fund_id
+
"_amount"
]
-=
row
[
"confirm_amount"
]
nav_df
.
loc
[
confirm_share_date
:,
cur_fund_id
+
"_share"
]
-=
row
[
"confirm_share"
]
nav_df
[
cur_fund_id
+
"_earn"
]
=
nav_df
[
cur_fund_id
+
"_profit"
]
*
nav_df
[
cur_fund_id
+
"_share"
]
self
.
group_data
[
p_folio
]
=
{
"basic_data"
:
nav_df
}
return
nav_df
app/service/result_service.py
0 → 100644
View file @
4770717b
#!/usr/bin/python3.6
# -*- coding: utf-8 -*-
# @Time : 2020/11/23 15:29
# @Author : Jie. Z
# @Email : zhaojiestudy@163.com
# @File : result_service.py
# @Software: PyCharm
import
pandas
as
pd
import
numpy
as
np
import
datetime
from
app.service.data_service
import
UserCustomerDataAdaptor
class
UserCustomerResultAdaptor
(
UserCustomerDataAdaptor
):
def
__init__
(
self
,
user_id
,
customer_id
,
end_date
=
str
(
datetime
.
date
.
today
())):
UserCustomerDataAdaptor
.
__init__
(
user_id
,
customer_id
,
end_date
)
# 综述数据
def
get_total_data
(
self
):
pass
# 组合数据
def
get_group_data
(
self
):
pass
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