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
56a7e393
Commit
56a7e393
authored
Feb 14, 2018
by
Dr.李
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor return get
parent
6b86de35
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
16 deletions
+11
-16
sqlengine.py
alphamind/data/engines/sqlengine.py
+11
-16
No files found.
alphamind/data/engines/sqlengine.py
View file @
56a7e393
...
...
@@ -155,6 +155,13 @@ class SqlEngine(object):
dates
:
Iterable
[
str
]
=
None
)
->
pd
.
DataFrame
:
return
universe
.
query
(
self
,
start_date
,
end_date
,
dates
)
def
_create_stats
(
self
,
table
,
horizon
,
offset
):
stats
=
func
.
sum
(
self
.
ln_func
(
1.
+
table
.
chgPct
))
.
over
(
partition_by
=
table
.
code
,
order_by
=
table
.
trade_date
,
rows
=
(
1
+
DAILY_RETURN_OFFSET
+
offset
,
1
+
horizon
+
DAILY_RETURN_OFFSET
+
offset
))
.
label
(
'dx'
)
return
stats
def
fetch_dx_return
(
self
,
ref_date
:
str
,
codes
:
Iterable
[
int
],
...
...
@@ -169,10 +176,7 @@ class SqlEngine(object):
else
:
end_date
=
expiry_date
stats
=
func
.
sum
(
self
.
ln_func
(
1.
+
Market
.
chgPct
))
.
over
(
partition_by
=
Market
.
code
,
order_by
=
Market
.
trade_date
,
rows
=
(
1
+
DAILY_RETURN_OFFSET
+
offset
,
1
+
horizon
+
DAILY_RETURN_OFFSET
+
offset
))
.
label
(
'dx'
)
stats
=
self
.
_create_stats
(
Market
,
horizon
,
offset
)
query
=
select
([
Market
.
trade_date
,
Market
.
code
,
stats
])
.
where
(
and_
(
...
...
@@ -200,10 +204,7 @@ class SqlEngine(object):
end_date
=
advanceDateByCalendar
(
'china.sse'
,
end_date
,
str
(
1
+
horizon
+
offset
+
DAILY_RETURN_OFFSET
)
+
'b'
)
.
strftime
(
'
%
Y-
%
m-
%
d'
)
stats
=
func
.
sum
(
self
.
ln_func
(
1.
+
Market
.
chgPct
))
.
over
(
partition_by
=
Market
.
code
,
order_by
=
Market
.
trade_date
,
rows
=
(
1
+
offset
+
DAILY_RETURN_OFFSET
,
1
+
horizon
+
offset
+
DAILY_RETURN_OFFSET
))
.
label
(
'dx'
)
stats
=
self
.
_create_stats
(
Market
,
horizon
,
offset
)
cond
=
universe
.
_query_statements
(
start_date
,
end_date
,
None
)
...
...
@@ -243,10 +244,7 @@ class SqlEngine(object):
else
:
end_date
=
expiry_date
stats
=
func
.
sum
(
self
.
ln_func
(
1.
+
IndexMarket
.
chgPct
))
.
over
(
partition_by
=
IndexMarket
.
indexCode
,
order_by
=
IndexMarket
.
trade_date
,
rows
=
(
1
+
DAILY_RETURN_OFFSET
+
offset
,
1
+
horizon
+
DAILY_RETURN_OFFSET
+
offset
))
.
label
(
'dx'
)
stats
=
self
.
_create_stats
(
IndexMarket
,
horizon
,
offset
)
query
=
select
([
IndexMarket
.
trade_date
,
IndexMarket
.
indexCode
.
label
(
'code'
),
stats
])
.
where
(
and_
(
...
...
@@ -274,10 +272,7 @@ class SqlEngine(object):
end_date
=
advanceDateByCalendar
(
'china.sse'
,
end_date
,
str
(
1
+
horizon
+
offset
+
DAILY_RETURN_OFFSET
)
+
'b'
)
.
strftime
(
'
%
Y-
%
m-
%
d'
)
stats
=
func
.
sum
(
self
.
ln_func
(
1.
+
IndexMarket
.
chgPct
))
.
over
(
partition_by
=
IndexMarket
.
indexCode
,
order_by
=
IndexMarket
.
trade_date
,
rows
=
(
1
+
offset
+
DAILY_RETURN_OFFSET
,
1
+
horizon
+
offset
+
DAILY_RETURN_OFFSET
))
.
label
(
'dx'
)
stats
=
self
.
_create_stats
(
IndexMarket
,
horizon
,
offset
)
query
=
select
([
IndexMarket
.
trade_date
,
IndexMarket
.
indexCode
.
label
(
'code'
),
stats
])
\
.
where
(
...
...
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