summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuillaume Horel <guillaume.horel@gmail.com>2022-05-20 15:45:56 -0400
committerGuillaume Horel <guillaume.horel@gmail.com>2022-05-20 15:45:56 -0400
commit94b0747c84ef50626e9dcc64e2fb89694df8dea2 (patch)
tree648f8a82c56ab19b807e4be2aee31e2e88aef11c
parent3b8ae529a29e26b2776558c1bcbd437aa1330453 (diff)
downloadpyisda-94b0747c84ef50626e9dcc64e2fb89694df8dea2.tar.gz
fix theta in case of defaulted name
-rw-r--r--pyisda/credit_index.pxd1
-rw-r--r--pyisda/credit_index.pyx8
-rw-r--r--pyisda/curve.pyx2
3 files changed, 8 insertions, 3 deletions
diff --git a/pyisda/credit_index.pxd b/pyisda/credit_index.pxd
index 12d405f..7722a9b 100644
--- a/pyisda/credit_index.pxd
+++ b/pyisda/credit_index.pxd
@@ -12,6 +12,7 @@ cdef class CurveList:
cdef map[CurveName, size_t] names
cdef vector[shared_ptr[double]] recovery_rates
cdef vector[TDate] defaulted
+ cdef double defaulted_weight
cdef class CreditIndex(CurveList):
cdef TDate _start_date
diff --git a/pyisda/credit_index.pyx b/pyisda/credit_index.pyx
index 0951f35..2d63306 100644
--- a/pyisda/credit_index.pyx
+++ b/pyisda/credit_index.pyx
@@ -67,6 +67,7 @@ cdef class CurveList:
i = 0
cdef int n_skipped = 0
cdef double total_weight = 0.
+ self.defaulted_weight = 0.0
for w, sc in curves:
if sc is not None:
it = self.names.find(deref(sc.name))
@@ -80,6 +81,8 @@ cdef class CurveList:
else:
self._weights[deref(it).second] += w
total_weight += w
+ if sc.defaulted != -1:
+ self.defaulted_weight += w
else:
n_skipped += 1
@@ -194,6 +197,7 @@ cdef class CurveList:
self._weights.clear()
self.recovery_rates.clear()
self.defaulted.clear()
+ self.defaulted_weight = 0.0
cdef TDate temp = self.base_date
CurveList.__init__(self, l)
self.base_date = temp
@@ -429,11 +433,11 @@ cdef class CreditIndex(CurveList):
if theta_date is None:
JpmcdsMakeDateInterval(-1, b"Y", &ivl)
JpmcdsDtFwdAny(maturity_c, &ivl, &temp)
- carry = fixed_rate * 365 / 360
+ carry = (1 - self.defaulted_weight) * fixed_rate * 365 / 360
else:
theta_date_c = pydate_to_TDate(theta_date)
temp = maturity_c - (theta_date_c - step_in_date_c)
- carry = fixed_rate * (theta_date_c - step_in_date_c) / 360
+ carry = (1 - self.defaulted_weight) * fixed_rate * (theta_date_c - step_in_date_c) / 360
if temp < step_in_date_c:
return nan("")
diff --git a/pyisda/curve.pyx b/pyisda/curve.pyx
index 76dcd06..71b61b3 100644
--- a/pyisda/curve.pyx
+++ b/pyisda/curve.pyx
@@ -1,7 +1,7 @@
from cython.operator import dereference as deref, preincrement as preinc
from libc.math cimport log1p, log, exp, isnan
-from .date cimport (JpmcdsStringToDateInterval, pydate_to_TDate, dcc, TMonthDayYear,
+from .date cimport (JpmcdsStringToDateInterval, pydate_to_TDate, dcc,
JpmcdsDateIntervalToFreq, JpmcdsDateFwdThenAdjust, TDate_to_pydate,
JpmcdsDateFromBusDaysOffset, JpmcdsStringToDayCountConv, ACT_360,
BadDay, FOLLOW, MODIFIED, NONE)