diff options
Diffstat (limited to 'legs.pyx')
| -rw-r--r-- | legs.pyx | 103 |
1 files changed, 0 insertions, 103 deletions
diff --git a/legs.pyx b/legs.pyx deleted file mode 100644 index 55f1fcb..0000000 --- a/legs.pyx +++ /dev/null @@ -1,103 +0,0 @@ -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 YieldCurve, 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) - if self._thisptr is NULL: - raise ValueError - - def __dealloc__(self): - if self._thisptr is not NULL: - free(self._thisptr) - - def pv(self, today, step_in_date, value_date, YieldCurve yc, SpreadCurve sc, - double recovery_rate): - cdef TDate today_c = pydate_to_TDate(today) - cdef TDate step_in_date_c = pydate_to_TDate(step_in_date) - cdef TDate value_date_c = pydate_to_TDate(value_date) - cdef double pv - if JpmcdsContingentLegPV(self._thisptr, today_c, value_date_c, step_in_date_c, - yc._thisptr, sc._thisptr, recovery_rate, &pv) == 0: - return pv - else: - raise ValueError - -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), - <long>'M', - b'NONE', - protect_start) - if self._thisptr is NULL: - raise ValueError - - def inspect(self): - cdef list acc_start_dates = [] - cdef list acc_end_dates = [] - cdef list pay_dates = [] - cdef size_t i - for i in range(self._thisptr.nbDates): - acc_start_dates.append(TDate_to_pydate(self._thisptr.accStartDates[i])) - acc_end_dates.append(TDate_to_pydate(self._thisptr.accEndDates[i])) - pay_dates.append(TDate_to_pydate(self._thisptr.payDates[i])) - return {'acc_start_dates': acc_start_dates, - 'acc_end_dates': acc_end_dates, - 'pay_dates': pay_dates} - - @property - def cashflows(self): - cdef TCashFlowList* cfl = JpmcdsFeeLegFlows(self._thisptr) - cdef TCashFlow cf - result = [] - for i in range(cfl.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, YieldCurve yc, SpreadCurve sc, - TBoolean pay_accrued_at_start): - cdef TDate today_c = pydate_to_TDate(today) - cdef TDate step_in_date_c = pydate_to_TDate(step_in_date) - cdef TDate value_date_c = pydate_to_TDate(value_date) - cdef double pv - if JpmcdsFeeLegPV(self._thisptr, today_c, step_in_date_c, value_date_c, - yc._thisptr, sc._thisptr, pay_accrued_at_start, &pv) == 0: - return pv - else: - raise ValueError - - def accrued(self, today): - cdef double ai - FeeLegAI(self._thisptr, pydate_to_TDate(today), &ai) - return ai - - def __dealloc__(self): - if self._thisptr is not NULL: - JpmcdsFeeLegFree(self._thisptr) |
