From d6268113ac807e7f137b54aed71f07486645c3fb Mon Sep 17 00:00:00 2001 From: Guillaume Horel Date: Thu, 16 Nov 2017 14:55:44 -0500 Subject: return numpy array --- pyisda/credit_index.pxd | 2 +- pyisda/credit_index.pyx | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/pyisda/credit_index.pxd b/pyisda/credit_index.pxd index f3e61b8..005d166 100644 --- a/pyisda/credit_index.pxd +++ b/pyisda/credit_index.pxd @@ -7,7 +7,7 @@ from libcpp.string cimport string cdef class CurveList: cdef TDate base_date - cdef public vector[double] weights + cdef vector[double] weights cdef vector[double] T cdef vector[shared_ptr[TCurve]] curves cdef unordered_map[string, size_t] tickers diff --git a/pyisda/credit_index.pyx b/pyisda/credit_index.pyx index 663d6ed..bc3ee8f 100644 --- a/pyisda/credit_index.pyx +++ b/pyisda/credit_index.pyx @@ -83,6 +83,13 @@ cdef class CurveList: sc.ticker = p.first yield (sc.ticker.decode(), self.weights[p.second], sc) + @property + def weights(self): + cdef np.npy_intp shape = self.weights.size() + cdef np.ndarray[np.float64_t] out = \ + np.PyArray_SimpleNewFromData(1, &shape, np.NPY_DOUBLE, self.weights.data()) + return out + @property def curves(self): """returns the list of curves inside the porfolio. -- cgit v1.2.3-70-g09d2