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
910ae0a4
Commit
910ae0a4
authored
Jan 31, 2018
by
Dr.李
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update example
parent
57c969bd
Changes
2
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
266 additions
and
191 deletions
+266
-191
factor_analysis_example.py
alphamind/examples/factor_analysis_example.py
+215
-174
factor_res_analysis.py
alphamind/examples/factor_res_analysis.py
+51
-17
No files found.
alphamind/examples/factor_analysis_example.py
View file @
910ae0a4
This diff is collapsed.
Click to expand it.
alphamind/examples/factor_res_analysis.py
View file @
910ae0a4
...
@@ -13,6 +13,7 @@ from alphamind.api import *
...
@@ -13,6 +13,7 @@ from alphamind.api import *
def
factor_residue_analysis
(
start_date
,
def
factor_residue_analysis
(
start_date
,
end_date
,
end_date
,
factor_name
,
factor
,
factor
,
freq
,
freq
,
universe
,
universe
,
...
@@ -26,10 +27,8 @@ def factor_residue_analysis(start_date,
...
@@ -26,10 +27,8 @@ def factor_residue_analysis(start_date,
tenor
=
freq
,
tenor
=
freq
,
calendar
=
'china.sse'
)
calendar
=
'china.sse'
)
alpha_factor_name
=
factor
+
'_res'
alpha_factor_name
=
factor_name
+
'_res'
base1
=
LAST
(
'roe_q'
)
alpha_factor
=
{
alpha_factor_name
:
factor
}
base2
=
CSRes
(
LAST
(
'ep_q'
),
'roe_q'
)
alpha_factor
=
{
alpha_factor_name
:
CSRes
(
CSRes
(
LAST
(
factor
),
base1
),
base2
)}
factor_all_data
=
engine
.
fetch_data_range
(
universe
,
factor_all_data
=
engine
.
fetch_data_range
(
universe
,
alpha_factor
,
alpha_factor
,
dates
=
dates
)[
'factor'
]
dates
=
dates
)[
'factor'
]
...
@@ -74,19 +73,54 @@ def factor_residue_analysis(start_date,
...
@@ -74,19 +73,54 @@ def factor_residue_analysis(start_date,
return
df
return
df
engine
=
SqlEngine
()
def
factor_analysis
(
f_name
):
df
=
engine
.
fetch_factor_coverage
()
.
groupby
(
'factor'
)
.
mean
()
from
alphamind.api
import
SqlEngine
,
Universe
,
alpha_logger
df
=
df
[
df
.
coverage
>=
0.98
]
engine
=
SqlEngine
()
universe
=
Universe
(
'custom'
,
[
'zz800'
])
universe
=
Universe
(
'custom'
,
[
'zz800'
])
base1
=
LAST
(
'Alpha60'
)
factor_df
=
pd
.
DataFrame
()
base2
=
CSRes
(
'roe_q'
,
base1
)
base3
=
CSRes
(
CSRes
(
'ep_q'
,
base1
),
base2
)
for
i
,
factor
in
enumerate
(
df
.
index
):
factor
=
CSRes
(
CSRes
(
CSRes
(
LAST
(
f_name
),
base1
),
base2
),
base3
)
res
=
factor_residue_analysis
(
'2011-01-01'
,
res
=
factor_residue_analysis
(
'2010-01-01'
,
'2018-01-05'
,
'2018-01-26'
,
f_name
,
factor
,
factor
,
'
5
b'
,
'
10
b'
,
universe
,
universe
,
engine
)
engine
)
factor_df
[
factor
]
=
res
[
'$top1 - bottom1$'
]
alpha_logger
.
info
(
'{0} is done'
.
format
(
f_name
))
alpha_logger
.
info
(
'{0}: {1} is done'
.
format
(
i
+
1
,
factor
))
return
f_name
,
res
if
__name__
==
'__main__'
:
from
dask.distributed
import
Client
client
=
Client
(
'10.63.6.176:8786'
)
engine
=
SqlEngine
()
df
=
engine
.
fetch_factor_coverage
()
df
=
df
[
df
.
universe
==
'zz800'
]
.
groupby
(
'factor'
)
.
mean
()
df
=
df
[
df
.
coverage
>=
0.98
]
universe
=
Universe
(
'custom'
,
[
'zz800'
])
factor_df
=
pd
.
DataFrame
()
tasks
=
client
.
map
(
factor_analysis
,
df
.
index
.
tolist
())
res
=
client
.
gather
(
tasks
)
for
f_name
,
df
in
res
:
factor_df
[
f_name
]
=
df
[
'$top1 - bottom1$'
]
# for i, f_name in enumerate(df.index):
# base1 = LAST('Alpha60')
# base2 = CSRes('roe_q', base1)
# base3 = CSRes(CSRes('ep_q', base1), base2)
# factor = CSRes(CSRes(CSRes(LAST(f_name), base1), base2), base3)
# res = factor_residue_analysis('2010-01-01',
# '2018-01-22',
# f_name,
# factor,
# '10b',
# universe,
# engine)
# factor_df[f_name] = res['$top1 - bottom1$']
# alpha_logger.info('{0}: {1} is done'.format(i + 1, f_name))
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