summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuillaume Horel <guillaume.horel@gmail.com>2023-06-09 16:11:49 -0400
committerGuillaume Horel <guillaume.horel@gmail.com>2023-06-09 16:11:49 -0400
commitbe2496b941a9af64dcdccb80f553c1694da89eb6 (patch)
tree348b65d3df01797f127563d4c5f9465ef7dfca36
parente0340354c0597e4ca97545b093510b833d6af5f1 (diff)
downloadpyisda-be2496b941a9af64dcdccb80f553c1694da89eb6.tar.gz
speedups
-rw-r--r--pyisda/credit_index.pyx27
1 files changed, 21 insertions, 6 deletions
diff --git a/pyisda/credit_index.pyx b/pyisda/credit_index.pyx
index b545858..509b0de 100644
--- a/pyisda/credit_index.pyx
+++ b/pyisda/credit_index.pyx
@@ -5,7 +5,7 @@ from libc.string cimport memcpy, memset, strcpy
from libcpp.pair cimport pair
from libcpp.memory cimport make_shared
from cython.operator cimport dereference as deref, preincrement as preinc
-from cpython cimport PyObject, Py_INCREF
+from cpython.unicode cimport PyUnicode_FromStringAndSize
from cython.parallel cimport prange, parallel
cimport cython
@@ -154,11 +154,12 @@ cdef class CurveList:
yield ((sc.ticker, sc.seniority, sc.doc_clause), self._weights[p.second], sc)
@property
+ @cython.wraparound(False)
def weights(self):
cdef:
np.npy_intp shape = self._weights.size()
pair[CurveName, size_t] p
- np.ndarray out = np.PyArray_EMPTY(1, &shape, np.NPY_DOUBLE, 1)
+ np.ndarray[np.float64_t, ndim=1] out = np.PyArray_EMPTY(1, &shape, np.NPY_DOUBLE, 1)
int j = 0
for p in self.names:
out[j] = self._weights[p.second]
@@ -171,20 +172,34 @@ cdef class CurveList:
raise ValueError("size mismatch")
cdef size_t i
- for i in range(self.weights.size()):
- self.weights[i] = val[i]
+ for i in range(self._weights.size()):
+ self._weights[i] = val[i]
+ @property
+ @cython.wraparound(False)
+ def recovery_rates(self):
+ cdef:
+ np.npy_intp shape = self._weights.size()
+ pair[CurveName, size_t] p
+ np.ndarray[np.float64_t, ndim=1] out = np.PyArray_EMPTY(1, &shape, np.NPY_DOUBLE, 1)
+ int j = 0
+
+ for p in self.names:
+ out[j] = (<double*>(self._curves[p.second].get() + self.offset_recovery_rates[p.second]))[0]
+ j += 1
+ return out
@property
+ @cython.wraparound(False)
def tickers(self):
cdef:
np.npy_intp shape = self.names.size()
pair[CurveName, size_t] p
- np.ndarray out = np.PyArray_EMPTY(1, &shape, np.NPY_OBJECT, 1)
+ np.ndarray[object, ndim=1] out = np.PyArray_EMPTY(1, &shape, np.NPY_OBJECT, 1)
int j = 0
for p in self.names:
- out[j] = string(p.first.ticker.begin(), p.first.ticker.end())
+ out[j] = PyUnicode_FromStringAndSize(p.first.ticker.data(), p.first.ticker.size())
j += 1
return out