from legs cimport (JpmcdsCdsContingentLegMake, JpmcdsCdsFeeLegMake, JpmcdsFeeLegFlows, TBoolean) from libc.stdlib cimport free from date cimport pydate_to_TDate, TDate_to_pydate, dcc from cdsone cimport JpmcdsStringToStubMethod, TStubMethod from curve cimport ZeroCurve, SpreadCurve cdef class ContingentLeg: def __cinit__(self, start_date, end_date, double notional, TBoolean protect_start = True): self._thisptr = JpmcdsCdsContingentLegMake(pydate_to_TDate(start_date), pydate_to_TDate(end_date), notional, protect_start) def __dealloc__(self): if self._thisptr is not NULL: free(self._thisptr) cdef class FeeLeg: def __cinit__(self, start_date, end_date, TBoolean pay_accrued_on_default, double notional, double coupon_rate, str payment_dcc = 'ACT/360', TBoolean protect_start = True): cdef TStubMethod stub_type if JpmcdsStringToStubMethod(b"f/s", &stub_type) != 0: raise ValueError("can't convert stub") self._thisptr = JpmcdsCdsFeeLegMake(pydate_to_TDate(start_date), pydate_to_TDate(end_date), pay_accrued_on_default, NULL, &stub_type, notional, coupon_rate, dcc(payment_dcc), 'M', NULL, protect_start) @property def cashflows(self): cdef TCashFlowList* cfl = JpmcdsFeeLegFlows(self._thisptr) cdef TCashFlow cf result = [] for i in range(cf.fNumItems): cf = cfl.fArray[i] result.append((TDate_to_pydate(cf.fDate), cf.fAmount)) return result def pv(self, today, step_in_date, value_date, ZeroCurve zc, SpreadCurve sc, TBoolean pay_accrued_at_start): cdef today_c = pydate_to_TDate(today) cdef step_in_date_c = pydate_to_TDate(step_in_date) cdef value_date_c = pydate_to_TDate(value_date) cdef double pv if JpmcdsFeeLegPV(self._thisptr, today, step_in_date, value_date, zc._thisptr, sc._thisptr, pay_accrued_at_start, &pv) == 0: return pv else: raise ValueError def __dealloc__(self): if self._thisptr is not NULL: JpmcdsFeeLegFree(self._thisptr)