diff options
| author | Guillaume Horel <guillaume.horel@gmail.com> | 2021-03-15 21:51:41 -0400 |
|---|---|---|
| committer | Guillaume Horel <guillaume.horel@gmail.com> | 2021-03-15 21:51:41 -0400 |
| commit | ba6e47340c1c4a44b34c5641eaadb9832a5a9493 (patch) | |
| tree | 0cb88ec7b6c3e6be9eace37637927cccfcffaadb | |
| parent | d7ee7a6bee1be2451a224091e6f4c32f56263771 (diff) | |
| download | pyisda-ba6e47340c1c4a44b34c5641eaadb9832a5a9493.tar.gz | |
allow to return log of survival probabilities
| -rw-r--r-- | pyisda/credit_index.pyx | 6 | ||||
| -rw-r--r-- | pyisda/curve.pxd | 2 | ||||
| -rw-r--r-- | pyisda/curve.pyx | 6 |
3 files changed, 7 insertions, 7 deletions
diff --git a/pyisda/credit_index.pyx b/pyisda/credit_index.pyx index 9a70125..2f90b01 100644 --- a/pyisda/credit_index.pyx +++ b/pyisda/credit_index.pyx @@ -597,7 +597,7 @@ cdef class CreditIndex(CurveList): tweak_curve(sc_orig, sc_copy, epsilon, mask) self._curves[i].reset(sc_copy, JpmcdsFreeTCurve) - def survival_matrix(self, const TDate[::1] schedule=None, double epsilon=0.): + def survival_matrix(self, const TDate[::1] schedule=None, double epsilon=0., bint log=False): cdef: shared_ptr[TCurve] sc pair[CurveName, size_t] p @@ -624,7 +624,7 @@ cdef class CreditIndex(CurveList): tickers[j] = p.first.ticker for i in range(n[1]): sp_view[j, i] = survival_prob(sc.get(), self.base_date, - schedule_ptr[i], epsilon) + schedule_ptr[i], epsilon, log) j += 1 return sp, tickers @@ -722,7 +722,7 @@ cdef class CreditIndex(CurveList): if exp_loss: if self.defaulted[j] != -1: for i in range(n): - spreads[i] = (1 - survival_prob(sc.get(), self.base_date, schedule_ptr[i], 0.)) * (1 - self.recovery_rates[j].get()[i]) + spreads[i] = (1 - survival_prob(sc.get(), self.base_date, schedule_ptr[i], 0., False)) * (1 - self.recovery_rates[j].get()[i]) else: for i in range(n): spreads[i] = 1 - self.recovery_rates[j].get()[i] diff --git a/pyisda/curve.pxd b/pyisda/curve.pxd index 7ab41da..a91a290 100644 --- a/pyisda/curve.pxd +++ b/pyisda/curve.pxd @@ -182,7 +182,7 @@ cdef extern from "isda/cxzerocurve.h" nogil: double JpmcdsZeroRate(TCurve* curve, TDate date) cdef double survival_prob(const TCurve* curve, TDate start_date, - TDate maturity_date, double eps) nogil + TDate maturity_date, double eps, bint log) nogil cdef extern from "isda/cfinanci.h" nogil: int JpmcdsDiscountToRateYearFrac(double discount, # (I) Discount factor diff --git a/pyisda/curve.pyx b/pyisda/curve.pyx index 87d613e..034dd81 100644 --- a/pyisda/curve.pyx +++ b/pyisda/curve.pyx @@ -40,7 +40,7 @@ cdef inline void double_free(double* ptr) nogil: free(ptr) -cdef double survival_prob(const TCurve* curve, TDate start_date, TDate maturity_date, double eps) nogil: +cdef double survival_prob(const TCurve* curve, TDate start_date, TDate maturity_date, double eps, bint log) nogil: cdef: double lambda1, lambda2 double t1, t2, u @@ -49,7 +49,7 @@ cdef double survival_prob(const TCurve* curve, TDate start_date, TDate maturity_ t2 = (maturity_date - curve.fBaseDate) / 365. if eps != 0.: lambda2 *= (1 + eps) - return exp(-lambda2 * t2) + return -lambda2 * t2 if log else exp(-lambda2 * t2) else: lambda1 = JpmcdsZeroRate(curve, start_date) lambda2 = JpmcdsZeroRate(curve, maturity_date) @@ -58,7 +58,7 @@ cdef double survival_prob(const TCurve* curve, TDate start_date, TDate maturity_ u = (lambda1 * t1 - lambda2 * t2) / 365. if eps != 0.: u *= (1 + eps) - return exp(u) + return u if log else exp(u) cdef class Curve(object): |
