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
f46e445d
Commit
f46e445d
authored
Sep 07, 2017
by
Dr.李
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update formula expression example
parent
59cf08bb
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
17 deletions
+13
-17
formula_expression.py
alphamind/examples/formula_expression.py
+13
-17
No files found.
alphamind/examples/formula_expression.py
View file @
f46e445d
...
...
@@ -11,14 +11,15 @@ from PyFin.api import *
from
alphamind.api
import
*
from
matplotlib
import
pyplot
as
plt
plt
.
style
.
use
(
'ggplot'
)
# defind your alpha formula here
base_factors
=
[
'EPS'
,
'ROEDiluted'
,
'BTOP'
]
#, 'ROEDiluted', 'VAL', 'CFinc1']
import
datetime
as
dt
expression
=
0.
start
=
dt
.
datetime
.
now
()
for
name
in
base_factors
:
expression
=
expression
+
LAST
(
name
)
formula1
=
CSRank
(
DIFF
(
LOG
(
"turnoverValue"
)))
formula2
=
CSRank
((
LAST
(
'closePrice'
)
-
LAST
(
'openPrice'
))
/
LAST
(
'openPrice'
))
expression
=
-
CORR
(
6
,
formula1
^
formula2
)
alpha_factor_name
=
'alpha_factor'
alpha_factor
=
{
alpha_factor_name
:
expression
}
...
...
@@ -29,18 +30,11 @@ engine = SqlEngine('postgresql+psycopg2://postgres:A12345678!@10.63.6.220/alpha'
universe
=
Universe
(
'custom'
,
[
'zz500'
])
benchmark_code
=
905
neutralize_risk
=
[
'SIZE'
]
+
industry_styles
freq
=
'1
w
'
freq
=
'1
d
'
n_bins
=
5
if
freq
==
'1m'
:
horizon
=
21
elif
freq
==
'1w'
:
horizon
=
4
elif
freq
==
'1d'
:
horizon
=
0
dates
=
makeSchedule
(
'2012-01-01'
,
'2012-08-01'
,
dates
=
makeSchedule
(
'2012-04-01'
,
'2017-09-03'
,
tenor
=
freq
,
calendar
=
'china.sse'
)
...
...
@@ -48,7 +42,7 @@ factor_all_data = engine.fetch_data_range(universe,
alpha_factor
,
dates
=
dates
,
benchmark
=
905
)[
'factor'
]
return_all_data
=
engine
.
fetch_dx_return_range
(
universe
,
dates
=
dates
,
horizon
=
horizon
)
return_all_data
=
engine
.
fetch_dx_return_range
(
universe
,
dates
=
dates
,
horizon
=
0
)
factor_groups
=
factor_all_data
.
groupby
(
'trade_date'
)
return_groups
=
return_all_data
.
groupby
(
'trade_date'
)
...
...
@@ -84,8 +78,10 @@ for i, value in enumerate(factor_groups):
df
=
pd
.
DataFrame
(
final_res
,
index
=
dates
)
start_date
=
advanceDateByCalendar
(
'china.sse'
,
dates
[
0
],
'-1
w
'
)
start_date
=
advanceDateByCalendar
(
'china.sse'
,
dates
[
0
],
'-1
d
'
)
df
.
loc
[
start_date
]
=
0.
df
.
sort_index
(
inplace
=
True
)
df
=
df
.
cumsum
()
.
plot
()
plt
.
show
()
print
(
dt
.
datetime
.
now
()
-
start
)
\ No newline at end of file
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