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
7e531c66
Commit
7e531c66
authored
Apr 28, 2017
by
Dr.李
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update benchmark
parent
258b0348
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
31 additions
and
27 deletions
+31
-27
benchmarks.py
alphamind/benchmarks/benchmarks.py
+19
-18
neutralize.py
alphamind/benchmarks/data/neutralize.py
+4
-3
neutralize.py
alphamind/data/neutralize.py
+1
-1
rankbuilder.py
alphamind/portfolio/rankbuilder.py
+7
-5
No files found.
alphamind/benchmarks/benchmarks.py
View file @
7e531c66
...
@@ -18,21 +18,22 @@ if __name__ == '__main__':
...
@@ -18,21 +18,22 @@ if __name__ == '__main__':
benchmark_neutralize
(
3000
,
10
,
1000
)
benchmark_neutralize
(
3000
,
10
,
1000
)
benchmark_neutralize
(
30
,
10
,
50000
)
benchmark_neutralize
(
30
,
10
,
50000
)
benchmark_standardize
(
3000
,
10
,
1000
)
benchmark_neutralize
(
50000
,
50
,
20
)
benchmark_standardize_with_group
(
3000
,
10
,
1000
,
30
)
# benchmark_standardize(3000, 10, 1000)
benchmark_standardize
(
30
,
10
,
50000
)
# benchmark_standardize_with_group(3000, 10, 1000, 30)
benchmark_standardize_with_group
(
30
,
10
,
5000
,
5
)
# benchmark_standardize(30, 10, 50000)
benchmark_standardize
(
50000
,
50
,
20
)
# benchmark_standardize_with_group(30, 10, 5000, 5)
benchmark_standardize_with_group
(
50000
,
50
,
20
,
50
)
# benchmark_standardize(50000, 50, 20)
benchmark_winsorize_normal
(
3000
,
10
,
1000
)
# benchmark_standardize_with_group(50000, 50, 20, 50)
benchmark_winsorize_normal_with_group
(
3000
,
10
,
1000
,
30
)
# benchmark_winsorize_normal(3000, 10, 1000)
benchmark_winsorize_normal
(
30
,
10
,
50000
)
# benchmark_winsorize_normal_with_group(3000, 10, 1000, 30)
benchmark_winsorize_normal_with_group
(
30
,
10
,
5000
,
5
)
# benchmark_winsorize_normal(30, 10, 50000)
benchmark_winsorize_normal
(
50000
,
50
,
20
)
# benchmark_winsorize_normal_with_group(30, 10, 5000, 5)
benchmark_winsorize_normal_with_group
(
50000
,
50
,
20
,
50
)
# benchmark_winsorize_normal(50000, 50, 20)
benchmark_build_rank
(
3000
,
1000
,
300
)
# benchmark_winsorize_normal_with_group(50000, 50, 20, 50)
benchmark_build_rank_with_group
(
3000
,
1000
,
10
,
30
)
# benchmark_build_rank(3000, 1000, 300)
benchmark_build_rank
(
30
,
50000
,
3
)
# benchmark_build_rank_with_group(3000, 1000, 10, 30)
benchmark_build_rank_with_group
(
30
,
50000
,
1
,
3
)
# benchmark_build_rank(30, 50000, 3)
benchmark_build_rank
(
50000
,
20
,
3000
)
# benchmark_build_rank_with_group(30, 50000, 1, 3)
benchmark_build_rank_with_group
(
50000
,
20
,
10
,
300
)
# benchmark_build_rank(50000, 20, 3000)
# benchmark_build_rank_with_group(50000, 20, 10, 300)
alphamind/benchmarks/data/neutralize.py
View file @
7e531c66
...
@@ -10,7 +10,7 @@ import datetime as dt
...
@@ -10,7 +10,7 @@ import datetime as dt
import
numpy
as
np
import
numpy
as
np
from
sklearn.linear_model
import
LinearRegression
from
sklearn.linear_model
import
LinearRegression
from
alphamind.data.neutralize
import
ls_fit
from
alphamind.data.neutralize
import
neutralize
def
benchmark_neutralize
(
n_samples
:
int
,
n_features
:
int
,
n_loops
:
int
)
->
None
:
def
benchmark_neutralize
(
n_samples
:
int
,
n_features
:
int
,
n_loops
:
int
)
->
None
:
...
@@ -23,7 +23,7 @@ def benchmark_neutralize(n_samples: int, n_features: int, n_loops: int) -> None:
...
@@ -23,7 +23,7 @@ def benchmark_neutralize(n_samples: int, n_features: int, n_loops: int) -> None:
start
=
dt
.
datetime
.
now
()
start
=
dt
.
datetime
.
now
()
for
_
in
range
(
n_loops
):
for
_
in
range
(
n_loops
):
_
=
ls_fit
(
x
,
y
)
_
=
neutralize
(
x
,
y
)
impl_model_time
=
dt
.
datetime
.
now
()
-
start
impl_model_time
=
dt
.
datetime
.
now
()
-
start
print
(
'{0:20s}: {1}'
.
format
(
'Implemented model'
,
impl_model_time
))
print
(
'{0:20s}: {1}'
.
format
(
'Implemented model'
,
impl_model_time
))
...
@@ -31,7 +31,8 @@ def benchmark_neutralize(n_samples: int, n_features: int, n_loops: int) -> None:
...
@@ -31,7 +31,8 @@ def benchmark_neutralize(n_samples: int, n_features: int, n_loops: int) -> None:
start
=
dt
.
datetime
.
now
()
start
=
dt
.
datetime
.
now
()
for
_
in
range
(
n_loops
):
for
_
in
range
(
n_loops
):
benchmark_model
=
LinearRegression
(
fit_intercept
=
False
)
benchmark_model
=
LinearRegression
(
fit_intercept
=
False
)
_
=
benchmark_model
.
fit
(
x
,
y
)
benchmark_model
.
fit
(
x
,
y
)
_
=
y
-
x
@
benchmark_model
.
coef_
benchmark_model_time
=
dt
.
datetime
.
now
()
-
start
benchmark_model_time
=
dt
.
datetime
.
now
()
-
start
print
(
'{0:20s}: {1}'
.
format
(
'Benchmark model'
,
benchmark_model_time
))
print
(
'{0:20s}: {1}'
.
format
(
'Benchmark model'
,
benchmark_model_time
))
...
...
alphamind/data/neutralize.py
View file @
7e531c66
...
@@ -15,7 +15,7 @@ def neutralize(x: np.ndarray, y: np.ndarray) -> np.ndarray:
...
@@ -15,7 +15,7 @@ def neutralize(x: np.ndarray, y: np.ndarray) -> np.ndarray:
def
ls_fit
(
x
:
np
.
ndarray
,
y
:
np
.
ndarray
)
->
np
.
ndarray
:
def
ls_fit
(
x
:
np
.
ndarray
,
y
:
np
.
ndarray
)
->
np
.
ndarray
:
x_bar
=
np
.
transpose
(
x
)
x_bar
=
x
.
T
b
=
solve
(
x_bar
@
x
,
x_bar
@
y
)
b
=
solve
(
x_bar
@
x
,
x_bar
@
y
)
return
b
return
b
...
...
alphamind/portfolio/rankbuilder.py
View file @
7e531c66
...
@@ -6,15 +6,17 @@ Created on 2017-4-26
...
@@ -6,15 +6,17 @@ Created on 2017-4-26
"""
"""
import
numpy
as
np
import
numpy
as
np
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
:
neg_er
=
-
er
neg_er
=
-
er
masks
=
np
.
zeros
(
len
(
er
),
dtype
=
bool
)
masks
=
zeros
(
len
(
er
),
dtype
=
bool
)
ordering
=
neg_er
.
argsort
()
ordering
=
neg_er
.
argsort
()
if
groups
is
not
None
:
if
groups
is
not
None
:
max_g
=
np
.
max
(
groups
)
max_g
=
max
(
groups
)
index_range
=
np
.
arange
(
len
(
er
))
index_range
=
np
.
arange
(
len
(
er
))
for
i
in
range
(
max_g
+
1
):
for
i
in
range
(
max_g
+
1
):
...
@@ -23,11 +25,10 @@ def rank_build(er: np.ndarray, use_rank: int, groups: np.ndarray=None) -> np.nda
...
@@ -23,11 +25,10 @@ def rank_build(er: np.ndarray, use_rank: int, groups: np.ndarray=None) -> np.nda
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
else
:
else
:
masks
[
ordering
[:
use_rank
]]
=
True
masks
[
ordering
[:
use_rank
]]
=
True
weights
=
np
.
zeros
(
len
(
er
))
weights
=
zeros
(
len
(
er
))
weights
[
masks
]
=
1.
/
np
.
sum
(
masks
)
weights
[
masks
]
=
1.
/
use_rank
return
weights
return
weights
...
@@ -43,3 +44,4 @@ if __name__ == '__main__':
...
@@ -43,3 +44,4 @@ if __name__ == '__main__':
for
i
in
range
(
10000
):
for
i
in
range
(
10000
):
weights
=
rank_build
(
x
,
30
,
groups
)
weights
=
rank_build
(
x
,
30
,
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