diff options
| author | Guillaume Horel <guillaume.horel@serenitascapital.com> | 2016-06-30 15:03:44 -0400 |
|---|---|---|
| committer | Guillaume Horel <guillaume.horel@serenitascapital.com> | 2016-06-30 15:03:44 -0400 |
| commit | ed83c435dcb32b5afd7f58a0fde72b41dc0d09e6 (patch) | |
| tree | 8d452dff2ac51a02eea4df3960b61d7f45f3e8d6 /curve.pyx | |
| parent | f1bed268cfd976966b6bab376a59c52dfd0216fa (diff) | |
| download | pyisda-ed83c435dcb32b5afd7f58a0fde72b41dc0d09e6.tar.gz | |
legs functions
Diffstat (limited to 'curve.pyx')
| -rw-r--r-- | curve.pyx | 58 |
1 files changed, 49 insertions, 9 deletions
@@ -1,11 +1,10 @@ from cpython cimport datetime from libc.stdlib cimport malloc, free -from pyisda.zerocurve cimport JpmcdsBuildIRZeroCurve, JpmcdsZeroPrice -from pyisda.yearfrac cimport dcc -from pyisda.date cimport (JpmcdsStringToDateInterval, pydate_to_TDate, - JpmcdsDateIntervalToFreq, JpmcdsDateFwdThenAdjust, TDate_to_pydate, - JpmcdsDateFromBusDaysOffset) - +from curve cimport JpmcdsBuildIRZeroCurve, JpmcdsZeroPrice, +from date cimport (JpmcdsStringToDateInterval, pydate_to_TDate, dcc, + JpmcdsDateIntervalToFreq, JpmcdsDateFwdThenAdjust, TDate_to_pydate, + JpmcdsDateFromBusDaysOffset) +from cdsone cimport JpmcdsStringToStubMethod, TStubMethod cdef int SUCCESS = 0 cpdef public enum BadDay: @@ -14,7 +13,12 @@ cpdef public enum BadDay: NONE = <long>'N' MODIFIED = <long>'M' -cdef class ZeroCurve: +cdef class Curve: + def __dealloc__(self): + if self._thisptr is not NULL: + JpmcdsFreeTCurve(self._thisptr) + +cdef class ZeroCurve(Curve): def __init__(self, date, str types, list periods, double[:] rates, @@ -68,8 +72,6 @@ cdef class ZeroCurve: ) def __dealloc__(self): - if self._thisptr is not NULL: - JpmcdsFreeTCurve(self._thisptr) if self._dates is not NULL: free(self._dates) @@ -82,3 +84,41 @@ cdef class ZeroCurve: def list_dates(self): cdef size_t i return [TDate_to_pydate(self._dates[i]) for i in range(self._ninstr)] + +cdef class SpreadCurve(Curve): + + def __init__(self, today, ZeroCurve zc, start_date, step_in_date, cash_settle_date, + list end_dates, double[:] coupon_rates, double recovery_rate, + TBoolean pay_accrued_on_default): + + cdef today_c = pydate_to_TDate(today) + cdef step_in_date_c = pydate_to_TDate(step_in_date) + cdef cash_settle_date_c = pydate_to_TDate(cash_settle_date) + cdef start_date_c = pydate_to_TDate(start_date) + cdef TDate* end_dates_c = <TDate*>malloc(len(end_dates) * sizeof(TDate)) + + cdef size_t i + + for i, d in enumerate(end_dates): + end_dates_c[i] = pydate_to_TDate(end_dates) + cdef TStubMethod stub_type + + if JpmcdsStringToStubMethod(b"f/s", &stub_type) != 0: + raise ValueError("can't convert stub") + + self._thisptr = JpmcdsCleanSpreadCurve(today_c, + zc._thisptr, + start_date_c, + step_in_date_c, + cash_settle_date, + len(end_dates), + end_dates_c, + &coupon_rates[0], + NULL, + recovery_rate, + pay_accrued_on_default, + NULL, + dcc('ACT/360'), + &stub_type, + <long>'M', + NULL) |
