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
e3b8c8f7
Commit
e3b8c8f7
authored
Jul 24, 2017
by
Dr.李
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update universe
parent
b16b4131
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
17 deletions
+29
-17
sqlengine.py
alphamind/data/engines/sqlengine.py
+1
-1
universe.py
alphamind/data/engines/universe.py
+28
-16
No files found.
alphamind/data/engines/sqlengine.py
View file @
e3b8c8f7
...
@@ -208,7 +208,7 @@ if __name__ == '__main__':
...
@@ -208,7 +208,7 @@ if __name__ == '__main__':
import
datetime
as
dt
import
datetime
as
dt
universe
=
Universe
(
'zz500'
,
[
'
zz500'
],
filter_cond
=
(
Uqer
.
BLEV
>=
0.1
)
&
(
Uqer
.
BLEV
<=
0.1
)
)
universe
=
Universe
(
'zz500'
,
[
'
ashare'
],
filter_cond
=
(
Uqer
.
BLEV
>=
0.
)
&
(
Uqer
.
BLEV
<=
0.1
),
include_universe
=
[
'hs300'
]
)
engine
=
SqlEngine
(
db_url
)
engine
=
SqlEngine
(
db_url
)
ref_date
=
'2017-07-04'
ref_date
=
'2017-07-04'
...
...
alphamind/data/engines/universe.py
View file @
e3b8c8f7
...
@@ -7,6 +7,7 @@ Created on 2017-7-7
...
@@ -7,6 +7,7 @@ Created on 2017-7-7
from
typing
import
Iterable
from
typing
import
Iterable
from
sqlalchemy
import
and_
from
sqlalchemy
import
and_
from
sqlalchemy
import
or_
from
sqlalchemy
import
select
from
sqlalchemy
import
select
from
alphamind.data.dbmodel.models
import
Uqer
from
alphamind.data.dbmodel.models
import
Uqer
from
alphamind.data.dbmodel.models
import
Universe
as
UniverseTable
from
alphamind.data.dbmodel.models
import
Universe
as
UniverseTable
...
@@ -16,13 +17,15 @@ class Universe(object):
...
@@ -16,13 +17,15 @@ class Universe(object):
def
__init__
(
self
,
def
__init__
(
self
,
name
,
name
,
base_universe
:
Iterable
[
str
]
=
None
,
filter_cond
=
None
,
include_universe
:
Iterable
[
str
]
=
None
,
include_universe
:
Iterable
[
str
]
=
None
,
exclude_universe
:
Iterable
[
str
]
=
None
,
exclude_universe
:
Iterable
[
str
]
=
None
,
include_codes
:
Iterable
[
str
]
=
None
,
include_codes
:
Iterable
[
str
]
=
None
,
exclude_codes
:
Iterable
[
str
]
=
None
,
exclude_codes
:
Iterable
[
str
]
=
None
):
filter_cond
=
None
):
self
.
name
=
name
self
.
name
=
name
self
.
base_universe
=
base_universe
self
.
include_universe
=
include_universe
self
.
include_universe
=
include_universe
self
.
exclude_universe
=
exclude_universe
self
.
exclude_universe
=
exclude_universe
self
.
include_codes
=
include_codes
self
.
include_codes
=
include_codes
...
@@ -32,31 +35,40 @@ class Universe(object):
...
@@ -32,31 +35,40 @@ class Universe(object):
def
query
(
self
,
ref_date
):
def
query
(
self
,
ref_date
):
query
=
select
([
UniverseTable
.
Code
])
.
distinct
()
query
=
select
([
UniverseTable
.
Code
])
.
distinct
()
all_
conditions
=
[
UniverseTable
.
Date
==
ref_date
]
all_
and_conditions
=
[
]
if
self
.
include_universe
:
univ_in
=
UniverseTable
.
universe
.
in_
(
self
.
includ
e_universe
)
univ_in
=
UniverseTable
.
universe
.
in_
(
self
.
bas
e_universe
)
all
_conditions
.
append
(
univ_in
)
all_and
_conditions
.
append
(
univ_in
)
if
self
.
exclude_universe
:
if
self
.
exclude_universe
:
univ_out
=
UniverseTable
.
universe
.
notin_
(
self
.
exclude_universe
)
univ_out
=
UniverseTable
.
universe
.
notin_
(
self
.
exclude_universe
)
all_conditions
.
append
(
univ_out
)
all_and_conditions
.
append
(
univ_out
)
if
self
.
include_codes
:
codes_in
=
UniverseTable
.
Code
.
in_
(
self
.
include_codes
)
all_conditions
.
append
(
codes_in
)
if
self
.
exclude_codes
:
if
self
.
exclude_codes
:
codes_out
=
UniverseTable
.
Code
.
notin_
(
self
.
exclude_codes
)
codes_out
=
UniverseTable
.
Code
.
notin_
(
self
.
exclude_codes
)
all_conditions
.
append
(
codes_out
)
all_and_conditions
.
append
(
codes_out
)
all_or_conditions
=
[]
if
self
.
include_universe
:
univ_in
=
UniverseTable
.
universe
.
in_
(
self
.
include_universe
)
all_or_conditions
.
append
(
univ_in
)
if
self
.
include_codes
:
codes_in
=
UniverseTable
.
Code
.
in_
(
self
.
include_codes
)
all_or_conditions
.
append
(
codes_in
)
if
self
.
filter_cond
is
not
None
:
if
self
.
filter_cond
is
not
None
:
all_conditions
.
extend
([
self
.
filter_cond
,
all_and_conditions
.
extend
([
self
.
filter_cond
])
UniverseTable
.
Code
==
Uqer
.
Code
,
UniverseTable
.
Date
==
Uqer
.
Date
])
query
=
query
.
where
(
query
=
query
.
where
(
and_
(
and_
(
*
all_conditions
UniverseTable
.
Date
==
ref_date
,
UniverseTable
.
Code
==
Uqer
.
Code
,
UniverseTable
.
Date
==
Uqer
.
Date
,
or_
(
and_
(
*
all_and_conditions
),
*
all_or_conditions
)
)
)
)
)
...
...
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