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
3697dcb5
Commit
3697dcb5
authored
May 03, 2017
by
Dr.李
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
change the implementation of groupby
parent
34497c4c
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
10 additions
and
24 deletions
+10
-24
aggregate.py
alphamind/aggregate.py
+8
-0
neutralize.py
alphamind/data/neutralize.py
+1
-1
groupby.pyx
alphamind/groupby.pyx
+0
-22
rankbuilder.py
alphamind/portfolio/rankbuilder.py
+1
-1
No files found.
alphamind/aggregate.py
View file @
3697dcb5
...
@@ -10,6 +10,14 @@ import numpy as np
...
@@ -10,6 +10,14 @@ import numpy as np
import
numba
as
nb
import
numba
as
nb
def
groupby
(
groups
):
a
=
np
.
arange
(
groups
.
shape
[
0
])
order_group_idx
=
groups
.
argsort
()
counts
=
np
.
bincount
(
groups
)
ret
=
np
.
split
(
a
[
order_group_idx
],
np
.
cumsum
(
counts
)[:
-
1
])
return
ret
@
nb
.
njit
(
nogil
=
True
,
cache
=
True
)
@
nb
.
njit
(
nogil
=
True
,
cache
=
True
)
def
simple_sum
(
x
,
axis
=
0
):
def
simple_sum
(
x
,
axis
=
0
):
length
,
width
=
x
.
shape
length
,
width
=
x
.
shape
...
...
alphamind/data/neutralize.py
View file @
3697dcb5
...
@@ -12,7 +12,7 @@ from numpy.linalg import solve
...
@@ -12,7 +12,7 @@ from numpy.linalg import solve
from
typing
import
Tuple
from
typing
import
Tuple
from
typing
import
Union
from
typing
import
Union
from
typing
import
Dict
from
typing
import
Dict
from
alphamind.
groupby
import
groupby
from
alphamind.
aggregate
import
groupby
def
neutralize
(
x
:
np
.
ndarray
,
y
:
np
.
ndarray
,
groups
:
np
.
ndarray
=
None
,
output_explained
=
False
,
output_exposure
=
False
)
\
def
neutralize
(
x
:
np
.
ndarray
,
y
:
np
.
ndarray
,
groups
:
np
.
ndarray
=
None
,
output_explained
=
False
,
output_exposure
=
False
)
\
...
...
alphamind/groupby.pyx
View file @
3697dcb5
...
@@ -9,31 +9,9 @@ Created on 2017-4-26
...
@@ -9,31 +9,9 @@ Created on 2017-4-26
import numpy as np
import numpy as np
from numpy import zeros
from numpy import zeros
cimport numpy as np
cimport numpy as np
from numpy import array
cimport cython
cimport cython
@cython.boundscheck(False)
@cython.wraparound(False)
@cython.initializedcheck(False)
cpdef groupby(long[:] groups):
cdef size_t length = groups.shape[0]
cdef dict group_ids = {}
cdef size_t i
cdef long curr_tag
for i in range(length):
curr_tag = groups[i]
try:
group_ids[curr_tag].append(i)
except KeyError:
group_ids[curr_tag] = [i]
return [array(v) for v in group_ids.values()]
@cython.boundscheck(False)
@cython.boundscheck(False)
@cython.wraparound(False)
@cython.wraparound(False)
@cython.initializedcheck(False)
@cython.initializedcheck(False)
...
...
alphamind/portfolio/rankbuilder.py
View file @
3697dcb5
...
@@ -9,7 +9,7 @@ import numpy as np
...
@@ -9,7 +9,7 @@ import numpy as np
import
numba
as
nb
import
numba
as
nb
from
numpy
import
zeros
from
numpy
import
zeros
from
numpy
import
zeros_like
from
numpy
import
zeros_like
from
alphamind.
groupby
import
groupby
from
alphamind.
aggregate
import
groupby
@
nb
.
njit
(
nogil
=
True
,
cache
=
True
)
@
nb
.
njit
(
nogil
=
True
,
cache
=
True
)
...
...
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