summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--pyisda/curve.pyx16
1 files changed, 15 insertions, 1 deletions
diff --git a/pyisda/curve.pyx b/pyisda/curve.pyx
index ef11a42..e2e602e 100644
--- a/pyisda/curve.pyx
+++ b/pyisda/curve.pyx
@@ -166,9 +166,22 @@ cdef class YieldCurve(Curve):
)
def __dealloc__(self):
+ ## __dealloc__ of superclass is called by cython so no need to call here
if self._dates is not NULL:
free(self._dates)
+ def __getstate__(self):
+ cdef Py_ssize_t size = sizeof(TRatePt) * self._ninstr
+ cdef bytes dates = (<char*>self._dates)[:size]
+ return super().__getstate__() + (self._ninstr, dates)
+
+ def __setstate__(self, state):
+ super().__setstate__(state[:5])
+ self._ninstr = <int>state[5]
+ cdef Py_ssize_t size = sizeof(TRatePt) * self._ninstr
+ self._dates = <TDate*>malloc(size)
+ memcpy(self._dates, <char*> state[6], size)
+
@classmethod
def from_discount_factors(cls, base_date, list dates, double[:] dfs, str day_count_conv):
""" build a yield curve from a list of discount factors """
@@ -189,7 +202,8 @@ cdef class YieldCurve(Curve):
discount_factor = Curve.__forward_zero_price
- def list_dates(self):
+ @property
+ def dates(self):
""" returns the list of instrument dates
"""