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
decdb3b1
Commit
decdb3b1
authored
May 26, 2017
by
Dr.李
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed tests
parent
1112f970
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
29 deletions
+12
-29
factoranalysis.py
alphamind/analysis/factoranalysis.py
+7
-28
test_factoranalysis.py
alphamind/tests/analysis/test_factoranalysis.py
+5
-1
No files found.
alphamind/analysis/factoranalysis.py
View file @
decdb3b1
...
@@ -67,7 +67,7 @@ class FDataPack(object):
...
@@ -67,7 +67,7 @@ class FDataPack(object):
risk_exp
:
Optional
[
np
.
ndarray
]
=
None
,
risk_exp
:
Optional
[
np
.
ndarray
]
=
None
,
risk_names
:
List
[
str
]
=
None
):
risk_names
:
List
[
str
]
=
None
):
self
.
raw_factor
=
raw_factor
self
.
raw_factor
=
raw_factor
.
reshape
((
-
1
,
1
))
self
.
d1returns
=
d1returns
.
flatten
()
self
.
d1returns
=
d1returns
.
flatten
()
if
factor_name
:
if
factor_name
:
self
.
factor_name
=
factor_name
self
.
factor_name
=
factor_name
...
@@ -145,14 +145,14 @@ class FDataPack(object):
...
@@ -145,14 +145,14 @@ class FDataPack(object):
index
=
self
.
codes
)
index
=
self
.
codes
)
def
factor_analysis
(
factor
_valu
es
,
def
factor_analysis
(
factor
s
:
pd
.
Seri
es
,
industry
,
industry
:
np
.
ndarray
,
d1returns
,
d1returns
:
np
.
ndarray
,
detail_analysis
=
True
,
detail_analysis
=
True
,
benchmark
:
Optional
[
np
.
ndarray
]
=
None
,
benchmark
:
Optional
[
np
.
ndarray
]
=
None
,
risk_exp
:
Optional
[
np
.
ndarray
]
=
None
)
->
Tuple
[
np
.
ndarray
,
Optional
[
pd
.
DataFrame
]]:
risk_exp
:
Optional
[
np
.
ndarray
]
=
None
)
->
Tuple
[
pd
.
Series
,
Optional
[
pd
.
DataFrame
]]:
data_pack
=
FDataPack
(
raw_factor
=
factor
_
values
,
data_pack
=
FDataPack
(
raw_factor
=
factor
s
.
values
,
d1returns
=
d1returns
,
d1returns
=
d1returns
,
groups
=
industry
,
groups
=
industry
,
benchmark
=
benchmark
,
benchmark
=
benchmark
,
...
@@ -187,28 +187,7 @@ def factor_analysis(factor_values,
...
@@ -187,28 +187,7 @@ def factor_analysis(factor_values,
analysis
=
data_pack
.
settle
(
weights
)
analysis
=
data_pack
.
settle
(
weights
)
else
:
else
:
analysis
=
None
analysis
=
None
return
weights
,
analysis
return
pd
.
Series
(
weights
,
index
=
factors
.
index
),
analysis
if
__name__
==
'__main__'
:
raw_factor
=
np
.
random
.
randn
(
1000
,
1
)
d1returns
=
np
.
random
.
randn
(
1000
,
1
)
groups
=
np
.
random
.
randint
(
30
,
size
=
1000
)
benchmark
=
np
.
random
.
randn
(
1000
,
1
)
risk_exp
=
np
.
random
.
randn
(
1000
,
3
)
codes
=
list
(
range
(
1
,
1001
))
data_pack
=
FDataPack
(
raw_factor
,
d1returns
,
'cfinc1'
,
codes
=
codes
,
groups
=
groups
,
benchmark
=
benchmark
,
risk_exp
=
risk_exp
,
risk_names
=
[
'market'
,
'size'
,
'growth'
])
weights
=
np
.
random
.
randn
(
1000
)
print
(
data_pack
.
settle
(
weights
))
alphamind/tests/analysis/test_factoranalysis.py
View file @
decdb3b1
...
@@ -8,6 +8,7 @@ Created on 2017-5-25
...
@@ -8,6 +8,7 @@ Created on 2017-5-25
import
unittest
import
unittest
import
numpy
as
np
import
numpy
as
np
import
pandas
as
pd
from
alphamind.data.winsorize
import
winsorize_normal
from
alphamind.data.winsorize
import
winsorize_normal
from
alphamind.data.standardize
import
standardize
from
alphamind.data.standardize
import
standardize
from
alphamind.data.neutralize
import
neutralize
from
alphamind.data.neutralize
import
neutralize
...
@@ -42,7 +43,10 @@ class TestFactorAnalysis(unittest.TestCase):
...
@@ -42,7 +43,10 @@ class TestFactorAnalysis(unittest.TestCase):
benchmark
=
np
.
random
.
randint
(
50
,
size
=
1000
)
benchmark
=
np
.
random
.
randint
(
50
,
size
=
1000
)
benchmark
=
benchmark
/
benchmark
.
sum
()
benchmark
=
benchmark
/
benchmark
.
sum
()
industry
=
np
.
random
.
randint
(
30
,
size
=
1000
)
industry
=
np
.
random
.
randint
(
30
,
size
=
1000
)
weight
,
analysis_table
=
factor_analysis
(
self
.
raw_factor
,
factor_series
=
pd
.
Series
(
self
.
raw_factor
.
flatten
(),
index
=
range
(
len
(
self
.
raw_factor
)))
weight
,
analysis_table
=
factor_analysis
(
factor_series
,
d1returns
=
self
.
d1returns
,
d1returns
=
self
.
d1returns
,
industry
=
industry
,
industry
=
industry
,
benchmark
=
benchmark
,
benchmark
=
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