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
77b97192
Unverified
Commit
77b97192
authored
May 29, 2018
by
iLampard
Committed by
GitHub
May 29, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #16 from alpha-miner/master
merge update
parents
2112699d
bce4c53e
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
26 additions
and
7 deletions
+26
-7
sqlengine.py
alphamind/data/engines/sqlengine.py
+11
-6
test_sql_engine.py
alphamind/tests/data/engines/test_sql_engine.py
+0
-1
test_universe.py
alphamind/tests/data/engines/test_universe.py
+15
-0
No files found.
alphamind/data/engines/sqlengine.py
View file @
77b97192
...
...
@@ -615,7 +615,7 @@ class SqlEngine(object):
def
fetch_industry
(
self
,
ref_date
:
str
,
codes
:
Iterable
[
int
],
codes
:
Iterable
[
int
]
=
None
,
category
:
str
=
'sw'
,
level
:
int
=
1
):
...
...
@@ -623,21 +623,26 @@ class SqlEngine(object):
code_name
=
'industryID'
+
str
(
level
)
category_name
=
'industryName'
+
str
(
level
)
query
=
select
([
Industry
.
code
,
getattr
(
Industry
,
code_name
)
.
label
(
'industry_code'
),
getattr
(
Industry
,
category_name
)
.
label
(
'industry'
)])
.
where
(
and_
(
cond
=
and_
(
Industry
.
trade_date
==
ref_date
,
Industry
.
code
.
in_
(
codes
),
Industry
.
industry
==
industry_category_name
)
if
codes
else
and_
(
Industry
.
trade_date
==
ref_date
,
Industry
.
industry
==
industry_category_name
)
query
=
select
([
Industry
.
code
,
getattr
(
Industry
,
code_name
)
.
label
(
'industry_code'
),
getattr
(
Industry
,
category_name
)
.
label
(
'industry'
)])
.
where
(
cond
)
.
distinct
()
return
pd
.
read_sql
(
query
,
self
.
engine
)
.
dropna
()
.
drop_duplicates
([
'code'
])
def
fetch_industry_matrix
(
self
,
ref_date
:
str
,
codes
:
Iterable
[
int
],
codes
:
Iterable
[
int
]
=
None
,
category
:
str
=
'sw'
,
level
:
int
=
1
):
df
=
self
.
fetch_industry
(
ref_date
,
codes
,
category
,
level
)
...
...
alphamind/tests/data/engines/test_sql_engine.py
View file @
77b97192
...
...
@@ -424,7 +424,6 @@ class TestSqlEngine(unittest.TestCase):
df3
=
self
.
engine
.
fetch_factor
(
ref_date
,
raw_factor
,
codes
)
ind_matrix
=
self
.
engine
.
fetch_industry_matrix
(
ref_date
,
codes
,
'sw'
,
1
)
cols
=
sorted
(
ind_matrix
.
columns
[
2
:]
.
tolist
())
series
=
(
ind_matrix
[
cols
]
*
np
.
array
(
range
(
1
,
len
(
cols
)
+
1
)))
.
sum
(
axis
=
1
)
...
...
alphamind/tests/data/engines/test_universe.py
View file @
77b97192
...
...
@@ -25,5 +25,20 @@ class TestUniverse(unittest.TestCase):
universe
=
Universe
(
'zz500'
)
univ_desc
=
universe
.
save
()
loaded_universe
=
load_universe
(
univ_desc
)
self
.
assertEqual
(
universe
,
loaded_universe
)
def
test_universe_arithmic
(
self
):
universe
=
Universe
(
'zz500'
)
+
Universe
(
'hs300'
)
univ_desc
=
universe
.
save
()
loaded_universe
=
load_universe
(
univ_desc
)
self
.
assertEqual
(
universe
,
loaded_universe
)
universe
=
Universe
(
'zz500'
)
-
Universe
(
'hs300'
)
univ_desc
=
universe
.
save
()
loaded_universe
=
load_universe
(
univ_desc
)
self
.
assertEqual
(
universe
,
loaded_universe
)
universe
=
Universe
(
'zz500'
)
&
Universe
(
'hs300'
)
univ_desc
=
universe
.
save
()
loaded_universe
=
load_universe
(
univ_desc
)
self
.
assertEqual
(
universe
,
loaded_universe
)
\ No newline at end of file
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