diff options
| -rw-r--r-- | pyisda/credit_index.pyx | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/pyisda/credit_index.pyx b/pyisda/credit_index.pyx index 6885aa9..5d8ee65 100644 --- a/pyisda/credit_index.pyx +++ b/pyisda/credit_index.pyx @@ -1,10 +1,10 @@ #cython: cdivision=True, boundscheck=False, c_string_type=unicode, c_string_encoding=ascii from libc.stdlib cimport malloc, free -from libc.math cimport nan +from libc.math cimport nan, isnan from libc.string cimport memcpy, memset from libcpp.pair cimport pair from libcpp.memory cimport unique_ptr -from cython.operator cimport dereference as deref +from cython.operator cimport dereference as deref, preincrement as preinc from cpython cimport PyObject, Py_INCREF from cython.parallel cimport prange, parallel @@ -617,7 +617,7 @@ cdef double pv(const vector[shared_ptr[TCurve]]& curves, TCurve *tweaked_curve TCurve *orig_curve size_t i = 0 - double recovery_rate + double* recovery_rate if epsilon == 0.: with parallel(): @@ -626,14 +626,18 @@ cdef double pv(const vector[shared_ptr[TCurve]]& curves, for i in prange(curves.size()): tweaked_curve = curves[i].get() - recovery_rate = recovery_rates[i].get()[0] + recovery_rate = recovery_rates[i].get() + # FIXME: do something better + if isnan(deref(recovery_rate)): + preinc(recovery_rate) + JpmcdsContingentLegPV(legs.first, base_date, cash_settle_date, step_in_date, yc, tweaked_curve, - recovery_rate, + deref(recovery_rate), &cl_pv) JpmcdsFeeLegPV(legs.second, base_date, @@ -652,14 +656,18 @@ cdef double pv(const vector[shared_ptr[TCurve]]& curves, for i in prange(curves.size()): orig_curve = curves[i].get() tweak_curve(orig_curve, tweaked_curve, epsilon, mask) - recovery_rate = recovery_rates[i].get()[0] + recovery_rate = recovery_rates[i].get() + # FIXME: do something better + if isnan(deref(recovery_rate)): + preinc(recovery_rate) + JpmcdsContingentLegPV(legs.first, base_date, cash_settle_date, - step_in_date, + step_in_date, yc, tweaked_curve, - recovery_rate, + deref(recovery_rate), &cl_pv) JpmcdsFeeLegPV(legs.second, base_date, |
