diff options
| author | Guillaume Horel <guillaume.horel@gmail.com> | 2019-02-05 15:17:04 -0500 |
|---|---|---|
| committer | Guillaume Horel <guillaume.horel@gmail.com> | 2019-02-05 15:17:04 -0500 |
| commit | 937e0728dba3b2eb2879723a4fdd6791809459ff (patch) | |
| tree | b113582c140381aaafcaa014c2ade211f4353a75 | |
| parent | 68a86b75970b66fa691a9377e0006ac17fe11131 (diff) | |
| download | pyisda-937e0728dba3b2eb2879723a4fdd6791809459ff.tar.gz | |
add protection_leg method
| -rw-r--r-- | pyisda/credit_index.pyx | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/pyisda/credit_index.pyx b/pyisda/credit_index.pyx index d87a198..d8187dd 100644 --- a/pyisda/credit_index.pyx +++ b/pyisda/credit_index.pyx @@ -453,6 +453,48 @@ cdef class CreditIndex(CurveList): JpmcdsFeeLegFree(legs.second) return r + def protection_leg(self, step_in_date, cash_settle_date, maturity, YieldCurve yc not None): + cdef: + TDate step_in_date_c = pydate_to_TDate(step_in_date) + TDate cash_settle_date_c = pydate_to_TDate(cash_settle_date) + TDate maturity_c = pydate_to_TDate(maturity) + TContingentLeg* cl + size_t i + int found + + found = get_maturity_index(maturity_c, self._maturities) + if found == -1: + cl = JpmcdsCdsContingentLegMake(self.start_date, + maturity_c, + 1., + True) + else: + cl = self.contingent_legs[found] + cdef: + double cl_pv, r = 0 + TCurve* sc + double* recovery_rate + with nogil: + with parallel(): + for i in prange(self._curves.size()): + sc = self._curves[i].get() + recovery_rate = self.recovery_rates[i].get() + # FIXME: do something better + if isnan(deref(recovery_rate)): + preinc(recovery_rate) + JpmcdsContingentLegPV(cl, + self.base_date, + cash_settle_date_c, + step_in_date_c, + yc._thisptr.get(), + sc, + deref(recovery_rate), + &cl_pv) + r += self._weights[i] * cl_pv + if found == -1: + free(cl) + return r + def duration(self, step_in_date, cash_settle_date, maturity, YieldCurve yc not None): cdef: |
