diff options
| author | Guillaume Horel <guillaume.horel@serenitascapital.com> | 2016-06-29 15:44:42 -0400 |
|---|---|---|
| committer | Guillaume Horel <guillaume.horel@serenitascapital.com> | 2016-06-29 15:44:42 -0400 |
| commit | c34e1e0988738fe697dba5ea628203eea17c24a0 (patch) | |
| tree | 5684f0b8eb8737ecc2bb97b20c5477f07eac7d96 | |
| parent | f6ee33b57d5f9dc82b06c9f9ccbf8528fc3b783f (diff) | |
| download | pyisda-c34e1e0988738fe697dba5ea628203eea17c24a0.tar.gz | |
add cdsone functions
| -rw-r--r-- | cdsone.pxd | 52 | ||||
| -rw-r--r-- | cdsone.pyx | 72 |
2 files changed, 124 insertions, 0 deletions
diff --git a/cdsone.pxd b/cdsone.pxd new file mode 100644 index 0000000..0f76c50 --- /dev/null +++ b/cdsone.pxd @@ -0,0 +1,52 @@ +from date cimport TDateInterval +from pyisda.zerocurve cimport TCurve + +cdef extern from "isda/stub.h": + ctypedef struct TStubMethod: + pass + + int JpmcdsStringToStubMethod(char* name, TStubMethod* stub) + +cdef extern from "isda/cdsone.h": + + ctypedef int TBoolean + + ctypedef long int TDate + + int JpmcdsCdsoneUpfrontCharge(TDate today, + TDate valueDate, + TDate benchmarkStartDate, + TDate stepinDate, + TDate startDate, + TDate endDate, + double couponRate, + TBoolean payAccruedOnDefault, + TDateInterval* dateInterval, + TStubMethod* stubType, + long accrueDCC, + long badDayConv, + char* calendar, + TCurve* discCurve, + double oneSpread, + double recoveryRate, + TBoolean payAccruedAtStart, + double* upfrontCharge) + + int JpmcdsCdsoneSpread(TDate today, + TDate valueDate, + TDate benchmarkStartDate, + TDate stepinDate, + TDate startDate, + TDate endDate, + double couponRate, + TBoolean payAccruedOnDefault, + TDateInterval* dateInterval, + TStubMethod* stubType, + long accrueDCC, + long badDayConv, + char* calendar, + TCurve* discCurve, + double upfrontCharge, + double recoveryRate, + TBoolean payAccruedAtStart, + double* oneSpread) diff --git a/cdsone.pyx b/cdsone.pyx new file mode 100644 index 0000000..cb567f6 --- /dev/null +++ b/cdsone.pyx @@ -0,0 +1,72 @@ +from pyisda.cdsone cimport (JpmcdsCdsoneUpfrontCharge, + JpmcdsCdsoneSpread, JpmcdsStringToStubMethod) +from pyisda.zerocurve cimport ZeroCurve +from pyisda.date cimport JpmcdsStringToDateInterval, pydate_to_TDate +from pyisda.yearfrac cimport dcc + +cdef int SUCCESS = 0 + +def upfront_charge(date, value_date, benchmark_start_date, stepin_date, + start_date, end_date, double coupon_rate, + ZeroCurve zc, + double spread, + double recovery_rate, + TBoolean pay_accrued_at_start = True, + TBoolean pay_accrued_on_default = True): + + cdef: + TDate today = pydate_to_TDate(date) + TDate value_date_c = pydate_to_TDate(value_date) + TDate benchmark_start_date_c = pydate_to_TDate(benchmark_start_date) + TDate stepin_date_c = pydate_to_TDate(stepin_date) + TDate start_date_c = pydate_to_TDate(start_date) + TDate end_date_c = pydate_to_TDate(end_date) + double result + TStubMethod stub + TDateInterval ivl + char* routine = "upfront_charge" + + if JpmcdsStringToStubMethod(b"f/s", &stub) != SUCCESS: + raise ValueError("can't convert stub") + if JpmcdsStringToDateInterval(b"3M", routine, &ivl) != SUCCESS: + raise ValueError("can't convert to date interval") + if JpmcdsCdsoneUpfrontCharge(today, value_date_c, benchmark_start_date_c, stepin_date_c, + start_date_c, end_date_c, coupon_rate, pay_accrued_on_default, + &ivl, &stub, + dcc("ACT/360"), b'F', b"None", zc._thisptr, spread, recovery_rate, + pay_accrued_at_start, &result) == SUCCESS: + return result + else: + raise ValueError("computation failed") + +def spread_from_upfront(date, value_date, benchmark_start_date, stepin_date, + start_date, end_date, double coupon_rate, + ZeroCurve zc, + double upfront, + double recovery_rate, + TBoolean pay_accrued_at_start = True, + TBoolean pay_accrued_on_default = True): + cdef: + TDate today = pydate_to_TDate(date) + TDate value_date_c = pydate_to_TDate(value_date) + TDate benchmark_start_date_c = pydate_to_TDate(benchmark_start_date) + TDate stepin_date_c = pydate_to_TDate(stepin_date) + TDate start_date_c = pydate_to_TDate(start_date) + TDate end_date_c = pydate_to_TDate(end_date) + double result + TStubMethod stub + TDateInterval ivl + char* routine = "upfront_charge" + + if JpmcdsStringToStubMethod(b"f/s", &stub) != SUCCESS: + raise ValueError("can't convert stub") + if JpmcdsStringToDateInterval(b"3M", routine, &ivl) != SUCCESS: + raise ValueError("can't convert to date interval") + if JpmcdsCdsoneSpread(today, value_date_c, benchmark_start_date_c, stepin_date_c, + start_date_c, end_date_c, coupon_rate, pay_accrued_on_default, + &ivl, &stub, + dcc("ACT/360"), b'F', b"None", zc._thisptr, upfront, recovery_rate, + pay_accrued_at_start, &result) == SUCCESS: + return result + else: + raise ValueError("computation failed") |
