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
cc5ffcc0
Commit
cc5ffcc0
authored
Aug 20, 2017
by
Dr.李
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed sql server bug
parent
97fd1291
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
6 deletions
+10
-6
sqlengine.py
alphamind/data/engines/sqlengine.py
+9
-5
quantile_analysis_example.py
alphamind/examples/quantile_analysis_example.py
+1
-1
No files found.
alphamind/data/engines/sqlengine.py
View file @
cc5ffcc0
...
...
@@ -119,6 +119,11 @@ class SqlEngine(object):
self
.
session
=
None
self
.
create_session
()
if
self
.
engine
.
name
==
'mssql'
:
self
.
ln_func
=
func
.
log
else
:
self
.
ln_func
=
func
.
ln
def
create_session
(
self
):
db_session
=
orm
.
sessionmaker
(
bind
=
self
.
engine
)
self
.
session
=
db_session
()
...
...
@@ -169,7 +174,7 @@ class SqlEngine(object):
else
:
end_date
=
expiry_date
query
=
select
([
DailyReturn
.
Code
,
func
.
sum
(
func
.
ln
(
1.
+
DailyReturn
.
d1
))
.
label
(
'dx'
)])
.
where
(
query
=
select
([
DailyReturn
.
Code
,
func
.
sum
(
self
.
ln_func
(
1.
+
DailyReturn
.
d1
))
.
label
(
'dx'
)])
.
where
(
and_
(
DailyReturn
.
Date
.
between
(
start_date
,
end_date
),
DailyReturn
.
Code
.
in_
(
codes
)
...
...
@@ -194,7 +199,7 @@ class SqlEngine(object):
q2
=
universe
.
query_range
(
start_date
,
end_date
)
.
alias
(
'temp_universe'
)
big_table
=
join
(
DailyReturn
,
q2
,
and_
(
DailyReturn
.
Date
==
q2
.
c
.
Date
,
DailyReturn
.
Code
==
q2
.
c
.
Code
))
stats
=
func
.
sum
(
func
.
ln
(
1.
+
DailyReturn
.
d1
))
.
over
(
stats
=
func
.
sum
(
self
.
ln_func
(
1.
+
DailyReturn
.
d1
))
.
over
(
partition_by
=
DailyReturn
.
Code
,
order_by
=
DailyReturn
.
Date
,
rows
=
(
0
,
horizon
))
.
label
(
'dx'
)
...
...
@@ -374,6 +379,7 @@ class SqlEngine(object):
benchmark
:
int
=
None
,
risk_model
:
str
=
'short'
)
->
Dict
[
str
,
pd
.
DataFrame
]:
dates
=
sorted
(
dates
)
total_data
=
{}
factor_data
=
self
.
fetch_factor_range
(
universe
,
factors
,
start_date
,
end_date
,
dates
)
...
...
@@ -403,8 +409,6 @@ if __name__ == '__main__':
ref_date
=
'2017-08-10'
codes
=
engine
.
fetch_codes_range
(
universe
,
None
,
None
,
[
'2017-01-01'
,
'2017-08-10'
])
data1
=
engine
.
fetch_dx_return
(
'2017-08-01'
,
)
data2
=
engine
.
fetch_dx_return_range
(
universe
,
'2017-08-01'
,
'2017-08-10'
,
[
'2017-08-01'
,
'2017-08-10'
])
print
(
codes
)
print
(
data
)
print
(
data
2
)
alphamind/examples/quantile_analysis_example.py
View file @
cc5ffcc0
...
...
@@ -19,7 +19,7 @@ n_bins = 5
factor_weights
=
np
.
array
([
1.
])
freq
=
'1
w
'
freq
=
'1
d
'
if
freq
==
'1m'
:
horizon
=
21
...
...
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