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
f4e68e0e
Commit
f4e68e0e
authored
Jul 11, 2017
by
Dr.李
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
modified sql engine and factor analysis implementation
parent
4e86d506
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
520 additions
and
155 deletions
+520
-155
factoranalysis.py
alphamind/analysis/factoranalysis.py
+15
-4
sqlengine.py
alphamind/data/engines/sqlengine.py
+7
-2
neutralize algorithm comparison.ipynb
notebooks/neutralize algorithm comparison.ipynb
+498
-149
No files found.
alphamind/analysis/factoranalysis.py
View file @
f4e68e0e
...
...
@@ -66,7 +66,7 @@ class FDataPack(object):
def
__init__
(
self
,
raw_factors
:
np
.
ndarray
,
d1returns
,
d1returns
=
None
,
factor_names
:
List
[
str
]
=
None
,
codes
:
List
=
None
,
groups
:
Optional
[
np
.
ndarray
]
=
None
,
...
...
@@ -75,7 +75,13 @@ class FDataPack(object):
risk_names
:
List
[
str
]
=
None
):
self
.
raw_factors
=
raw_factors
self
.
d1returns
=
d1returns
.
flatten
()
if
d1returns
is
not
None
:
self
.
d1returns
=
d1returns
.
flatten
()
else
:
self
.
d1returns
=
None
if
factor_names
:
self
.
factor_names
=
factor_names
else
:
...
...
@@ -93,6 +99,10 @@ class FDataPack(object):
return
self
.
risk_exp
@
self
.
benchmark
def
settle
(
self
,
weights
:
np
.
ndarray
)
->
pd
.
DataFrame
:
if
self
.
d1returns
is
None
:
raise
ValueError
(
"No return is offered"
)
weights
=
weights
.
flatten
()
if
self
.
benchmark
is
not
None
:
...
...
@@ -158,7 +168,7 @@ class FDataPack(object):
def
factor_analysis
(
factors
:
pd
.
DataFrame
,
factor_weights
:
np
.
ndarray
,
industry
:
np
.
ndarray
,
d1returns
:
np
.
ndarray
,
d1returns
:
np
.
ndarray
=
None
,
detail_analysis
=
True
,
benchmark
:
Optional
[
np
.
ndarray
]
=
None
,
risk_exp
:
Optional
[
np
.
ndarray
]
=
None
,
...
...
@@ -208,7 +218,8 @@ def factor_analysis(factors: pd.DataFrame,
else
:
analysis
=
None
return
pd
.
DataFrame
({
'weight'
:
weights
,
'industry'
:
industry
},
'industry'
:
industry
,
'er'
:
er
},
index
=
factors
.
index
),
\
analysis
...
...
alphamind/data/engines/sqlengine.py
View file @
f4e68e0e
...
...
@@ -102,6 +102,12 @@ class SqlEngine(object):
return
sorted
(
codes_set
)
def
fetch_d1_return
(
self
,
ref_date
,
codes
):
codes_str
=
','
.
join
(
str
(
c
)
for
c
in
codes
)
sql
=
"select Code, d1 from daily_return where Date = '{ref_date}' and Code in ({codes})"
.
format
(
ref_date
=
ref_date
,
codes
=
codes_str
)
return
pd
.
read_sql
(
sql
,
self
.
engine
)
def
fetch_data
(
self
,
ref_date
,
factors
:
Iterable
[
str
],
codes
:
Iterable
[
int
],
...
...
@@ -124,13 +130,12 @@ class SqlEngine(object):
special_risk_table
=
'specific_risk_'
+
risk_model
codes_str
=
','
.
join
(
str
(
c
)
for
c
in
codes
)
sql
=
"select uqer.Code, {factors}, {risks}, market.isOpen,
daily_return.d1,
{risk_table}.SRISK"
\
sql
=
"select uqer.Code, {factors}, {risks}, market.isOpen, {risk_table}.SRISK"
\
" from (uqer INNER JOIN"
\
" risk_exposure on uqer.Date = risk_exposure.Date and uqer.Code = risk_exposure.Code)"
\
" INNER JOIN market on uqer.Date = market.Date and uqer.Code = market.Code"
\
" LEFT JOIN tiny on uqer.Date = tiny.Date and uqer.Code = tiny.Code"
\
" LEFT JOIN legacy_factor on uqer.Date = legacy_factor.Date and uqer.Code = legacy_factor.Code"
\
" INNER JOIN daily_return on uqer.Date = daily_return.Date and uqer.Code = daily_return.Code"
\
" INNER JOIN {risk_table} on uqer.Date = {risk_table}.Date and uqer.Code = {risk_table}.Code"
\
" where uqer.Date = '{ref_date}' and uqer.Code in ({codes})"
.
format
(
factors
=
factor_str
,
ref_date
=
ref_date
,
...
...
notebooks/neutralize algorithm comparison.ipynb
View file @
f4e68e0e
This source diff could not be displayed because it is too large. You can
view the blob
instead.
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