diff options
Diffstat (limited to 'python/analytics')
| -rw-r--r-- | python/analytics/tranche_basket.py | 55 |
1 files changed, 38 insertions, 17 deletions
diff --git a/python/analytics/tranche_basket.py b/python/analytics/tranche_basket.py index c0145ecc..195b43da 100644 --- a/python/analytics/tranche_basket.py +++ b/python/analytics/tranche_basket.py @@ -865,12 +865,13 @@ class TrancheBasket(BasketIndex): else: return tranche_cl(L, R, cs, 0.0, K), tranche_pl(L, cs, 0.0, K) - def jump_to_default(self): + def jump_to_default(self, zero_recovery=False): curves = self.curves orig_factor, orig_cumloss = self.factor, self.cumloss el_orig = self.expected_loss() orig_upfs = ( - self.tranche_factors() * self.tranche_pvs(protection=True).bond_price + self.tranche_factors() + * self.tranche_pvs(protection=True, zero_recovery=zero_recovery).bond_price ) r = [] tickers = [] @@ -885,7 +886,12 @@ class TrancheBasket(BasketIndex): self.K = adjust_attachments(self.K_orig, self.cumloss, self.factor) Korig_eq = self.K[1:1] / self.expected_loss() self.rho = np.hstack([np.nan, expit(self._skew(np.log(Korig_eq))), np.nan]) - upfs = self.tranche_factors() * self.tranche_pvs(protection=True).bond_price + upfs = ( + self.tranche_factors() + * self.tranche_pvs( + protection=True, zero_recovery=zero_recovery + ).bond_price + ) # we allocate the loss to the different tranches loss = np.diff([0, *(min(k, L) for k in self.K[1:])]) upfs += loss / np.diff(self.K_orig) * orig_factor @@ -992,21 +998,25 @@ class TrancheBasket(BasketIndex): probfun = PchipInterpolator(support, p) return probfun(K) - def tranche_durations(self, complement=False): - cl = self.tranche_pvs(complement=complement).coupon_leg + def tranche_durations(self, complement=False, zero_recovery=False): + cl = self.tranche_pvs( + complement=complement, zero_recovery=zero_recovery + ).coupon_leg durations = (cl - self._accrued) / self.tranche_quotes.running durations.index = self._row_names durations.name = "duration" return durations - def tranche_EL(self, complement=False): - pl = self.tranche_pvs(complement=complement).protection_leg + def tranche_EL(self, complement=False, zero_recovery=False): + pl = self.tranche_pvs( + complement=complement, zero_recovery=zero_recovery + ).protection_leg EL = pd.Series(-pl * np.diff(self.K), index=self._row_names) EL.name = "expected_loss" return EL - def tranche_spreads(self, complement=False): - cl, pl, _ = self.tranche_pvs(complement=complement) + def tranche_spreads(self, complement=False, zero_recovery=False): + cl, pl, _ = self.tranche_pvs(complement=complement, zero_recovery=zero_recovery) durations = (cl - self._accrued) / self.tranche_quotes.running.values return pd.Series(-pl / durations * 1e4, index=self._row_names, name="spread") @@ -1016,12 +1026,16 @@ class TrancheBasket(BasketIndex): ad = (self.K_orig * 100).astype("int") return [f"{a}-{d}" for a, d in zip(ad, ad[1:])] - def tranche_thetas(self, complement=False, shortened=4, method="ATM"): - bp = self.tranche_pvs(complement=complement).bond_price + def tranche_thetas( + self, complement=False, shortened=4, method="ATM", zero_recovery=False + ): + bp = self.tranche_pvs( + complement=complement, zero_recovery=zero_recovery + ).bond_price rho_saved = self.rho self.rho = self.map_skew(self, method, shortened) bpshort = self.tranche_pvs( - complement=complement, shortened=shortened + complement=complement, shortened=shortened, zero_recovery=zero_recovery ).bond_price self.rho = rho_saved thetas = bpshort - bp + self.tranche_quotes.running.values @@ -1043,7 +1057,7 @@ class TrancheBasket(BasketIndex): df.columns = ["fwd_delta", "fwd_gamma"] return df - def tranche_deltas(self, complement=False): + def tranche_deltas(self, complement=False, zero_recovery=False): eps = 1e-4 index_list = [self] for tweak in [eps, -eps, 2 * eps]: @@ -1055,7 +1069,7 @@ class TrancheBasket(BasketIndex): for i, index in enumerate(index_list): indexbp[i] = index.index_pv().bond_price - bp[i] = index.tranche_pvs().bond_price + bp[i] = index.tranche_pvs(zero_recovery=zero_recovery).bond_price factor = self.tranche_factors() / self.factor deltas = (bp[1] - bp[2]) / (indexbp[1] - indexbp[2]) * factor @@ -1063,11 +1077,18 @@ class TrancheBasket(BasketIndex): gammas = (deltasplus - deltas) / (indexbp[1] - indexbp[0]) / 100 return pd.DataFrame({"delta": deltas, "gamma": gammas}, index=self._row_names) - def tranche_corr01(self, eps=0.01, complement=False): - bp = self.tranche_pvs(complement=complement).bond_price + def tranche_corr01(self, eps=0.01, complement=False, zero_recovery=False): + bp = self.tranche_pvs( + complement=complement, zero_recovery=zero_recovery + ).bond_price rho_saved = self.rho self.rho = np.power(self.rho, 1 - eps) - corr01 = self.tranche_pvs(complement=complement).bond_price - bp + corr01 = ( + self.tranche_pvs( + complement=complement, zero_recovery=zero_recovery + ).bond_price + - bp + ) self.rho = rho_saved return corr01 |
