diff options
| author | Guillaume Horel <guillaume.horel@gmail.com> | 2017-02-17 16:50:12 -0500 |
|---|---|---|
| committer | Guillaume Horel <guillaume.horel@gmail.com> | 2017-02-17 16:50:12 -0500 |
| commit | 6ad9601730ee5f5584ec2770b5ec2202c464d808 (patch) | |
| tree | aefb259107d31b56e4e00eab8fc7f90adc91f881 | |
| parent | bdd6f0f5b70a75e929ce9365773b849236455f30 (diff) | |
| download | pyisda-6ad9601730ee5f5584ec2770b5ec2202c464d808.tar.gz | |
add convenience methods
| -rw-r--r-- | pyisda/curve.pyx | 25 |
1 files changed, 25 insertions, 0 deletions
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) |
