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
1d36527e
Commit
1d36527e
authored
May 25, 2017
by
Dr.李
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added factor analysis module
parent
8ef605f0
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
88 additions
and
1 deletion
+88
-1
factoranalysis.py
alphamind/analysis/factoranalysis.py
+44
-0
test_factoranalysis.py
alphamind/tests/analysis/test_factoranalysis.py
+41
-0
test_suite.py
alphamind/tests/test_suite.py
+3
-1
No files found.
alphamind/analysis/factoranalysis.py
0 → 100644
View file @
1d36527e
# -*- coding: utf-8 -*-
"""
Created on 2017-5-25
@author: cheng.li
"""
import
numpy
as
np
from
typing
import
Optional
from
typing
import
List
from
alphamind.data.neutralize
import
neutralize
def
factor_processing
(
raw_factor
:
np
.
ndarray
,
pre_process
:
Optional
[
List
]
=
None
,
risk_factors
:
Optional
[
np
.
ndarray
]
=
None
):
new_factor
=
raw_factor
if
pre_process
:
for
p
in
pre_process
:
new_factor
=
p
(
new_factor
)
if
risk_factors
is
not
None
:
new_factor
=
neutralize
(
risk_factors
,
new_factor
)
return
new_factor
if
__name__
==
'__main__'
:
from
alphamind.data.standardize
import
standardize
from
alphamind.data.winsorize
import
winsorize_normal
raw_factor
=
np
.
random
.
randn
(
1000
,
1
)
pre_process
=
[
winsorize_normal
,
standardize
]
risk_factors
=
np
.
ones
((
1000
,
1
))
new_factor
=
factor_processing
(
raw_factor
,
pre_process
,
risk_factors
)
print
(
new_factor
.
sum
())
\ No newline at end of file
alphamind/tests/analysis/test_factoranalysis.py
0 → 100644
View file @
1d36527e
# -*- coding: utf-8 -*-
"""
Created on 2017-5-25
@author: cheng.li
"""
import
unittest
import
numpy
as
np
from
alphamind.data.winsorize
import
winsorize_normal
from
alphamind.data.standardize
import
standardize
from
alphamind.data.neutralize
import
neutralize
from
alphamind.analysis.factoranalysis
import
factor_processing
class
TestFactorAnalysis
(
unittest
.
TestCase
):
def
setUp
(
self
):
self
.
raw_factor
=
np
.
random
.
randn
(
1000
,
1
)
self
.
risk_factor
=
np
.
random
.
randn
(
1000
,
3
)
def
test_factor_processing
(
self
):
new_factor
=
factor_processing
(
self
.
raw_factor
)
np
.
testing
.
assert_array_almost_equal
(
new_factor
,
self
.
raw_factor
)
new_factor
=
factor_processing
(
self
.
raw_factor
,
pre_process
=
[
standardize
,
winsorize_normal
])
np
.
testing
.
assert_array_almost_equal
(
new_factor
,
winsorize_normal
(
standardize
(
self
.
raw_factor
)))
new_factor
=
factor_processing
(
self
.
raw_factor
,
pre_process
=
[
standardize
,
winsorize_normal
],
risk_factors
=
self
.
risk_factor
)
np
.
testing
.
assert_array_almost_equal
(
new_factor
,
neutralize
(
self
.
risk_factor
,
winsorize_normal
(
standardize
(
self
.
raw_factor
))))
if
__name__
==
'__main__'
:
unittest
.
main
()
\ No newline at end of file
alphamind/tests/test_suite.py
View file @
1d36527e
...
...
@@ -21,6 +21,7 @@ from alphamind.tests.portfolio.test_linearbuild import TestLinearBuild
from
alphamind.tests.settlement.test_simplesettle
import
TestSimpleSettle
from
alphamind.tests.analysis.test_riskanalysis
import
TestRiskAnalysis
from
alphamind.tests.analysis.test_perfanalysis
import
TestPerformanceAnalysis
from
alphamind.tests.analysis.test_factoranalysis
import
TestFactorAnalysis
if
__name__
==
'__main__'
:
...
...
@@ -33,6 +34,7 @@ if __name__ == '__main__':
TestLinearBuild
,
TestSimpleSettle
,
TestRiskAnalysis
,
TestPerformanceAnalysis
],
TestPerformanceAnalysis
,
TestFactorAnalysis
],
alpha_logger
)
runner
.
run
()
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