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
d18cf28c
Commit
d18cf28c
authored
Jul 11, 2017
by
Dr.李
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update example
parent
c2f950d3
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
7 deletions
+14
-7
example2.py
alphamind/examples/example2.py
+14
-7
No files found.
alphamind/examples/example2.py
View file @
d18cf28c
...
...
@@ -5,12 +5,14 @@ Created on 2017-7-10
@author: cheng.li
"""
import
datetime
as
dt
import
pandas
as
pd
from
alphamind.analysis.factoranalysis
import
factor_analysis
from
alphamind.data.engines.sqlengine
import
SqlEngine
from
alphamind.data.engines.universe
import
Universe
from
alphamind.data.engines.sqlengine
import
industry_styles
from
PyFin.api
import
bizDatesList
from
PyFin.api
import
makeSchedule
engine
=
SqlEngine
(
'mssql+pymssql://licheng:A12345678!@10.63.6.220/alpha'
)
universe
=
Universe
(
'custom'
,
[
'zz500'
])
...
...
@@ -21,15 +23,16 @@ total_risks = used_risk_styles + industry_styles
build_type
=
'risk_neutral'
def
calculate_one_day
(
ref_date
,
factors
,
factor_weights
):
def
calculate_one_day
(
ref_date
,
factors
,
factor_weights
,
horizon_end
=
None
):
print
(
ref_date
)
codes
=
engine
.
fetch_codes
(
ref_date
,
universe
)
total_data
=
engine
.
fetch_data
(
ref_date
,
factors
,
codes
,
905
)
factor_data
=
total_data
[
'factor'
]
factor_df
=
factor_data
[[
'Code'
,
'industry'
,
'weight'
,
'isOpen'
]
+
total_risks
+
factors
]
.
dropna
()
dx_return
=
engine
.
fetch_dx_return
(
ref_date
,
codes
)
dx_return
=
engine
.
fetch_dx_return
(
ref_date
,
codes
,
expiry_date
=
horizon_end
)
factor_df
=
pd
.
merge
(
factor_df
,
dx_return
,
on
=
[
'Code'
])
weights
,
_
=
factor_analysis
(
factor_df
[
factors
],
...
...
@@ -51,15 +54,19 @@ if __name__ == '__main__':
factors
=
[
'BDTO'
,
'CFinc1'
,
'DivP'
,
'EPS'
,
'RVOL'
,
'DROEAfterNonRecurring'
]
factor_weights
=
[
0.10
,
0.30
,
0.15
,
0.18
,
0.11
,
0.35
]
biz_dates
=
bizDatesList
(
'china.sse'
,
'2017-01-01'
,
'2017-07-07
'
)
biz_dates
=
makeSchedule
(
'2015-01-01'
,
'2017-07-07'
,
'1w'
,
'china.sse
'
)
ers
=
[]
dates
=
[]
for
ref_date
in
biz_dates
:
ref_date
,
er
=
calculate_one_day
(
ref_date
,
factors
,
factor_weights
)
dates
.
append
(
ref_date
)
ers
.
append
(
er
)
for
i
,
ref_date
in
enumerate
(
biz_dates
[:
-
1
]):
ref_date
=
ref_date
.
strftime
(
"
%
Y-
%
m-
%
d"
)
try
:
ref_date
,
er
=
calculate_one_day
(
ref_date
,
factors
,
factor_weights
,
horizon_end
=
biz_dates
[
i
+
1
])
dates
.
append
(
ref_date
)
ers
.
append
(
er
)
except
Exception
as
e
:
print
(
str
(
e
)
+
": {0}"
.
format
(
ref_date
))
res
=
pd
.
Series
(
ers
,
index
=
dates
)
res
.
cumsum
()
.
plot
()
...
...
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