diff options
| author | Guillaume Horel <guillaume.horel@serenitascapital.com> | 2016-06-29 15:41:19 -0400 |
|---|---|---|
| committer | Guillaume Horel <guillaume.horel@serenitascapital.com> | 2016-06-29 15:43:41 -0400 |
| commit | 698e0ddb347fa4b67a9ded9d1b8dbb452d8cffbc (patch) | |
| tree | 770d1131c9751ee91d235df878b47209caa23d79 | |
| parent | fa3c124b5da1b3ef07efeb8c1d279680b514c1ff (diff) | |
| download | pyisda-698e0ddb347fa4b67a9ded9d1b8dbb452d8cffbc.tar.gz | |
add convenience function to convert python dates
| -rw-r--r-- | date.pxd | 2 | ||||
| -rw-r--r-- | date.pyx | 6 | ||||
| -rw-r--r-- | zerocurve.pyx | 17 |
3 files changed, 12 insertions, 13 deletions
@@ -18,3 +18,5 @@ cdef extern from "isda/dateconv.h": cdef extern from "isda/ldate.h": int JpmcdsDateFwdThenAdjust(TDate date, TDateInterval* interval, long badDayMethod, char* holidayFile, TDate *advAdjustedDate) + +cdef TDate pydate_to_TDate(d) diff --git a/date.pyx b/date.pyx new file mode 100644 index 0000000..2852f1b --- /dev/null +++ b/date.pyx @@ -0,0 +1,6 @@ +import datetime +from date cimport JpmcdsDate + +cdef TDate pydate_to_TDate(d): + assert isinstance(d, datetime.date) + return JpmcdsDate(d.year, d.month, d.day) 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 = <TDate*>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) |
