From 698e0ddb347fa4b67a9ded9d1b8dbb452d8cffbc Mon Sep 17 00:00:00 2001 From: Guillaume Horel Date: Wed, 29 Jun 2016 15:41:19 -0400 Subject: add convenience function to convert python dates --- zerocurve.pyx | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) (limited to 'zerocurve.pyx') diff --git a/zerocurve.pyx b/zerocurve.pyx index d86c0bd..6760d41 100644 --- a/zerocurve.pyx +++ b/zerocurve.pyx @@ -2,8 +2,8 @@ from cpython cimport datetime from libc.stdlib cimport malloc, free from pyisda.zerocurve cimport JpmcdsBuildIRZeroCurve from pyisda.yearfrac cimport dcc -from pyisda.date cimport (JpmcdsStringToDateInterval, JpmcdsDateIntervalToFreq, - JpmcdsDate, JpmcdsDateFwdThenAdjust) +from pyisda.date cimport (JpmcdsStringToDateInterval, pydate_to_TDate, + JpmcdsDateIntervalToFreq, JpmcdsDateFwdThenAdjust) cdef int SUCCESS = 0 @@ -30,12 +30,7 @@ cdef class ZeroCurve: double float_freq TDateInterval ivl char* routine = 'zerocurve' - TDate value_date - - if isinstance(date, datetime.date): - value_date = JpmcdsDate(date.year, date.month, date.day) - else: - raise ValueError + TDate value_date = pydate_to_TDate(date) self._dates = malloc(len(periods) * sizeof(TDate)) cdef TDateInterval tmp @@ -77,9 +72,5 @@ cdef class ZeroCurve: def discount_factor(self, date): if self._thisptr is NULL: raise ValueError('curve is empty') - cdef TDate discount_date - if isinstance(date, datetime.date): - discount_date = JpmcdsDate(date.year, date.month, date.day) - else: - raise ValueError + cdef TDate discount_date = pydate_to_TDate(date) return JpmcdsZeroPrice(self._thisptr, discount_date) -- cgit v1.2.3-70-g09d2