diff options
Diffstat (limited to 'python/analytics')
| -rw-r--r-- | python/analytics/tranche_basket.py | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/python/analytics/tranche_basket.py b/python/analytics/tranche_basket.py index b2bb2f61..29074988 100644 --- a/python/analytics/tranche_basket.py +++ b/python/analytics/tranche_basket.py @@ -379,10 +379,6 @@ class TrancheBasket(BasketIndex): @value_date.setter def value_date(self, d: pd.Timestamp): BasketIndex.value_date.__set__(self, d) - # Norske Skogindustrier ASA didn't trigger for tranches - if self.index_type == "XO" and self.series == 22 \ - and self.value_date > datetime.date(2016, 4, 25): - self._factor += 0.013333333333333333 self.cs = credit_schedule(d, self.tenor[:-1], 1, self.yc, self.maturity) self.K = adjust_attachments(self.K_orig, self.cumloss, self.factor) @@ -651,7 +647,7 @@ class TrancheBasket(BasketIndex): newrho = x else: newrho = expit(index1._skew(logit(x))) - assert newrho >= 0 and newrho <= 1, "Something went wrong" + assert newrho >= 0. and newrho <= 1., "Something went wrong" return self.expected_loss_trunc(x, rho=newrho) / el1 - \ index2.expected_loss_trunc(K2, newrho, shortened) / el2 @@ -661,6 +657,14 @@ class TrancheBasket(BasketIndex): return np.log(self.probability_trunc(x, newrho)) - \ np.log(index2.probability_trunc(K2, newrho, shortened)) + def find_upper_bound(*args): + K2 = args[4] + while aux(K2, *args) < 0: + if K2 > 1.: + raise ValueError("Can't find reasonnable bracketing interval") + K2 *= 1.1 + return K2 + if method not in ["ATM", "TLP", "PM"]: raise ValueError("method needs to be one of 'ATM', 'TLP' or 'PM'") @@ -673,7 +677,9 @@ class TrancheBasket(BasketIndex): elif method == "TLP": K1eq = [] for K2 in index2.K[1:-1]: - K1eq.append(brentq(aux, 0., 1., (self, el1, index2, el2, K2, shortened))) + b = find_upper_bound(self, el1, index2, el2, K2, shortened) + K1eq.append(brentq(aux, 0., b, + (self, el1, index2, el2, K2, shortened))) K1eq = np.array(K1eq) elif method == "PM": K1eq = [] |
