From e61c2ea1409c9579f6a2020f382db480f58be538 Mon Sep 17 00:00:00 2001 From: Guillaume Horel Date: Wed, 6 Jul 2016 11:05:46 -0400 Subject: add new constructor --- curve.pxd | 13 +++++++++++++ curve.pyx | 23 ++++++++++++++++++++++- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/curve.pxd b/curve.pxd index bd36e09..831baf7 100644 --- a/curve.pxd +++ b/curve.pxd @@ -77,10 +77,23 @@ cdef extern from "isda/cds.h": cdef extern from "isda/tcurve.h": void JpmcdsFreeTCurve(TCurve* curve) + TCurve* JpmcdsMakeTCurve(TDate baseDate, + TDate *dates, + double *rates, + int numPts, + double basis, + long dayCountConv); cdef extern from "isda/cxzerocurve.h": double JpmcdsZeroPrice(TCurve* curve, TDate date) +cdef enum Basis: + CONTINUOUS = 5000 + DISCOUNT_RATE = 512 + SIMPLE_BASIS = 0 + ANNUAL_BASIS = 1 + DISCOUNT_FACTOR = -2 + cdef class Curve: cdef TCurve* _thisptr diff --git a/curve.pyx b/curve.pyx index c956295..b4b61ad 100644 --- a/curve.pyx +++ b/curve.pyx @@ -1,12 +1,17 @@ from libc.stdlib cimport malloc, free -from curve cimport JpmcdsBuildIRZeroCurve, JpmcdsZeroPrice +from curve cimport (JpmcdsBuildIRZeroCurve, JpmcdsZeroPrice, JpmcdsMakeTCurve, + Basis, CONTINUOUS) from date cimport (JpmcdsStringToDateInterval, pydate_to_TDate, dcc, JpmcdsDateIntervalToFreq, JpmcdsDateFwdThenAdjust, TDate_to_pydate, JpmcdsDateFromBusDaysOffset) from date import dcc_tostring from cdsone cimport JpmcdsStringToStubMethod, TStubMethod + cdef int SUCCESS = 0 +cdef extern from "limits.h": + long LONG_MAX + cpdef public enum BadDay: FOLLOW = 'F' PREVIOUS = 'P' @@ -135,3 +140,19 @@ cdef class SpreadCurve(Curve): &stub_type, 'M', b'NONE') + + @classmethod + def from_flat_hazard(cls, base_date, double rate, Basis basis = CONTINUOUS, + str day_count_conv = 'Actual/365F'): + cdef TDate base_date_c = pydate_to_TDate(base_date) + cdef SpreadCurve sc = cls.__new__(cls) + cdef TDate max_date = LONG_MAX + cdef TDate* dates = malloc(sizeof(TDate)) + + cdef double* rates = malloc(sizeof(double)) + dates[0] = max_date + rates[0] = rate + + sc._thisptr = JpmcdsMakeTCurve(base_date_c, dates, rates, 1, + basis, dcc(day_count_conv)) + return sc -- cgit v1.2.3-70-g09d2