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
5b7abf91
Commit
5b7abf91
authored
Apr 29, 2017
by
Dr.李
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update rank build tests
parent
5e586da0
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
17 deletions
+24
-17
test_rankbuild.py
alphamind/tests/portfolio/test_rankbuild.py
+24
-17
No files found.
alphamind/tests/portfolio/test_rankbuild.py
View file @
5b7abf91
...
...
@@ -18,17 +18,20 @@ class TestRankBuild(unittest.TestCase):
n_samples
=
3000
n_included
=
300
x
=
np
.
random
.
randn
(
n_samples
,
2
)
n_portfolios
=
range
(
10
)
calc_weights
=
rank_build
(
x
,
n_included
)
for
n_portfolio
in
n_portfolios
:
x
=
np
.
random
.
randn
(
n_samples
,
n_portfolio
)
expected_weights
=
np
.
zeros
((
len
(
x
),
2
))
masks
=
(
-
x
)
.
argsort
(
axis
=
0
)
.
argsort
(
axis
=
0
)
<
n_included
calc_weights
=
rank_build
(
x
,
n_included
)
for
j
in
range
(
x
.
shape
[
1
]):
expected_weights
[
masks
[:,
j
],
j
]
=
1.
/
n_included
expected_weights
=
np
.
zeros
((
len
(
x
),
n_portfolio
))
masks
=
(
-
x
)
.
argsort
(
axis
=
0
)
.
argsort
(
axis
=
0
)
<
n_included
np
.
testing
.
assert_array_almost_equal
(
calc_weights
,
expected_weights
)
for
j
in
range
(
x
.
shape
[
1
]):
expected_weights
[
masks
[:,
j
],
j
]
=
1.
/
n_included
np
.
testing
.
assert_array_almost_equal
(
calc_weights
,
expected_weights
)
def
test_rank_build_with_group
(
self
):
...
...
@@ -36,19 +39,23 @@ class TestRankBuild(unittest.TestCase):
n_include
=
10
n_groups
=
30
x
=
np
.
random
.
randn
(
n_samples
,
2
)
groups
=
np
.
random
.
randint
(
n_groups
,
size
=
n_samples
)
n_portfolios
=
range
(
10
)
for
n_portfolio
in
n_portfolios
:
x
=
np
.
random
.
randn
(
n_samples
,
n_portfolio
)
groups
=
np
.
random
.
randint
(
n_groups
,
size
=
n_samples
)
calc_weights
=
rank_build
(
x
,
n_include
,
groups
)
calc_weights
=
rank_build
(
x
,
n_include
,
groups
)
grouped_ordering
=
pd
.
DataFrame
(
-
x
)
.
groupby
(
groups
)
.
rank
()
expected_weights
=
np
.
zeros
((
len
(
x
),
2
))
masks
=
(
grouped_ordering
<=
n_include
)
.
values
choosed
=
masks
.
sum
(
axis
=
0
)
for
j
in
range
(
x
.
shape
[
1
]):
expected_weights
[
masks
[:,
j
],
j
]
=
1.
/
choosed
[
j
]
grouped_ordering
=
pd
.
DataFrame
(
-
x
)
.
groupby
(
groups
)
.
rank
()
expected_weights
=
np
.
zeros
((
len
(
x
),
n_portfolio
))
masks
=
(
grouped_ordering
<=
n_include
)
.
values
choosed
=
masks
.
sum
(
axis
=
0
)
for
j
in
range
(
x
.
shape
[
1
]):
expected_weights
[
masks
[:,
j
],
j
]
=
1.
/
choosed
[
j
]
np
.
testing
.
assert_array_almost_equal
(
calc_weights
,
expected_weights
)
np
.
testing
.
assert_array_almost_equal
(
calc_weights
,
expected_weights
)
if
__name__
==
'__main__'
:
...
...
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