summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuillaume Horel <guillaume.horel@gmail.com>2018-03-19 18:07:27 -0400
committerGuillaume Horel <guillaume.horel@gmail.com>2018-03-19 18:21:34 -0400
commit81de457dcd815e739eaa8d36cd2c218aa68b7aa0 (patch)
tree27f6cf0b467272b82bdb4672873c6d0f468a9fb0
parentdd34b0aa8599933e118a4b6d0efdd347d5541a4a (diff)
downloadpyisda-81de457dcd815e739eaa8d36cd2c218aa68b7aa0.tar.gz
also accept tenors
-rw-r--r--pyisda/curve.pyx20
1 files changed, 16 insertions, 4 deletions
diff --git a/pyisda/curve.pyx b/pyisda/curve.pyx
index 6748f92..d4a34c1 100644
--- a/pyisda/curve.pyx
+++ b/pyisda/curve.pyx
@@ -27,6 +27,7 @@ cdef extern from "numpy/arrayobject.h":
void PyArray_ENABLEFLAGS(np.ndarray arr, int flags)
int PyArray_CheckExact(object)
void* PyArray_DATA(object)
+ int PyArray_TYPE(object)
npy_intp PyArray_Size(object)
cdef int SUCCESS = 0
@@ -573,6 +574,7 @@ cdef class SpreadCurve(Curve):
cdef int n_dates
cdef TDate* end_dates_c = NULL
+ cdef double* tenors_c = NULL
cdef TCurve* curve = NULL
cdef unsigned int includes = 0
cdef size_t i
@@ -593,11 +595,21 @@ cdef class SpreadCurve(Curve):
includes |= 1 << i
i += 1
elif PyArray_CheckExact(end_dates):
- end_dates_c = <TDate*>PyArray_DATA(end_dates)
n_dates = PyArray_Size(end_dates)
- for i in range(n_dates):
- if upfront_rates[i] == upfront_rates[i]:
- includes |= 1 << i
+ if PyArray_TYPE(end_dates) == np.NPY_INT:
+ end_dates_c = <TDate*>PyArray_DATA(end_dates)
+ for i in range(upfront_rates.shape[0]):
+ if upfront_rates[i] == upfront_rates[i]:
+ includes |= 1 << i
+ elif PyArray_TYPE(end_dates) == np.NPY_DOUBLE:
+ end_dates_c = <TDate*>malloc(n_dates * sizeof(TDate))
+ tenors_c = <double*>PyArray_DATA(end_dates)
+ freeup = True
+ for i in range(n_dates):
+ end_dates_c[i] = roll_date(today_c, tenors_c[i])
+ if upfront_rates[i] == upfront_rates[i]:
+ includes |= 1 << i
+
cdef TStubMethod stub_type
if JpmcdsStringToStubMethod(b"f/s", &stub_type) != 0: