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
dd6f5e66
Commit
dd6f5e66
authored
Jul 21, 2017
by
Dr.李
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
neutralize difference
parent
f70bab43
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
6 deletions
+24
-6
factoranalysis.py
alphamind/analysis/factoranalysis.py
+24
-6
No files found.
alphamind/analysis/factoranalysis.py
View file @
dd6f5e66
...
@@ -24,7 +24,8 @@ from alphamind.portfolio.meanvariancebuilder import mean_variance_builder
...
@@ -24,7 +24,8 @@ from alphamind.portfolio.meanvariancebuilder import mean_variance_builder
def
factor_processing
(
raw_factors
:
np
.
ndarray
,
def
factor_processing
(
raw_factors
:
np
.
ndarray
,
pre_process
:
Optional
[
List
]
=
None
,
pre_process
:
Optional
[
List
]
=
None
,
risk_factors
:
Optional
[
np
.
ndarray
]
=
None
,
risk_factors
:
Optional
[
np
.
ndarray
]
=
None
,
post_process
:
Optional
[
List
]
=
None
)
->
np
.
ndarray
:
post_process
:
Optional
[
List
]
=
None
,
do_neutralize
:
Optional
[
bool
]
=
True
)
->
np
.
ndarray
:
new_factors
=
raw_factors
new_factors
=
raw_factors
...
@@ -32,7 +33,7 @@ def factor_processing(raw_factors: np.ndarray,
...
@@ -32,7 +33,7 @@ def factor_processing(raw_factors: np.ndarray,
for
p
in
pre_process
:
for
p
in
pre_process
:
new_factors
=
p
(
new_factors
)
new_factors
=
p
(
new_factors
)
if
risk_factors
is
not
None
:
if
risk_factors
is
not
None
and
do_neutralize
:
new_factors
=
neutralize
(
risk_factors
,
new_factors
)
new_factors
=
neutralize
(
risk_factors
,
new_factors
)
if
post_process
:
if
post_process
:
...
@@ -133,17 +134,19 @@ class FDataPack(object):
...
@@ -133,17 +134,19 @@ class FDataPack(object):
'ic'
:
ic_table
.
values
},
'ic'
:
ic_table
.
values
},
index
=
ret_agg
.
index
)
index
=
ret_agg
.
index
)
def
factor_processing
(
self
,
pre_process
,
pos_process
)
->
np
.
ndarray
:
def
factor_processing
(
self
,
pre_process
,
pos_process
,
do_neutralize
)
->
np
.
ndarray
:
if
self
.
risk_exp
is
None
:
if
self
.
risk_exp
is
None
:
return
factor_processing
(
self
.
raw_factors
,
return
factor_processing
(
self
.
raw_factors
,
pre_process
,
pre_process
,
pos_process
)
pos_process
,
do_neutralize
)
else
:
else
:
return
factor_processing
(
self
.
raw_factors
,
return
factor_processing
(
self
.
raw_factors
,
pre_process
,
pre_process
,
self
.
risk_exp
,
self
.
risk_exp
,
pos_process
)
pos_process
,
do_neutralize
)
def
factor_analysis
(
factors
:
pd
.
DataFrame
,
def
factor_analysis
(
factors
:
pd
.
DataFrame
,
...
@@ -156,6 +159,7 @@ def factor_analysis(factors: pd.DataFrame,
...
@@ -156,6 +159,7 @@ def factor_analysis(factors: pd.DataFrame,
is_tradable
:
Optional
[
np
.
ndarray
]
=
None
,
is_tradable
:
Optional
[
np
.
ndarray
]
=
None
,
constraints
:
Optional
[
Constraints
]
=
None
,
constraints
:
Optional
[
Constraints
]
=
None
,
method
=
'risk_neutral'
,
method
=
'risk_neutral'
,
do_neutralize
=
True
,
**
kwargs
)
->
Tuple
[
pd
.
DataFrame
,
Optional
[
pd
.
DataFrame
]]:
**
kwargs
)
->
Tuple
[
pd
.
DataFrame
,
Optional
[
pd
.
DataFrame
]]:
if
risk_exp
is
not
None
:
if
risk_exp
is
not
None
:
...
@@ -167,7 +171,19 @@ def factor_analysis(factors: pd.DataFrame,
...
@@ -167,7 +171,19 @@ def factor_analysis(factors: pd.DataFrame,
risk_exp
=
risk_exp
,
risk_exp
=
risk_exp
,
constraints
=
constraints
)
constraints
=
constraints
)
er
=
data_pack
.
factor_processing
([
winsorize_normal
,
standardize
],
[
standardize
])
@
factor_weights
if
'pre_process'
in
kwargs
:
pre_process
=
kwargs
[
'pre_process'
]
del
kwargs
[
'pre_process'
]
else
:
pre_process
=
[
winsorize_normal
,
standardize
]
if
'post_process'
in
kwargs
:
post_process
=
kwargs
[
'post_process'
]
del
kwargs
[
'post_process'
]
else
:
post_process
=
[
standardize
]
er
=
data_pack
.
factor_processing
(
pre_process
,
post_process
,
do_neutralize
)
@
factor_weights
if
benchmark
is
not
None
and
risk_exp
is
not
None
and
method
==
'risk_neutral'
:
if
benchmark
is
not
None
and
risk_exp
is
not
None
and
method
==
'risk_neutral'
:
# using linear programming portfolio builder
# using linear programming portfolio builder
...
@@ -175,11 +191,13 @@ def factor_analysis(factors: pd.DataFrame,
...
@@ -175,11 +191,13 @@ def factor_analysis(factors: pd.DataFrame,
if
'lbound'
in
kwargs
:
if
'lbound'
in
kwargs
:
lbound
=
kwargs
[
'lbound'
]
lbound
=
kwargs
[
'lbound'
]
del
kwargs
[
'lbound'
]
else
:
else
:
lbound
=
0.
lbound
=
0.
if
'ubound'
in
kwargs
:
if
'ubound'
in
kwargs
:
ubound
=
kwargs
[
'ubound'
]
ubound
=
kwargs
[
'ubound'
]
del
kwargs
[
'ubound'
]
else
:
else
:
ubound
=
0.01
+
benchmark
ubound
=
0.01
+
benchmark
...
...
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