summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--pyisda/credit_index.pyx45
1 files changed, 44 insertions, 1 deletions
diff --git a/pyisda/credit_index.pyx b/pyisda/credit_index.pyx
index 31044b9..75e1067 100644
--- a/pyisda/credit_index.pyx
+++ b/pyisda/credit_index.pyx
@@ -14,7 +14,7 @@ from .legs cimport (JpmcdsCdsContingentLegMake, JpmcdsCdsFeeLegMake,
from .curve cimport (SpreadCurve, JpmcdsCopyCurve, tweak_curve, YieldCurve,
JpmcdsFreeTCurve, survival_prob, Hash64WithSeed,
Hash64, uint64_t, TCurve_size, serialize, CurveName,
- Seniority, DocClause, get_TCurve)
+ Seniority, DocClause, get_TCurve, JpmcdsCdsParSpreads)
from .date cimport (pydate_to_TDate, TDate_to_pydate, JpmcdsDtFwdAny,
TDateInterval, JpmcdsMakeDateInterval)
from .cdsone cimport JpmcdsStringToStubMethod, TStubMethod
@@ -601,6 +601,49 @@ cdef class CreditIndex(CurveList):
schedule_ptr[i], epsilon)
return sp, tickers
+ def spreads(self, YieldCurve yc not None, const TDate[::1] schedule=None):
+ cdef:
+ shared_ptr[TCurve] sc
+ pair[CurveName, size_t] p
+ np.npy_intp[2] n
+ const TDate* schedule_ptr
+
+ if schedule is None:
+ schedule_ptr = self._maturities.const_data()
+ n[1] = self._maturities.size()
+ else:
+ schedule_ptr = &schedule[0]
+ n[1] = schedule.shape[0]
+ n[0] = self._curves.size()
+
+ cdef:
+ np.ndarray spreads = np.PyArray_EMPTY(2, n, np.NPY_DOUBLE, 0)
+ double[:, ::1] spreads_view = spreads
+ TStubMethod stub_type
+
+ JpmcdsStringToStubMethod(b"f/s", &stub_type)
+
+ with nogil:
+ for p in self.names:
+ sc = self._curves[p.second]
+ JpmcdsCdsParSpreads(
+ self.base_date,
+ self.base_date + 1,
+ self.start_date,
+ n[1],
+ schedule_ptr,
+ True,
+ NULL,
+ &stub_type,
+ ACT_360,
+ MODIFIED,
+ b'NONE',
+ get_TCurve(yc),
+ sc.get(),
+ self.recovery_rates[p.second].get(),
+ &spreads_view[p.second, 0])
+ return spreads
+
cdef unsigned long fill_mask(const TDate maturity, const vector[TDate]& maturities,
const shared_ptr[TCurve]& sc) nogil:
cdef: