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
dddf850a
Commit
dddf850a
authored
Jan 22, 2018
by
Dr.李
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update example
parent
b1c1d69f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
23 deletions
+21
-23
factor_analysis_example.py
alphamind/examples/factor_analysis_example.py
+20
-22
xgboost
xgboost
+1
-1
No files found.
alphamind/examples/factor_analysis_example.py
View file @
dddf850a
...
@@ -20,37 +20,37 @@ plt.style.use('ggplot')
...
@@ -20,37 +20,37 @@ plt.style.use('ggplot')
Back test parameter settings
Back test parameter settings
"""
"""
start_date
=
'201
5
-01-01'
start_date
=
'201
1
-01-01'
end_date
=
'201
7-11-28
'
end_date
=
'201
8-01-11
'
benchmark_code
=
300
benchmark_code
=
300
universe_name
=
[
'
hs3
00'
]
universe_name
=
[
'
zz8
00'
]
universe
=
Universe
(
universe_name
,
universe_name
)
universe
=
Universe
(
'custom'
,
universe_name
)
frequency
=
'5b'
frequency
=
'5b'
method
=
'risk_neutral'
method
=
'risk_neutral'
use_rank
=
100
industry_lower
=
1.
industry_lower
=
1.
industry_upper
=
1.
industry_upper
=
1.
neutralize_risk
=
[
'SIZE'
]
+
industry_styles
neutralize_risk
=
[
'SIZE'
,
'LEVERAGE'
]
+
industry_styles
constraint_risk
=
[
'SIZE'
]
+
industry_styles
constraint_risk
=
[
'SIZE'
,
'LEVERAGE'
]
+
industry_styles
size_risk_lower
=
0
size_risk_lower
=
0
size_risk_upper
=
0
size_risk_upper
=
0
turn_over_target_base
=
0.25
turn_over_target_base
=
0.25
benchmark_total_lower
=
1.
benchmark_total_lower
=
0.8
benchmark_total_upper
=
1.
benchmark_total_upper
=
1.
0
horizon
=
map_freq
(
frequency
)
horizon
=
map_freq
(
frequency
)
executor
=
NaiveExecutor
()
executor
=
NaiveExecutor
()
engine
=
SqlEngine
()
engine
=
SqlEngine
(
'postgres+psycopg2://postgres:we083826@192.168.0.102/alpha'
)
"""
"""
Model phase: we need 1 constant linear model and one linear regression model
Model phase: we need 1 constant linear model and one linear regression model
"""
"""
alpha_name
=
[
'alpha_factor'
]
alpha_name
=
[
'alpha_factor'
]
factor_name
=
'SalesCostRatio'
base1
=
LAST
(
'roe_q'
)
base1
=
LAST
(
'roe_q'
)
base2
=
CSRes
(
LAST
(
'ep_q'
),
'roe_q'
)
base2
=
CSRes
(
LAST
(
'ep_q'
),
'roe_q'
)
simple_expression
=
CSRes
(
CSRes
(
LAST
(
'DividendPS'
),
base1
),
base2
)
simple_expression
=
DIFF
(
CSRes
(
CSRes
(
LAST
(
factor_name
),
base1
),
base2
)
)
const_features
=
{
alpha_name
[
0
]:
simple_expression
}
const_features
=
{
alpha_name
[
0
]:
simple_expression
}
const_weights
=
np
.
array
([
1.
])
const_weights
=
np
.
array
([
1.
])
...
@@ -105,16 +105,16 @@ for i, value in enumerate(factor_groups):
...
@@ -105,16 +105,16 @@ for i, value in enumerate(factor_groups):
constraint
=
Constraints
(
risk_exp_expand
,
risk_names
)
constraint
=
Constraints
(
risk_exp_expand
,
risk_names
)
for
i
,
name
in
enumerate
(
risk_names
):
for
j
,
name
in
enumerate
(
risk_names
):
if
name
==
'total'
:
if
name
==
'total'
:
constraint
.
set_constraints
(
name
,
constraint
.
set_constraints
(
name
,
lower_bound
=
risk_target
[
i
],
lower_bound
=
risk_target
[
j
],
upper_bound
=
risk_target
[
i
])
upper_bound
=
risk_target
[
j
])
elif
name
==
'SIZE'
:
elif
name
==
'SIZE'
:
base_target
=
abs
(
risk_target
[
i
])
base_target
=
abs
(
risk_target
[
j
])
constraint
.
set_constraints
(
name
,
constraint
.
set_constraints
(
name
,
lower_bound
=
risk_target
[
i
]
+
base_target
*
size_risk_lower
,
lower_bound
=
risk_target
[
j
]
+
base_target
*
size_risk_lower
,
upper_bound
=
risk_target
[
i
]
+
base_target
*
size_risk_upper
)
upper_bound
=
risk_target
[
j
]
+
base_target
*
size_risk_upper
)
elif
name
==
'benchmark_total'
:
elif
name
==
'benchmark_total'
:
base_target
=
benchmark_w
.
sum
()
base_target
=
benchmark_w
.
sum
()
constraint
.
set_constraints
(
name
,
constraint
.
set_constraints
(
name
,
...
@@ -122,8 +122,8 @@ for i, value in enumerate(factor_groups):
...
@@ -122,8 +122,8 @@ for i, value in enumerate(factor_groups):
upper_bound
=
benchmark_total_upper
*
base_target
)
upper_bound
=
benchmark_total_upper
*
base_target
)
else
:
else
:
constraint
.
set_constraints
(
name
,
constraint
.
set_constraints
(
name
,
lower_bound
=
risk_target
[
i
]
*
industry_lower
,
lower_bound
=
risk_target
[
j
]
*
industry_lower
,
upper_bound
=
risk_target
[
i
]
*
industry_upper
)
upper_bound
=
risk_target
[
j
]
*
industry_upper
)
factor_values
=
factor_processing
(
total_data
[
alpha_name
]
.
values
,
factor_values
=
factor_processing
(
total_data
[
alpha_name
]
.
values
,
pre_process
=
[
winsorize_normal
,
standardize
],
pre_process
=
[
winsorize_normal
,
standardize
],
...
@@ -154,7 +154,6 @@ for i, value in enumerate(factor_groups):
...
@@ -154,7 +154,6 @@ for i, value in enumerate(factor_groups):
False
,
False
,
benchmark_w
,
benchmark_w
,
method
=
method
,
method
=
method
,
use_rank
=
use_rank
,
turn_over_target
=
turn_over_target
,
turn_over_target
=
turn_over_target
,
current_position
=
current_position
,
current_position
=
current_position
,
lbound
=
lbound
,
lbound
=
lbound
,
...
@@ -168,7 +167,6 @@ for i, value in enumerate(factor_groups):
...
@@ -168,7 +167,6 @@ for i, value in enumerate(factor_groups):
False
,
False
,
benchmark_w
,
benchmark_w
,
method
=
method
,
method
=
method
,
use_rank
=
use_rank
,
lbound
=
lbound
,
lbound
=
lbound
,
ubound
=
ubound
)
ubound
=
ubound
)
...
@@ -207,7 +205,7 @@ ret_df['tc_cost'] = ret_df.turn_over * 0.002
...
@@ -207,7 +205,7 @@ ret_df['tc_cost'] = ret_df.turn_over * 0.002
ret_df
[
'returns'
]
=
ret_df
[
'returns'
]
-
ret_df
[
'index'
]
*
ret_df
[
'leverage'
]
ret_df
[
'returns'
]
=
ret_df
[
'returns'
]
-
ret_df
[
'index'
]
*
ret_df
[
'leverage'
]
ret_df
[[
'returns'
,
'tc_cost'
]]
.
cumsum
()
.
plot
(
figsize
=
(
12
,
6
),
ret_df
[[
'returns'
,
'tc_cost'
]]
.
cumsum
()
.
plot
(
figsize
=
(
12
,
6
),
title
=
'Fixed frequency rebalanced: {0}
'
.
format
(
frequency
),
title
=
'Fixed frequency rebalanced: {0}
for {1}'
.
format
(
frequency
,
factor_name
),
secondary_y
=
'tc_cost'
)
secondary_y
=
'tc_cost'
)
plt
.
show
()
plt
.
show
()
xgboost
@
8b2f4e2d
Subproject commit
bf4367184164e593cd2856ef38f8dd4f8cc76999
Subproject commit
8b2f4e2d394a5fc6d76a8b90f5c0bdde054c958d
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