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
e087207b
Commit
e087207b
authored
Aug 24, 2017
by
Dr.李
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added one more table in factors
parent
f45e145e
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
8 deletions
+24
-8
sqlengine.py
alphamind/data/engines/sqlengine.py
+24
-8
No files found.
alphamind/data/engines/sqlengine.py
View file @
e087207b
...
@@ -35,6 +35,7 @@ from alphamind.data.dbmodel.models import RiskExposure
...
@@ -35,6 +35,7 @@ from alphamind.data.dbmodel.models import RiskExposure
from
alphamind.data.dbmodel.models
import
Market
from
alphamind.data.dbmodel.models
import
Market
from
alphamind.data.transformer
import
Transformer
from
alphamind.data.transformer
import
Transformer
from
PyFin.api
import
advanceDateByCalendar
from
PyFin.api
import
advanceDateByCalendar
from
PyFin.Analysis.SecurityValueHolders
import
SecurityLatestValueHolder
risk_styles
=
[
'BETA'
,
risk_styles
=
[
'BETA'
,
'MOMENTUM'
,
'MOMENTUM'
,
...
@@ -82,7 +83,7 @@ macro_styles = ['COUNTRY']
...
@@ -82,7 +83,7 @@ macro_styles = ['COUNTRY']
total_risk_factors
=
risk_styles
+
industry_styles
+
macro_styles
total_risk_factors
=
risk_styles
+
industry_styles
+
macro_styles
factor_tables
=
[
Uqer
,
Tiny
,
LegacyFactor
,
Experimental
,
RiskExposure
]
factor_tables
=
[
Uqer
,
Tiny
,
LegacyFactor
,
Experimental
,
Market
]
def
append_industry_info
(
df
):
def
append_industry_info
(
df
):
...
@@ -107,9 +108,10 @@ def _map_risk_model_table(risk_model: str) -> tuple:
...
@@ -107,9 +108,10 @@ def _map_risk_model_table(risk_model: str) -> tuple:
def
_map_factors
(
factors
:
Iterable
[
str
])
->
dict
:
def
_map_factors
(
factors
:
Iterable
[
str
])
->
dict
:
factor_cols
=
{}
factor_cols
=
{}
excluded
=
{
'Date'
,
'Code'
,
'isOpen'
,
}
for
f
in
factors
:
for
f
in
factors
:
for
t
in
factor_tables
:
for
t
in
factor_tables
:
if
f
in
t
.
__table__
.
columns
:
if
f
not
in
excluded
and
f
in
t
.
__table__
.
columns
:
factor_cols
[
t
.
__table__
.
columns
[
f
]]
=
t
factor_cols
[
t
.
__table__
.
columns
[
f
]]
=
t
break
break
return
factor_cols
return
factor_cols
...
@@ -271,14 +273,28 @@ class SqlEngine(object):
...
@@ -271,14 +273,28 @@ class SqlEngine(object):
dependency
=
transformer
.
dependency
dependency
=
transformer
.
dependency
factor_cols
=
_map_factors
(
dependency
)
factor_cols
=
_map_factors
(
dependency
)
fast_path_optimization
=
False
for
name
in
transformer
.
expressions
:
if
not
isinstance
(
name
,
SecurityLatestValueHolder
)
and
not
isinstance
(
name
,
str
):
break
else
:
fast_path_optimization
=
True
if
fast_path_optimization
:
real_start_date
=
start_date
real_end_date
=
end_date
real_dates
=
dates
else
:
if
dates
:
if
dates
:
real_start_date
=
advanceDateByCalendar
(
'china.sse'
,
dates
[
0
],
str
(
-
default_window
)
+
'b'
)
.
strftime
(
'
%
Y-
%
m-
%
d'
)
real_start_date
=
advanceDateByCalendar
(
'china.sse'
,
dates
[
0
],
str
(
-
default_window
)
+
'b'
)
.
strftime
(
'
%
Y-
%
m-
%
d'
)
real_end_date
=
dates
[
-
1
]
real_end_date
=
dates
[
-
1
]
else
:
else
:
real_start_date
=
advanceDateByCalendar
(
'china.sse'
,
start_date
,
str
(
-
default_window
)
+
'b'
)
.
strftime
(
'
%
Y-
%
m-
%
d'
)
real_start_date
=
advanceDateByCalendar
(
'china.sse'
,
start_date
,
str
(
-
default_window
)
+
'b'
)
.
strftime
(
'
%
Y-
%
m-
%
d'
)
real_end_date
=
end_date
real_end_date
=
end_date
real_dates
=
None
q2
=
universe
.
query_range
(
real_start_date
,
real_end_date
)
.
alias
(
'temp_universe'
)
q2
=
universe
.
query_range
(
real_start_date
,
real_end_date
,
real_dates
)
.
alias
(
'temp_universe'
)
big_table
=
join
(
Market
,
q2
,
and_
(
Market
.
Date
==
q2
.
c
.
Date
,
Market
.
Code
==
q2
.
c
.
Code
))
big_table
=
join
(
Market
,
q2
,
and_
(
Market
.
Date
==
q2
.
c
.
Date
,
Market
.
Code
==
q2
.
c
.
Code
))
for
t
in
set
(
factor_cols
.
values
()):
for
t
in
set
(
factor_cols
.
values
()):
...
@@ -464,6 +480,6 @@ if __name__ == '__main__':
...
@@ -464,6 +480,6 @@ if __name__ == '__main__':
ref_date
=
'2017-08-10'
ref_date
=
'2017-08-10'
codes
=
engine
.
fetch_codes
(
universe
=
universe
,
ref_date
=
'2017-08-10'
)
codes
=
engine
.
fetch_codes
(
universe
=
universe
,
ref_date
=
'2017-08-10'
)
data2
=
engine
.
fetch_factor_range
(
universe
=
universe
,
start_date
=
'2017-08-01'
,
end_date
=
'2017-08-10'
,
factors
=
{
'factor'
:
MAXIMUM
((
'EPS'
,
'ROEDiluted'
))})
data2
=
engine
.
fetch_factor_range
(
universe
=
universe
,
dates
=
[
'2017-08-01'
,
'2017-08-10'
]
,
factors
=
{
'factor'
:
MAXIMUM
((
'EPS'
,
'ROEDiluted'
))})
print
(
codes
)
print
(
codes
)
print
(
data2
)
print
(
data2
)
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