From 6ad9601730ee5f5584ec2770b5ec2202c464d808 Mon Sep 17 00:00:00 2001 From: Guillaume Horel Date: Fri, 17 Feb 2017 16:50:12 -0500 Subject: add convenience methods --- pyisda/curve.pyx | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/pyisda/curve.pyx b/pyisda/curve.pyx index d721666..dd9d66b 100644 --- a/pyisda/curve.pyx +++ b/pyisda/curve.pyx @@ -70,6 +70,31 @@ cdef class Curve(object): 'day_count_convention': dcc_tostring(self._thisptr.fDayCountConv), 'data': fArray_to_list(self._thisptr.fArray, self._thisptr.fNumItems)} + @cython.boundscheck(False) + def to_df(self): + cdef np.npy_intp n = self._thisptr.fNumItems + cdef np.ndarray[np.float64_t,ndim=1] h = np.PyArray_EMPTY(1, &n, np.NPY_DOUBLE, 0) + cdef np.ndarray[np.int64_t,ndim=1] d = np.PyArray_EMPTY(1, &n, np.NPY_INT64, 0) + cdef size_t i + for i in range(self._thisptr.fNumItems): + h[i] = self._thisptr.fArray[i].fRate + d[i] = self._thisptr.fArray[i].fDate + d[i] -= 134774 + return {'hazard_rates': h, 'dates':d.view('M8[D]')} + + def __iter__(self): + cdef: + size_t i + double h + int d + for i in range(self._thisptr.fNumItems): + h = self._thisptr.fArray[i].fRate + d = self._thisptr.fArray[i].fDate + yield TDate_to_pydate(d), h + + def __len__(self): + return self._thisptr.fNumItems + def __deepcopy__(self, memo): cdef Curve sc = type(self).__new__(type(self)) sc._thisptr = JpmcdsCopyCurve(self._thisptr) -- cgit v1.2.3-70-g09d2