From 81de457dcd815e739eaa8d36cd2c218aa68b7aa0 Mon Sep 17 00:00:00 2001 From: Guillaume Horel Date: Mon, 19 Mar 2018 18:07:27 -0400 Subject: also accept tenors --- pyisda/curve.pyx | 20 ++++++++++++++++---- 1 file 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 = 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 = 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 = malloc(n_dates * sizeof(TDate)) + tenors_c = 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: -- cgit v1.2.3-70-g09d2