diff options
| -rw-r--r-- | pyisda/optim.pyx | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/pyisda/optim.pyx b/pyisda/optim.pyx index 0004996..38867be 100644 --- a/pyisda/optim.pyx +++ b/pyisda/optim.pyx @@ -1,7 +1,7 @@ from libc.stdlib cimport abort from libc.stdlib cimport free, malloc from libc.stdio cimport fprintf, stderr -from libc.math cimport exp, sqrt +from libc.math cimport exp, sqrt, NAN from .cdsone cimport JpmcdsStringToStubMethod, TStubMethod from .curve cimport (TCurve, YieldCurve, JpmcdsFreeTCurve, JpmcdsNewTCurve, CONTINUOUS) @@ -107,7 +107,7 @@ def init_context(YieldCurve yc not None, trade_date, value_date, start_date, @cython.cdivision(True) -cdef api double pv(double Z, void* ctx) nogil: +cdef api double pv(double Z, void* ctx) nogil except NAN: cdef: my_ctx* params_ext = <my_ctx*>ctx cds_bootstrap_ctx* params = ¶ms_ext.params @@ -130,8 +130,8 @@ cdef api double pv(double Z, void* ctx) nogil: 1e-10, # xacc */ 1e-10, # facc */ &h) != 0: - fprintf(stderr, "Failed to find hazard rate for: %f\n", S) - abort() + with gil: + raise ValueError(f"Failed to find hazard rate for: {S}") params.cdsCurve.fArray[0].fRate = h if JpmcdsFeeLegPV(params.fl, params.cdsCurve.fBaseDate, params.stepinDate, params.cashSettleDate, @@ -182,8 +182,7 @@ def expected_pv(double[:] tilt, double[:] w, double S0, object ctx): 1e-10, # xacc */ 1e-10, # facc */ &h) != 0: - fprintf(stderr, "Failed to find hazard rate for: %f\n", S) - abort() + raise ValueError(f"Failed to find hazard rate for: {S}") params.cdsCurve.fArray[0].fRate = h if JpmcdsFeeLegPV(params.fl, params.cdsCurve.fBaseDate, params.stepinDate, params.cashSettleDate, |
