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
70214fe0
Commit
70214fe0
authored
Apr 30, 2017
by
Dr.李
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
enhance performance
parent
106e3b19
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
9 additions
and
4 deletions
+9
-4
aggregate.pyx
alphamind/aggregate.pyx
+8
-3
simplesettle.py
alphamind/benchmarks/settlement/simplesettle.py
+1
-1
No files found.
alphamind/aggregate.pyx
View file @
70214fe0
# -*- coding: utf-8 -*-
# distutils: language = c++
"""
Created on 2017-4-26
...
...
@@ -16,6 +17,8 @@ from numpy import array
from cpython.dict cimport PyDict_GetItem, PyDict_SetItem
from cpython.ref cimport PyObject
from cpython.list cimport PyList_Append
from libcpp.unordered_map cimport unordered_map as cpp_map
from cython.operator cimport dereference as deref
np.import_array()
...
...
@@ -54,19 +57,21 @@ cpdef list groupby(long[:] groups):
@cython.initializedcheck(False)
cdef long* group_mapping(long* groups, size_t length, size_t* max_g):
cdef long *res_ptr = <long*>calloc(length, sizeof(int))
cdef
dict current_hold = {}
cdef
cpp_map[long, long] current_hold
cdef long curr_g
cdef long running_g = -1
cdef size_t i = 0
cdef cpp_map[long, long].iterator it
for i in range(length):
curr_g = groups[i]
if curr_g not in current_hold:
it = current_hold.find(curr_g)
if it == current_hold.end():
running_g += 1
res_ptr[i] = running_g
current_hold[curr_g] = running_g
else:
res_ptr[i] =
current_hold[curr_g]
res_ptr[i] =
deref(it).second
max_g[0] = running_g
return res_ptr
...
...
alphamind/benchmarks/settlement/simplesettle.py
View file @
70214fe0
...
...
@@ -57,7 +57,7 @@ def benchmark_simple_settle_with_group(n_samples: int, n_portfolios: int, n_loop
ret_series
.
shape
=
-
1
,
1
for
_
in
range
(
n_loops
):
ret_mat
=
weights
*
ret_series
exp_ret
=
pd
.
DataFrame
(
ret_mat
)
.
groupby
(
groups
)
.
sum
()
.
values
exp_ret
=
pd
.
DataFrame
(
ret_mat
)
.
groupby
(
groups
,
sort
=
False
)
.
sum
()
.
values
benchmark_model_time
=
dt
.
datetime
.
now
()
-
start
np
.
testing
.
assert_array_almost_equal
(
calc_ret
,
exp_ret
)
...
...
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