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
65c347f3
Commit
65c347f3
authored
May 22, 2018
by
Dr.李
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added one more test
parent
47fe2c2f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
0 deletions
+30
-0
test_sql_engine.py
alphamind/tests/data/engines/test_sql_engine.py
+30
-0
No files found.
alphamind/tests/data/engines/test_sql_engine.py
View file @
65c347f3
...
@@ -171,6 +171,36 @@ class TestSqlEngine(unittest.TestCase):
...
@@ -171,6 +171,36 @@ class TestSqlEngine(unittest.TestCase):
calculated_return
=
dx_return
[
dx_return
.
trade_date
==
ref_date
]
calculated_return
=
dx_return
[
dx_return
.
trade_date
==
ref_date
]
np
.
testing
.
assert_array_almost_equal
(
calculated_return
.
dx
.
values
,
res
.
chgPct
.
values
)
np
.
testing
.
assert_array_almost_equal
(
calculated_return
.
dx
.
values
,
res
.
chgPct
.
values
)
def
test_sql_engine_fetch_dx_return_with_universe_adjustment
(
self
):
ref_dates
=
makeSchedule
(
advanceDateByCalendar
(
'china.sse'
,
'2017-01-26'
,
'-6m'
),
'2017-01-26'
,
'60b'
,
'china.sse'
)
universe
=
Universe
(
'zz500'
)
dx_return
=
self
.
engine
.
fetch_dx_return_range
(
universe
,
dates
=
ref_dates
,
horizon
=
4
,
offset
=
1
)
codes
=
self
.
engine
.
fetch_codes_range
(
universe
,
dates
=
ref_dates
)
groups
=
codes
.
groupby
(
'trade_date'
)
for
ref_date
,
g
in
groups
:
start_date
=
advanceDateByCalendar
(
'china.sse'
,
ref_date
,
'2b'
)
end_date
=
advanceDateByCalendar
(
'china.sse'
,
ref_date
,
'6b'
)
query
=
select
([
Market
.
code
,
Market
.
chgPct
])
.
where
(
and_
(
Market
.
trade_date
.
between
(
start_date
,
end_date
),
Market
.
code
.
in_
(
g
.
code
.
unique
()
.
tolist
())
)
)
df
=
pd
.
read_sql
(
query
,
con
=
self
.
engine
.
engine
)
res
=
df
.
groupby
(
'code'
)
.
apply
(
lambda
x
:
np
.
log
(
1.
+
x
)
.
sum
())
calculated_return
=
dx_return
[
dx_return
.
trade_date
==
ref_date
]
np
.
testing
.
assert_array_almost_equal
(
calculated_return
.
dx
.
values
,
res
.
chgPct
.
values
)
def
test_sql_engine_fetch_dx_return_index
(
self
):
def
test_sql_engine_fetch_dx_return_index
(
self
):
horizon
=
4
horizon
=
4
offset
=
1
offset
=
1
...
...
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