summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--pyisda/curve.pyx25
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)