aboutsummaryrefslogtreecommitdiffstats
path: root/python
diff options
context:
space:
mode:
Diffstat (limited to 'python')
-rw-r--r--python/analytics/tranche_basket.py44
1 files changed, 27 insertions, 17 deletions
diff --git a/python/analytics/tranche_basket.py b/python/analytics/tranche_basket.py
index b75559ab..b7039d1c 100644
--- a/python/analytics/tranche_basket.py
+++ b/python/analytics/tranche_basket.py
@@ -5,6 +5,8 @@ from .tranche_functions import (
GHquad,
BCloss_recov_dist,
BCloss_recov_trunc,
+ CDS2015,
+ OldCDS,
tranche_cl,
tranche_pl,
tranche_pl_trunc,
@@ -19,6 +21,7 @@ from copy import deepcopy
from dateutil.relativedelta import relativedelta
from lru import LRU
from math import log
+from pandas.tseries.offsets import Day
from pyisda.date import cds_accrued
from scipy.optimize import brentq
from scipy.interpolate import CubicSpline, PchipInterpolator
@@ -162,10 +165,15 @@ class DualCorrTranche:
self.rho = [corr_attach, corr_detach]
self.tranche_running = tranche_running
self.notional = notional
+ if index_type == "BS":
+ rule = OldCDS
+ self._accrued = 0.0
+ else:
+ rule = CDS2015
+ self._accrued = cds_accrued(value_date, tranche_running * 1e-4)
self.cs = credit_schedule(
- value_date, None, 1.0, self._index.yc, self._index.maturities[0]
+ value_date, 1.0, self._index.yc, self._index.maturities[0], rule=rule
)
- self._accrued = cds_accrued(value_date, tranche_running * 1e-4)
self.use_trunc = use_trunc
self._tranche_id = None
self._ignore_hash = set(["_Z", "_w", "cs", "_cache", "_Legs", "_ignore_hash"])
@@ -177,7 +185,14 @@ class DualCorrTranche:
@maturity.setter
def maturity(self, m):
self._index.maturities = [m]
- self.cs = credit_schedule(self.value_date, None, 1.0, self._index.yc, m)
+ start_date = pd.Timestamp(self.value_date) + Day()
+ self.cs = credit_schedule(
+ start_date,
+ 1.0,
+ self._index.yc,
+ m,
+ rule=OldCDS if self.index_type == "BS" else CDS2015,
+ )
def _default_prob(self, epsilon=0.0):
return (
@@ -241,10 +256,14 @@ class DualCorrTranche:
@value_date.setter
def value_date(self, d: pd.Timestamp):
self._index.value_date = d
- self.cs = credit_schedule(
- d, None, 1.0, self._index.yc, self._index.maturities[0]
+ start_date = pd.Timestamp(d) + Day()
+ self.cs = self.cs[self.cs.index > start_date]
+ self._accrued = (
+ (start_date - self.cs.start_dates[0]).days
+ / 360
+ * self.tranche_running
+ * 1e-4
)
- self._accrued = cds_accrued(d, self.tranche_running * 1e-4)
if (
self._index.index_type == "XO"
and self._index.series == 22
@@ -329,13 +348,6 @@ class DualCorrTranche:
def pv(self):
pl, cl = self._pv()
_pv = -self.notional * self.tranche_factor * (pl + cl)
- if self.index_type == "BS":
- if self.value_date < next_twentieth(self._trade_date):
- stub = (
- cds_accrued(self._trade_date, self.tranche_running * 1e-4)
- * self.notional
- )
- _pv -= stub
return _pv
@property
@@ -733,9 +745,7 @@ class TrancheBasket(BasketIndex):
self._Ngrid = 301
self._Z, self._w = GHquad(self._Ngh)
self.rho = np.full(self.K.size, np.nan)
- self.cs = credit_schedule(
- value_date, self.tenor[:-1], 1, self.yc, self.maturity
- )
+ self.cs = credit_schedule(value_date, 1.0, self.yc, self.maturity)
def _get_tranche_quotes(self, value_date):
if isinstance(value_date, datetime.datetime):
@@ -788,7 +798,7 @@ class TrancheBasket(BasketIndex):
@value_date.setter
def value_date(self, d: pd.Timestamp):
BasketIndex.value_date.__set__(self, d)
- self.cs = credit_schedule(d, self.tenor[:-1], 1, self.yc, self.maturity)
+ self.cs = credit_schedule(d, 1.0, self.yc, self.maturity)
self.K = adjust_attachments(self.K_orig, self.cumloss, self.factor)
try:
self._get_tranche_quotes(d)