diff options
Diffstat (limited to 'python/analytics/tranche_basket.py')
| -rw-r--r-- | python/analytics/tranche_basket.py | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/python/analytics/tranche_basket.py b/python/analytics/tranche_basket.py index 9f535368..303e82f2 100644 --- a/python/analytics/tranche_basket.py +++ b/python/analytics/tranche_basket.py @@ -183,6 +183,20 @@ class TrancheBasket(BasketIndex): def recovery_rates(self): return np.array([c.recovery_rates[0] for c in self.curves]) + def tranche_theta(self, shortened=4, complement=False, method=['ATM', 'TLP', 'PM']): + N = len(self.cs) - shortened + indexshort = deepcopy(self) + indexshort.cs = self.cs[:-shortened] + indexshort.rho = self.map_skew(indexshort, "ATM") + temp = self.tranche_pvs(complement=complement) + temp2 = indexshort.tranche_pvs(complement=complement) + temp3 = indexshort.tranche_deltas(complement=complement) + thetas = temp2[2] - temp[2] + self.tranche_quotes.running.values + return pd.DataFrame({'theta': thetas, 'delta': temp3.delta}, + index=self.tranche_quotes[['attach', 'detach']]. + apply(lambda row: f'{row.attach}-{row.detach}', + axis=1)) + def tranche_deltas(self, complement=False): eps = 1e-4 self._Ngrid = 301 @@ -247,8 +261,8 @@ class TrancheBasket(BasketIndex): def map_skew(self, index2, method="ATM"): def aux(x, index1, el1, index2, el2, K2): newrho = expit(index1._skew(logit(x))) - return self.expected_loss_trunc(x, rho=newrho) - \ - index2.expected_loss_trunc(K2, rho=newrho) + return self.expected_loss_trunc(x, rho=newrho)/el1 - \ + index2.expected_loss_trunc(K2, rho=newrho)/el2 def aux2(x, index1, index2, K2): newrho = expit(index1._skew(logit(x))) @@ -264,13 +278,11 @@ class TrancheBasket(BasketIndex): if method == "ATM": K1eq = el1 / el2 * index2.K[1:-1] - return expit(self._skew(logit(K1eq))) elif method == "TLP": K1eq = [] m = np.nanmax(index2.K) for K2 in index2.K[1:-1]: K1eq.append(brentq(aux, 0., m, (self, el1, index2, el2, K2))) - K1eq = np.array(K1eq) elif method == "PM": K1eq = [] |
