From ed43f3874ccbe7782595b225821230cfca02ceb7 Mon Sep 17 00:00:00 2001 From: Guillaume Horel Date: Tue, 28 Jun 2016 15:59:05 -0400 Subject: cleanups --- Makefile | 4 ++++ convert.pxd | 15 --------------- date.pxd | 25 +++++++++++++++++++++++++ zerocurve.pyx | 21 ++++++++++++++------- 4 files changed, 43 insertions(+), 22 deletions(-) delete mode 100644 convert.pxd create mode 100644 date.pxd diff --git a/Makefile b/Makefile index 1ea9bde..a2b0b14 100644 --- a/Makefile +++ b/Makefile @@ -1,2 +1,6 @@ build: python setup.py build_ext --inplace + +clean: + find -name \*.c -exec rm {} \; + rm -rf build diff --git a/convert.pxd b/convert.pxd deleted file mode 100644 index 0d02c8b..0000000 --- a/convert.pxd +++ /dev/null @@ -1,15 +0,0 @@ -cdef extern from "isda/cdate.h": - ctypedef struct TDateInterval: - pass - -ctypedef long TDate - -cdef extern from "isda/convert.h": - int JpmcdsStringToDateInterval(char* input, char* label, TDateInterval* interval) - int JpmcdsMakeDateInterval(int num_periods, char period_type, TDateInterval* interval) - -cdef extern from "isda/date_sup.h": - int JpmcdsDateIntervalToFreq(TDateInterval* interval, double* freq) - -cdef extern from "isda/dateconv.h": - TDate JpmcdsDate(long year, long month, long day) diff --git a/date.pxd b/date.pxd new file mode 100644 index 0000000..22ea9f6 --- /dev/null +++ b/date.pxd @@ -0,0 +1,25 @@ +cdef extern from "isda/cdate.h": + ctypedef struct TDateInterval: + pass + +ctypedef long TDate + +cdef extern from "isda/convert.h": + int JpmcdsStringToDateInterval(char* input, char* label, TDateInterval* interval) + int JpmcdsMakeDateInterval(int num_periods, char period_type, TDateInterval* interval) + +cdef extern from "isda/date_sup.h": + int JpmcdsDateIntervalToFreq(TDateInterval* interval, double* freq) + +cdef extern from "isda/dateconv.h": + TDate JpmcdsDate(long year, long month, long day) + +cdef extern from "isda/ldate.h": + int JpmcdsDateFwdThenAdjust(TDate date, TDateInterval* interval, long badDayMethod, + char* holidayFile, TDate *advAdjustedDate) + +cdef enum BadDay: + FOLLOW = 'F' + PREVIOUS = 'P' + NONE = 'N' + MODIFIED = 'M' diff --git a/zerocurve.pyx b/zerocurve.pyx index 2918bae..e56a38e 100644 --- a/zerocurve.pyx +++ b/zerocurve.pyx @@ -2,16 +2,17 @@ from cpython cimport datetime from libc.stdlib cimport malloc, free from pyisda.zerocurve cimport JpmcdsBuildIRZeroCurve from pyisda.yearfrac cimport dcc -from pyisda.convert cimport JpmcdsStringToDateInterval, JpmcdsDateIntervalToFreq, JpmcdsDate +from pyisda.date cimport (JpmcdsStringToDateInterval, JpmcdsDateIntervalToFreq, + JpmcdsDate, JpmcdsDateFwdThenAdjust, NONE) cdef int SUCCESS = 0 -cdef class Tcurve: +cdef class ZeroCurve: cdef TCurve* _thisptr cdef TDate* _dates def __cinit__(self, date, str types, - list dates, double[:] rates, + list periods, double[:] rates, str mm_dcc, str fixed_swap_period, str float_swap_period, str fixed_swap_dcc, str float_swap_dcc, char bad_day_conv, char* holidayFile): @@ -28,10 +29,16 @@ cdef class Tcurve: else: raise ValueError - cdef TDate* _dates = malloc(len(dates) * sizeof(TDate)) + cdef TDate* _dates = malloc(len(periods) * sizeof(TDate)) + cdef TDateInterval tmp - for i, d in enumerate(date): - _dates[i] = JpmcdsDate(d.year, d.month, d.day) + for i, p in enumerate(periods): + period_bytes = p.encode('utf-8') + if JpmcdsStringToDateInterval(p, routine, &tmp) != SUCCESS: + raise ValueError + if JpmcdsDateFwdThenAdjust(value_date, &tmp, NONE, + "None", &_dates[i]) != SUCCESS: + raise ValueError('Invalid interval') fixed_bytes = fixed_swap_period.encode('utf-8') float_bytes = float_swap_period.encode('utf-8') @@ -47,7 +54,7 @@ cdef class Tcurve: raise ValueError self._thisptr = JpmcdsBuildIRZeroCurve( value_date, types_bytes, _dates, - &rates[0], len(dates), dcc(mm_dcc), fixed_freq, + &rates[0], len(periods), dcc(mm_dcc), fixed_freq, float_freq, dcc(fixed_swap_dcc), dcc(fixed_swap_dcc), bad_day_conv, "None" ) -- cgit v1.2.3-70-g09d2