diff options
| -rw-r--r-- | pyisda/curve.pxd | 2 | ||||
| -rw-r--r-- | pyisda/curve.pyx | 18 |
2 files changed, 19 insertions, 1 deletions
diff --git a/pyisda/curve.pxd b/pyisda/curve.pxd index a91a290..937a8f5 100644 --- a/pyisda/curve.pxd +++ b/pyisda/curve.pxd @@ -192,7 +192,7 @@ cdef extern from "isda/cfinanci.h" nogil: cdef extern from "isda/macros.h" nogil: cdef double JPMCDS_MAX_RATE -cdef enum Basis: +cpdef enum Basis: CONTINUOUS = 5000 DISCOUNT_RATE = 512 SIMPLE_BASIS = 0 diff --git a/pyisda/curve.pyx b/pyisda/curve.pyx index 7fff52b..91b8c48 100644 --- a/pyisda/curve.pyx +++ b/pyisda/curve.pyx @@ -208,6 +208,10 @@ cdef class Curve(object): def base_date(self): return TDate_to_pydate(get_TCurve(self).fBaseDate) + @property + def basis(self): + return <Basis>get_TCurve(self).fBasis + def __forward_zero_price(self, d2, d1=None): """ computes the forward zero price at a given date. @@ -465,6 +469,20 @@ cdef class YieldCurve(Curve): <double>basis, dcc(day_count_conv)), JpmcdsFreeTCurve) return yc + @classmethod + def from_zero_rates(cls, base_date, list dates, double[:] rates, str day_count_conv, Basis basis=CONTINUOUS): + """ build a yield curve from a list of discount factors """ + cdef TDate base_date_c = pydate_to_TDate(base_date) + cdef YieldCurve yc = YieldCurve.__new__(YieldCurve) + yc.dates = vector[TDate](len(dates)) + cdef size_t i + for i, d in enumerate(dates): + yc.dates[i] = pydate_to_TDate(d) + yc._thisptr.reset( + JpmcdsMakeTCurve(base_date_c, yc.dates.data(), &rates[0], rates.shape[0], + <double>basis, dcc(day_count_conv)), JpmcdsFreeTCurve) + return yc + discount_factor = Curve.__forward_zero_price @property |
