diff options
Diffstat (limited to 'python/analytics/tranche_basket.py')
| -rw-r--r-- | python/analytics/tranche_basket.py | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/python/analytics/tranche_basket.py b/python/analytics/tranche_basket.py index f6b87dd1..89a4e31f 100644 --- a/python/analytics/tranche_basket.py +++ b/python/analytics/tranche_basket.py @@ -601,9 +601,14 @@ class TrancheBasket(BasketIndex): cl, pl = self.tranche_legs(self.K[j], self.rho[j]) q = self.tranche_quotes.quotes.iat[j] * dK[j] - \ pl - cl * self.tranche_quotes.running.iat[j] - x0, r = brentq(aux, 0., 1., - args=(self, self.K[j+1], q, self.tranche_quotes.running.iat[j], False), - full_output=True) + try: + x0, r = brentq(aux, 0., 1., + args=(self, self.K[j+1], q, + self.tranche_quotes.running.iat[j], False), + full_output=True) + except ValueError as e: + print(f"can't calibrate skew at attach {self.K[j+1]}") + raise if r.converged: self.rho[j+1] = x0 else: @@ -649,7 +654,7 @@ class TrancheBasket(BasketIndex): el2 = index2.expected_loss(shortened=shortened) if method == "ATM": - K1eq = el1 / el2 * index2.K[1:-1] + K1eq = np.clip(el1 / el2 * index2.K[1:-1], None, .999) elif method == "TLP": K1eq = [] for K2 in index2.K[1:-1]: @@ -661,5 +666,4 @@ class TrancheBasket(BasketIndex): # need to figure out a better way of setting the bounds K1eq.append(brentq(aux2, K2 * 0.1, K2 * 2.5, (self, index2, K2, shortened))) - return np.hstack([np.nan, expit(self._skew(logit(K1eq))), np.nan]) |
