diff options
Diffstat (limited to 'python/analytics/tranche_basket.py')
| -rw-r--r-- | python/analytics/tranche_basket.py | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/python/analytics/tranche_basket.py b/python/analytics/tranche_basket.py index b1c03702..0bf661e7 100644 --- a/python/analytics/tranche_basket.py +++ b/python/analytics/tranche_basket.py @@ -245,6 +245,16 @@ class TrancheBasket(BasketIndex): logit(self.rho[1:-1]), bc_type='natural') 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) + + def aux2(x, index1, index2, K2): + newrho = expit(index1._skew(logit(x))) + return np.log(self.probability_trunc(x, newrho)) - \ + np.log(index2.probability_trunc(x, newrho)) + if method not in ["ATM", "TLP", "PM"]: raise ValueError("method needs to be one of 'ATM', 'TLP' or 'PM'") @@ -254,5 +264,19 @@ class TrancheBasket(BasketIndex): if method == "ATM": K1eq = el1 / el2 * index2.K[1:-1] - # elif method == "TLP": - # pass + 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, K2))) + + K1eq = np.array(K1eq) + elif method == "PM": + K1eq = [] + m = np.nanmax(K2) + 0.25 + for K2 in index2.K[1:-1]: + K1eq.append(brentq(aux, K2 * 0.1, K2*1.8, + (self, index2, K2))) + + return np.hstack([np.nan, K1eq, np.nan]) |
