summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--pyisda/credit_index.pyx22
1 files changed, 20 insertions, 2 deletions
diff --git a/pyisda/credit_index.pyx b/pyisda/credit_index.pyx
index f0be482..a3f617d 100644
--- a/pyisda/credit_index.pyx
+++ b/pyisda/credit_index.pyx
@@ -7,7 +7,7 @@ cimport cython
from legs cimport (JpmcdsCdsContingentLegMake, JpmcdsCdsFeeLegMake,
JpmcdsContingentLegPV, JpmcdsFeeLegPV, FeeLegAI, JpmcdsFeeLegFree)
from curve cimport (SpreadCurve, JpmcdsCopyCurve, tweak_curve, YieldCurve,
- JpmcdsFreeTCurve)
+ JpmcdsFreeTCurve, JpmcdsForwardZeroPrice)
from date cimport (pydate_to_TDate, TDate_to_pydate, ACT_365F, JpmcdsDtFwdAny,
TDateInterval, JpmcdsMakeDateInterval)
from cdsone cimport JpmcdsStringToStubMethod, TStubMethod
@@ -310,7 +310,7 @@ cdef class CreditIndex(CurveList):
r.append(TDate_to_pydate(maturity))
return r
- def tweak_portfolio(self, double epsilon, maturity, inplace=True):
+ def tweak_portfolio(self, double epsilon, maturity, bint inplace=True):
cdef:
TDate maturity_c = pydate_to_TDate(maturity)
unsigned long mask = fill_mask(maturity_c, self.maturities,
@@ -323,6 +323,24 @@ cdef class CreditIndex(CurveList):
sc = p.second.get()
tweak_curve(sc, sc, epsilon, h, self.T, mask)
+ @cython.boundscheck(False)
+ def survival_matrix(self, TDate[:] schedule, d1=None):
+ cdef:
+ pair[string, shared_ptr[TCurve]] p
+ TCurve* sc
+ TDate start_date
+ size_t i, j
+ np.npy_intp[2] n = [self.curves.size(), schedule.shape[0]]
+ np.ndarray[np.float64_t,ndim=2] sp = np.PyArray_EMPTY(2, n, np.NPY_DOUBLE, 0)
+ j = 0
+ for p in self.curves:
+ sc = p.second.get()
+ start_date = sc.fBaseDate
+ for i in range(n[1]):
+ sp[j,i] = JpmcdsForwardZeroPrice(sc, start_date, schedule[i])
+ j += 1
+ return sp
+
cdef unsigned long fill_mask(const TDate maturity, const vector[TDate]& maturities,
const shared_ptr[TCurve]& sc) nogil:
cdef: