diff options
| author | Guillaume Horel <guillaume.horel@gmail.com> | 2019-02-22 12:53:11 -0500 |
|---|---|---|
| committer | Guillaume Horel <guillaume.horel@gmail.com> | 2019-02-22 14:38:29 -0500 |
| commit | a0e798113024114c3002e3eee1e09ae194dbf3f4 (patch) | |
| tree | fa15facd8f40b6f4e29792173ef0da6b75ae851d | |
| parent | 4379b928e38fa77942bfc6e140d4a10444e12234 (diff) | |
| download | pyisda-a0e798113024114c3002e3eee1e09ae194dbf3f4.tar.gz | |
initialize variable
| -rw-r--r-- | pyisda/credit_index.pyx | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/pyisda/credit_index.pyx b/pyisda/credit_index.pyx index 75c1270..76c77a1 100644 --- a/pyisda/credit_index.pyx +++ b/pyisda/credit_index.pyx @@ -12,7 +12,8 @@ from . cimport _curve cimport cython from .legs cimport (JpmcdsCdsContingentLegMake, JpmcdsCdsFeeLegMake, JpmcdsContingentLegPV, JpmcdsFeeLegPV, FeeLegAI, JpmcdsFeeLegFree) -from .curve cimport (SpreadCurve, YieldCurve, Hash64WithSeed, Hash64, uint64_t) +from .curve cimport (SpreadCurve, YieldCurve, Hash64WithSeed, Hash64, uint64_t, + JpmcdsCopyCurve) from ._curve cimport TCurve, TRatePt from .date cimport (pydate_to_TDate, TDate_to_pydate, ACT_365F, JpmcdsDtFwdAny, TDateInterval, JpmcdsMakeDateInterval) @@ -607,7 +608,7 @@ cdef double pv(const vector[shared_ptr[Curve]]& curves, _curve.SpreadCurve *curve TCurve *tweaked_curve size_t i = 0 - double* recovery_rate + double recovery_rate if epsilon == 0.: with parallel(): @@ -616,10 +617,10 @@ cdef double pv(const vector[shared_ptr[Curve]]& curves, for i in prange(curves.size()): curve = <_curve.SpreadCurve*>(curves[i].get()) - recovery_rate = curve.recovery_rates.data() + recovery_rate = curve.recovery_rates[0] # FIXME: do something better - if isnan(deref(recovery_rate)): - preinc(recovery_rate) + if isnan(recovery_rate): + recovery_rate = curve.recovery_rates[1] JpmcdsContingentLegPV(legs.first, base_date, @@ -627,7 +628,7 @@ cdef double pv(const vector[shared_ptr[Curve]]& curves, step_in_date, yc, <TCurve*>deref(curve), - deref(recovery_rate), + recovery_rate, &cl_pv) JpmcdsFeeLegPV(legs.second, base_date, @@ -640,15 +641,16 @@ cdef double pv(const vector[shared_ptr[Curve]]& curves, r += weights[i] * (cl_pv - fl_pv * fixed_rate) else: with parallel(): + tweaked_curve = JpmcdsCopyCurve(<TCurve*>deref(curves[0].get())) cl_pv = 0. fl_pv = 0. for i in prange(curves.size()): curve = <_curve.SpreadCurve*>(curves[i].get()) - recovery_rate = curve.recovery_rates.data() + recovery_rate = curve.recovery_rates[0] _curve.Curve.tweak_mask_(tweaked_curve, epsilon, mask) # FIXME: do something better - if isnan(deref(recovery_rate)): - preinc(recovery_rate) + if isnan(recovery_rate): + recovery_rate = curve.recovery_rates[1] JpmcdsContingentLegPV(legs.first, base_date, @@ -656,7 +658,7 @@ cdef double pv(const vector[shared_ptr[Curve]]& curves, step_in_date, yc, tweaked_curve, - deref(recovery_rate), + recovery_rate, &cl_pv) JpmcdsFeeLegPV(legs.second, base_date, |
