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
248e2c95
Commit
248e2c95
authored
Jul 11, 2017
by
Dr.李
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed bug
parent
35e2da4c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
6 deletions
+13
-6
factoranalysis.py
alphamind/analysis/factoranalysis.py
+13
-6
No files found.
alphamind/analysis/factoranalysis.py
View file @
248e2c95
...
@@ -22,7 +22,8 @@ from alphamind.portfolio.meanvariancebuilder import mean_variance_builder
...
@@ -22,7 +22,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
)
->
np
.
ndarray
:
risk_factors
:
Optional
[
np
.
ndarray
]
=
None
,
post_process
:
Optional
[
List
]
=
None
)
->
np
.
ndarray
:
new_factors
=
raw_factors
new_factors
=
raw_factors
...
@@ -33,7 +34,11 @@ def factor_processing(raw_factors: np.ndarray,
...
@@ -33,7 +34,11 @@ def factor_processing(raw_factors: np.ndarray,
if
risk_factors
is
not
None
:
if
risk_factors
is
not
None
:
new_factors
=
neutralize
(
risk_factors
,
new_factors
)
new_factors
=
neutralize
(
risk_factors
,
new_factors
)
return
standardize
(
new_factors
)
if
post_process
:
for
p
in
pre_process
:
new_factors
=
p
(
new_factors
)
return
new_factors
def
build_portfolio
(
er
:
np
.
ndarray
,
def
build_portfolio
(
er
:
np
.
ndarray
,
...
@@ -133,15 +138,17 @@ class FDataPack(object):
...
@@ -133,15 +138,17 @@ 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
)
->
np
.
ndarray
:
def
factor_processing
(
self
,
pre_process
,
pos_process
)
->
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
)
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
)
def
to_df
(
self
)
->
pd
.
DataFrame
:
def
to_df
(
self
)
->
pd
.
DataFrame
:
cols
=
self
.
factor_names
cols
=
self
.
factor_names
...
@@ -184,7 +191,7 @@ def factor_analysis(factors: pd.DataFrame,
...
@@ -184,7 +191,7 @@ def factor_analysis(factors: pd.DataFrame,
benchmark
=
benchmark
,
benchmark
=
benchmark
,
risk_exp
=
risk_exp
)
risk_exp
=
risk_exp
)
er
=
data_pack
.
factor_processing
([
winsorize_normal
,
standardize
])
@
factor_weights
er
=
data_pack
.
factor_processing
([
winsorize_normal
,
standardize
]
,
[
standardize
]
)
@
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
...
...
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