summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuillaume Horel <guillaume.horel@gmail.com>2018-03-16 16:10:00 -0400
committerGuillaume Horel <guillaume.horel@gmail.com>2018-03-16 16:27:51 -0400
commit11fee1a22129b1ff09d9787f1ede7fdbf0357011 (patch)
tree7378d5d208f275c5b0554ac40647f09ed1b694c0
parent628c310ef3b921efe8ad9eb47fc9d026e4a6f620 (diff)
downloadpyisda-11fee1a22129b1ff09d9787f1ede7fdbf0357011.tar.gz
allow to pass None for start_date, step_in_date and cash_settle_date
-rw-r--r--pyisda/curve.pxd2
-rw-r--r--pyisda/curve.pyx43
-rw-r--r--pyisda/date.pxd1
3 files changed, 39 insertions, 7 deletions
diff --git a/pyisda/curve.pxd b/pyisda/curve.pxd
index 8d62d65..3f5c744 100644
--- a/pyisda/curve.pxd
+++ b/pyisda/curve.pxd
@@ -96,7 +96,7 @@ cdef extern from "isda/cds.h" nogil:
TDate startDate,
# Step in date of the benchmark CDS
TDate stepinDate,
- # Date when payment should be make
+ # Date when payment should be made
TDate cashSettleDate,
# Number of benchmark dates
long nbDate,
diff --git a/pyisda/curve.pyx b/pyisda/curve.pyx
index b839ee9..c966d03 100644
--- a/pyisda/curve.pyx
+++ b/pyisda/curve.pyx
@@ -1,7 +1,8 @@
from libc.math cimport log1p, log
-from date cimport (JpmcdsStringToDateInterval, pydate_to_TDate, dcc,
+from date cimport (JpmcdsStringToDateInterval, pydate_to_TDate, dcc, TMonthDayYear,
JpmcdsDateIntervalToFreq, JpmcdsDateFwdThenAdjust, TDate_to_pydate,
- JpmcdsDateFromBusDaysOffset, JpmcdsStringToDayCountConv, ACT_360)
+ JpmcdsDateFromBusDaysOffset, JpmcdsStringToDayCountConv, ACT_360,
+ JpmcdsDateToMDY, JpmcdsMDYToDate)
from date import dcc_tostring
from cdsone cimport JpmcdsStringToStubMethod, TStubMethod
from legs cimport (JpmcdsCdsContingentLegMake, JpmcdsCdsFeeLegMake,
@@ -39,6 +40,22 @@ cdef inline shared_ptr[TCurve] make_shared(TCurve* ptr) nogil:
cdef inline void double_free(double* ptr) nogil:
free(ptr)
+cdef TDate previous_twentieth(TDate d) nogil:
+ cdef TMonthDayYear mdy
+ JpmcdsDateToMDY(d, &mdy)
+ if mdy.day < 20:
+ mdy.month = 12 if mdy.month == 1 else mdy.month - 1
+ mdy.day = 20
+ cdef int mod = mdy.month % 3
+ if mod != 0:
+ mdy.month -= mod
+ if mdy.month < 0:
+ mdy.month += 12
+ mdy.year -= 1
+ cdef TDate r
+ JpmcdsMDYToDate(&mdy, &r)
+ return r
+
cdef class Curve(object):
def __getstate__(self):
@@ -466,9 +483,23 @@ cdef class SpreadCurve(Curve):
str ticker=None):
cdef TDate today_c = pydate_to_TDate(today)
- cdef TDate step_in_date_c = pydate_to_TDate(step_in_date)
- cdef TDate cash_settle_date_c = pydate_to_TDate(cash_settle_date)
- cdef TDate start_date_c = pydate_to_TDate(start_date)
+ cdef TDate step_in_date_c
+ cdef TDate cash_settle_date_c
+ cdef TDate start_date_c
+
+ if start_date is None:
+ start_date_c = previous_twentieth(today_c)
+ else:
+ start_date_c = pydate_to_TDate(start_date)
+ if step_in_date is None:
+ step_in_date_c = today_c + 1
+ else:
+ step_in_date_c = pydate_to_TDate(step_in_date)
+ if cash_settle_date is None:
+ JpmcdsDateFromBusDaysOffset(today_c, 3, "None", &cash_settle_date_c)
+ else:
+ cash_settle_date_c = pydate_to_TDate(cash_settle_date)
+
cdef int n_dates
cdef TDate* end_dates_c = NULL
cdef TCurve* curve = NULL
@@ -520,7 +551,7 @@ cdef class SpreadCurve(Curve):
b'NONE')
if freeup:
free(end_dates_c)
- if curve == NULL:
+ if curve is NULL:
raise ValueError("Didn't init the survival curve properly")
else:
self._thisptr = make_shared(curve)
diff --git a/pyisda/date.pxd b/pyisda/date.pxd
index dda35d0..56d1e45 100644
--- a/pyisda/date.pxd
+++ b/pyisda/date.pxd
@@ -29,6 +29,7 @@ cdef extern from "isda/date_sup.h" nogil:
cdef extern from "isda/dateconv.h" nogil:
TDate JpmcdsDate(long year, long month, long day)
int JpmcdsDateToMDY(TDate date, TMonthDayYear *mdyDate)
+ int JpmcdsMDYToDate(TMonthDayYear*, TDate*)
cdef extern from "isda/ldate.h" nogil:
int JpmcdsDateFwdThenAdjust(TDate date, TDateInterval* interval, long badDayMethod,