aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--python/analytics/tranche_basket.py28
1 files changed, 14 insertions, 14 deletions
diff --git a/python/analytics/tranche_basket.py b/python/analytics/tranche_basket.py
index 9554fbe0..0e431173 100644
--- a/python/analytics/tranche_basket.py
+++ b/python/analytics/tranche_basket.py
@@ -965,6 +965,16 @@ class TrancheBasket(BasketIndex):
)
return pd.DataFrame(1 - sm, index=tickers, columns=self.cs.index)
+ def _default_prob(self, shortened):
+ if shortened == 0:
+ cs = self.cs
+ else:
+ cs = self.cs[:-shortened]
+ sm, _ = super().survival_matrix(
+ cs.index.values.astype("M8[D]").view("int") + 134774
+ )
+ return cs, 1 - sm
+
def tranche_legs(self, K, rho, complement=False, shortened=0, zero_recovery=False):
if (K == 0.0 and not complement) or (K == 1.0 and complement):
return 0.0, 0.0
@@ -973,12 +983,7 @@ class TrancheBasket(BasketIndex):
elif np.isnan(rho):
raise ValueError("rho needs to be a real number between 0. and 1.")
else:
- if shortened > 0:
- default_prob = self.default_prob.values[:, :-shortened]
- cs = self.cs[:-shortened]
- else:
- default_prob = self.default_prob.values
- cs = self.cs
+ cs, default_prob = self._default_prob(shortened)
if zero_recovery:
recovery_rates = np.zeros(self.weights.size)
else:
@@ -1067,14 +1072,9 @@ class TrancheBasket(BasketIndex):
return self._Legs(cl, pl, bp)
def index_pv(self, discounted=True, shortened=0, zero_recovery=False):
- if shortened > 0:
- DP = self.default_prob.values[:, -shortened]
- df = self.cs.df.values[:-shortened]
- coupons = self.cs.coupons.values[:-shortened]
- else:
- DP = self.default_prob.values
- df = self.cs.df.values
- coupons = self.cs.coupons
+ cs, DP = self._default_prob(shortened)
+ df = cs.df.values
+ coupons = cs.coupons.values
if zero_recovery:
ELvec = self.weights @ DP
else: