Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
A
alpha-mind
Project
Project
Details
Activity
Releases
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
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Dr.李
alpha-mind
Commits
bfc257f9
Commit
bfc257f9
authored
Jan 12, 2018
by
Yucheng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update fetch_outright_status function, and fix bug
parent
9203f363
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
7 deletions
+20
-7
sqlengine.py
alphamind/data/engines/sqlengine.py
+20
-7
No files found.
alphamind/data/engines/sqlengine.py
View file @
bfc257f9
...
...
@@ -793,15 +793,25 @@ class SqlEngine(object):
index
=
False
,
dtype
=
{
'weight'
:
sa
.
types
.
JSON
})
def
fetch_outright_status
(
self
,
ref_date
:
str
):
def
fetch_outright_status
(
self
,
ref_date
:
str
,
is_open
=
True
):
table
=
OutrightTmp
if
is_open
:
id_filter
=
'notin_'
else
:
id_filter
=
'in_'
t
=
select
([
table
.
trade_id
])
.
\
where
(
and_
(
table
.
trade_date
<=
ref_date
,
table
.
operation
==
'withdraw'
))
.
alias
(
't'
)
query
=
select
([
table
])
.
\
where
(
and_
(
table
.
trade_id
.
notin_
(
t
),
table
.
trade_date
<=
ref_date
))
df
=
pd
.
read_sql
(
query
,
engine
.
engine
)
.
set_index
(
'trade_id'
)
where
(
and_
(
getattr
(
table
.
trade_id
,
id_filter
)(
t
),
table
.
trade_date
<=
ref_date
,
table
.
operation
==
'lend'
))
df
=
pd
.
read_sql
(
query
,
self
.
engine
)
.
set_index
(
'trade_id'
)
if
df
.
empty
:
return
# calc total volume
df
[
'total_volume'
]
=
df
.
groupby
(
'trade_id'
)[
'volume'
]
.
transform
(
sum
)
...
...
@@ -813,8 +823,11 @@ class SqlEngine(object):
if
rule
[
0
]
in
[
'closePrice'
,
'openPrice'
]:
query
=
select
([
getattr
(
Market
,
rule
[
0
])])
.
\
where
(
and_
(
Market
.
code
==
code
,
Market
.
trade_date
==
rule
[
1
]))
data
=
pd
.
read_sql
(
query
,
engine
.
engine
)
price
=
data
.
values
[
0
][
0
]
data
=
pd
.
read_sql
(
query
,
self
.
engine
)
if
not
data
.
empty
:
price
=
data
.
values
[
0
][
0
]
else
:
price
=
None
elif
rule
[
0
]
==
'fixedPrice'
:
price
=
float
(
rule
[
1
])
else
:
...
...
@@ -822,7 +835,7 @@ class SqlEngine(object):
return
price
df
[
'price'
]
=
df
.
apply
(
lambda
x
:
parse_price_rule
(
x
),
axis
=
1
)
df
.
drop
([
'remark'
,
'price_rule'
],
axis
=
1
,
inplace
=
True
)
df
.
drop
([
'remark'
,
'price_rule'
,
'operation'
],
axis
=
1
,
inplace
=
True
)
# pivot portfolio volume
total_cols
=
df
.
columns
pivot_cols
=
[
'portfolio_name'
,
'volume'
]
...
...
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