diff options
| author | Guillaume Horel <guillaume.horel@gmail.com> | 2018-03-16 16:59:44 -0400 |
|---|---|---|
| committer | Guillaume Horel <guillaume.horel@gmail.com> | 2018-03-19 09:50:35 -0400 |
| commit | a1554f98515d506e5b494b4d849b91306744163e (patch) | |
| tree | 7a4a6073f58809c138b4f5f2fa52ef3e33425c18 | |
| parent | 11fee1a22129b1ff09d9787f1ede7fdbf0357011 (diff) | |
| download | pyisda-a1554f98515d506e5b494b4d849b91306744163e.tar.gz | |
Fix previous_twentieth
| -rw-r--r-- | pyisda/curve.pyx | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/pyisda/curve.pyx b/pyisda/curve.pyx index c966d03..7fbc151 100644 --- a/pyisda/curve.pyx +++ b/pyisda/curve.pyx @@ -2,7 +2,7 @@ from libc.math cimport log1p, log from date cimport (JpmcdsStringToDateInterval, pydate_to_TDate, dcc, TMonthDayYear, JpmcdsDateIntervalToFreq, JpmcdsDateFwdThenAdjust, TDate_to_pydate, JpmcdsDateFromBusDaysOffset, JpmcdsStringToDayCountConv, ACT_360, - JpmcdsDateToMDY, JpmcdsMDYToDate) + JpmcdsDateToMDY, JpmcdsMDYToDate, JpmcdsFormatDate) from date import dcc_tostring from cdsone cimport JpmcdsStringToStubMethod, TStubMethod from legs cimport (JpmcdsCdsContingentLegMake, JpmcdsCdsFeeLegMake, @@ -42,19 +42,26 @@ cdef inline void double_free(double* ptr) nogil: cdef TDate previous_twentieth(TDate d) nogil: cdef TMonthDayYear mdy - JpmcdsDateToMDY(d, &mdy) + if JpmcdsDateToMDY(d, &mdy) != SUCCESS: + return -1 if mdy.day < 20: - mdy.month = 12 if mdy.month == 1 else mdy.month - 1 + if mdy.month == 1: + mdy.month = 12 + mdy.year -= 1 + else: + mdy.month -= 1 mdy.day = 20 cdef int mod = mdy.month % 3 if mod != 0: mdy.month -= mod - if mdy.month < 0: + if mdy.month <= 0: mdy.month += 12 mdy.year -= 1 cdef TDate r - JpmcdsMDYToDate(&mdy, &r) - return r + if JpmcdsMDYToDate(&mdy, &r) != SUCCESS: + return -1 + else: + return r cdef class Curve(object): @@ -489,6 +496,8 @@ cdef class SpreadCurve(Curve): if start_date is None: start_date_c = previous_twentieth(today_c) + if start_date_c == -1: + raise ValueError("incorrect today's date: " + today) else: start_date_c = pydate_to_TDate(start_date) if step_in_date is None: |
