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
66b2fbf2
Commit
66b2fbf2
authored
Apr 28, 2017
by
Dr.李
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
further enhance
parent
7e531c66
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
22 deletions
+21
-22
benchmarks.py
alphamind/benchmarks/benchmarks.py
+9
-9
rankbuilder.py
alphamind/portfolio/rankbuilder.py
+12
-13
No files found.
alphamind/benchmarks/benchmarks.py
View file @
66b2fbf2
...
@@ -16,9 +16,9 @@ from alphamind.benchmarks.portfolio.rankbuild import benchmark_build_rank_with_g
...
@@ -16,9 +16,9 @@ from alphamind.benchmarks.portfolio.rankbuild import benchmark_build_rank_with_g
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
benchmark_neutralize
(
3000
,
10
,
1000
)
#
benchmark_neutralize(3000, 10, 1000)
benchmark_neutralize
(
30
,
10
,
50000
)
#
benchmark_neutralize(30, 10, 50000)
benchmark_neutralize
(
50000
,
50
,
20
)
#
benchmark_neutralize(50000, 50, 20)
# benchmark_standardize(3000, 10, 1000)
# benchmark_standardize(3000, 10, 1000)
# benchmark_standardize_with_group(3000, 10, 1000, 30)
# benchmark_standardize_with_group(3000, 10, 1000, 30)
# benchmark_standardize(30, 10, 50000)
# benchmark_standardize(30, 10, 50000)
...
@@ -31,9 +31,9 @@ if __name__ == '__main__':
...
@@ -31,9 +31,9 @@ if __name__ == '__main__':
# benchmark_winsorize_normal_with_group(30, 10, 5000, 5)
# benchmark_winsorize_normal_with_group(30, 10, 5000, 5)
# benchmark_winsorize_normal(50000, 50, 20)
# benchmark_winsorize_normal(50000, 50, 20)
# benchmark_winsorize_normal_with_group(50000, 50, 20, 50)
# benchmark_winsorize_normal_with_group(50000, 50, 20, 50)
#
benchmark_build_rank(3000, 1000, 300)
benchmark_build_rank
(
3000
,
1000
,
300
)
#
benchmark_build_rank_with_group(3000, 1000, 10, 30)
benchmark_build_rank_with_group
(
3000
,
1000
,
10
,
30
)
#
benchmark_build_rank(30, 50000, 3)
benchmark_build_rank
(
30
,
50000
,
3
)
#
benchmark_build_rank_with_group(30, 50000, 1, 3)
benchmark_build_rank_with_group
(
30
,
50000
,
1
,
3
)
#
benchmark_build_rank(50000, 20, 3000)
benchmark_build_rank
(
50000
,
20
,
3000
)
#
benchmark_build_rank_with_group(50000, 20, 10, 300)
benchmark_build_rank_with_group
(
50000
,
20
,
10
,
300
)
alphamind/portfolio/rankbuilder.py
View file @
66b2fbf2
...
@@ -7,28 +7,27 @@ Created on 2017-4-26
...
@@ -7,28 +7,27 @@ Created on 2017-4-26
import
numpy
as
np
import
numpy
as
np
from
numpy
import
zeros
from
numpy
import
zeros
from
numpy
import
max
def
rank_build
(
er
:
np
.
ndarray
,
use_rank
:
int
,
groups
:
np
.
ndarray
=
None
)
->
np
.
ndarray
:
def
rank_build
(
er
:
np
.
ndarray
,
use_rank
:
int
,
groups
:
np
.
ndarray
=
None
)
->
np
.
ndarray
:
length
=
len
(
er
)
neg_er
=
-
er
neg_er
=
-
er
masks
=
zeros
(
len
(
er
)
,
dtype
=
bool
)
masks
=
zeros
(
len
gth
,
dtype
=
bool
)
ordering
=
neg_er
.
argsort
(
)
weights
=
zeros
(
length
)
if
groups
is
not
None
:
if
groups
is
not
None
:
max_g
=
max
(
groups
)
max_g
=
groups
.
max
()
index_range
=
np
.
arange
(
len
(
er
))
index_range
=
np
.
arange
(
length
)
for
i
in
range
(
max_g
+
1
):
for
i
in
range
(
max_g
+
1
):
current_mask
=
groups
==
i
current_mask
=
groups
==
i
current_index
=
index_range
[
current_mask
]
current_index
=
index_range
[
current_mask
]
current_ordering
=
neg_er
[
current_mask
]
.
argsort
()
current_ordering
=
neg_er
[
current_mask
]
.
argsort
()
masks
[
current_index
[
current_ordering
[:
use_rank
]]]
=
True
masks
[
current_index
[
current_ordering
[:
use_rank
]]]
=
True
weights
[
masks
]
=
1.
/
masks
.
sum
()
else
:
else
:
ordering
=
neg_er
.
argsort
()
masks
[
ordering
[:
use_rank
]]
=
True
masks
[
ordering
[:
use_rank
]]
=
True
weights
[
masks
]
=
1.
/
use_rank
weights
=
zeros
(
len
(
er
))
weights
[
masks
]
=
1.
/
use_rank
return
weights
return
weights
...
@@ -36,12 +35,12 @@ if __name__ == '__main__':
...
@@ -36,12 +35,12 @@ if __name__ == '__main__':
import
datetime
as
dt
import
datetime
as
dt
x
=
np
.
random
.
randn
(
3000
)
x
=
np
.
random
.
randn
(
4
)
groups
=
np
.
random
.
randint
(
30
,
size
=
3000
)
groups
=
np
.
random
.
randint
(
2
,
size
=
4
)
start
=
dt
.
datetime
.
now
()
start
=
dt
.
datetime
.
now
()
for
i
in
range
(
10000
):
for
i
in
range
(
10000
):
weights
=
rank_build
(
x
,
30
,
groups
)
weights
=
rank_build
(
x
,
1
,
groups
)
print
(
dt
.
datetime
.
now
()
-
start
)
print
(
dt
.
datetime
.
now
()
-
start
)
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