diff options
| author | Guillaume Horel <guillaume.horel@gmail.com> | 2021-11-22 17:54:30 -0500 |
|---|---|---|
| committer | Guillaume Horel <guillaume.horel@gmail.com> | 2021-11-22 17:55:02 -0500 |
| commit | a8c6922c722e2a8104bfffd261040c10f0198169 (patch) | |
| tree | bcc0a8d400c76efd532c2cc23eb171c8f21c2f03 | |
| parent | 7a02344500d91ddea8ea9f03ad72d9669265f032 (diff) | |
| download | pyisda-a8c6922c722e2a8104bfffd261040c10f0198169.tar.gz | |
allow to create curve from zero rates
| -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 |
