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
20147520
Commit
20147520
authored
Nov 10, 2018
by
Dr.李
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
remove api and add api
parent
b999368b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
29 deletions
+6
-29
sqlengine.py
alphamind/data/engines/sqlengine.py
+6
-29
No files found.
alphamind/data/engines/sqlengine.py
View file @
20147520
...
@@ -25,6 +25,7 @@ from alphamind.data.dbmodel.models import Market
...
@@ -25,6 +25,7 @@ from alphamind.data.dbmodel.models import Market
from
alphamind.data.dbmodel.models
import
IndexMarket
from
alphamind.data.dbmodel.models
import
IndexMarket
from
alphamind.data.dbmodel.models
import
Universe
as
UniverseTable
from
alphamind.data.dbmodel.models
import
Universe
as
UniverseTable
from
alphamind.data.dbmodel.models
import
RiskExposure
from
alphamind.data.dbmodel.models
import
RiskExposure
from
alphamind.data.dbmodel.models
import
FundMaster
from
alphamind.data.transformer
import
Transformer
from
alphamind.data.transformer
import
Transformer
from
alphamind.data.engines.utilities
import
_map_factors
from
alphamind.data.engines.utilities
import
_map_factors
from
alphamind.data.engines.utilities
import
_map_industry_category
from
alphamind.data.engines.utilities
import
_map_industry_category
...
@@ -81,18 +82,13 @@ macro_styles = ['COUNTRY']
...
@@ -81,18 +82,13 @@ macro_styles = ['COUNTRY']
total_risk_factors
=
risk_styles
+
industry_styles
+
macro_styles
total_risk_factors
=
risk_styles
+
industry_styles
+
macro_styles
DEFAULT_URL
=
'postgresql+psycopg2://postgres:A12345678!@10.63.6.220/alpha'
DAILY_RETURN_OFFSET
=
0
DAILY_RETURN_OFFSET
=
0
class
SqlEngine
(
object
):
class
SqlEngine
(
object
):
def
__init__
(
self
,
def
__init__
(
self
,
db_url
:
str
=
None
):
db_url
:
str
=
None
):
if
db_url
:
self
.
engine
=
sa
.
create_engine
(
db_url
)
self
.
engine
=
sa
.
create_engine
(
db_url
)
else
:
self
.
engine
=
sa
.
create_engine
(
DEFAULT_URL
)
self
.
session
=
self
.
create_session
()
self
.
session
=
self
.
create_session
()
...
@@ -116,33 +112,14 @@ class SqlEngine(object):
...
@@ -116,33 +112,14 @@ class SqlEngine(object):
db_session
=
orm
.
sessionmaker
(
bind
=
self
.
engine
)
db_session
=
orm
.
sessionmaker
(
bind
=
self
.
engine
)
return
db_session
()
return
db_session
()
def
fetch_fund_meta
(
self
)
->
pd
.
DataFrame
:
query
=
self
.
session
.
query
(
FundMaster
)
return
pd
.
read_sql
(
query
.
statement
,
query
.
session
.
bind
)
def
fetch_factors_meta
(
self
)
->
pd
.
DataFrame
:
def
fetch_factors_meta
(
self
)
->
pd
.
DataFrame
:
query
=
self
.
session
.
query
(
FactorMaster
)
query
=
self
.
session
.
query
(
FactorMaster
)
return
pd
.
read_sql
(
query
.
statement
,
query
.
session
.
bind
)
return
pd
.
read_sql
(
query
.
statement
,
query
.
session
.
bind
)
def
fetch_factor_coverage
(
self
,
start_date
:
str
,
end_date
:
str
,
universe
:
str
=
None
,
source
:
str
=
None
)
->
pd
.
DataFrame
:
conditions
=
[]
conditions
.
append
(
FactorLog
.
trade_date
.
between
(
start_date
,
end_date
))
if
universe
:
conditions
.
append
(
FactorLog
.
universe
==
universe
)
if
source
:
conditions
.
append
(
FactorLog
.
source
==
source
)
query
=
select
([
FactorLog
])
.
where
(
and_
(
*
conditions
)
)
return
pd
.
read_sql
(
query
,
self
.
session
.
bind
)
def
fetch_risk_meta
(
self
)
->
pd
.
DataFrame
:
def
fetch_risk_meta
(
self
)
->
pd
.
DataFrame
:
query
=
self
.
session
.
query
(
RiskMaster
)
query
=
self
.
session
.
query
(
RiskMaster
)
return
pd
.
read_sql
(
query
.
statement
,
query
.
session
.
bind
)
return
pd
.
read_sql
(
query
.
statement
,
query
.
session
.
bind
)
...
...
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