diff options
Diffstat (limited to 'python')
| -rw-r--r-- | python/analytics/tranche_basket.py | 35 |
1 files changed, 30 insertions, 5 deletions
diff --git a/python/analytics/tranche_basket.py b/python/analytics/tranche_basket.py index 894a4545..b5e5f1af 100644 --- a/python/analytics/tranche_basket.py +++ b/python/analytics/tranche_basket.py @@ -40,6 +40,7 @@ import matplotlib.pyplot as plt import pandas as pd import numpy as np import analytics +import warnings logger = logging.getLogger(__name__) @@ -157,7 +158,6 @@ class DualCorrTranche: index_type, series, tenor = next(r) self._index = BasketIndex(index_type, series, [tenor], value_date=value_date) - self.index_type = index_type self.series = series self.tenor = tenor @@ -426,11 +426,32 @@ class DualCorrTranche: @pv.setter def pv(self, val): - def aux(rho): - self.rho[1] = rho + # if super senior tranche, we adjust the lower correlation, + # otherwise we adjust upper + if self.detach == 100: + corr_index = 0 + else: + corr_index = 1 + rho_saved = self.rho.copy() + + def aux(rho, corr_index): + self.rho[corr_index] = rho return self.pv - val - self.rho[1], r = brentq(aux, 0.0, 1.0, full_output=True) + try: + rho, r = brentq(aux, 0.0, 1.0, (corr_index,), full_output=True) + except ValueError: + self.rho = rho_saved + # if not equity or not super senior we try to adjust lower corr instead + if self.detach < 100 and self.attach > 0: + corr_index = 0 + try: + rho, r = brentq(aux, 0.0, 1.0, (corr_index,), full_output=True) + except ValueError: + self.rho = rho_saved + raise + else: + raise def reset_pv(self): with run_local(): @@ -537,9 +558,13 @@ class DualCorrTranche: def mark(self, **kwargs): if kwargs.pop("use_external", False): try: - self.pv = get_external_nav( + _pv = get_external_nav( dawn_engine, self._trade_id, self.value_date, "cds" ) + if analytics._local: + _pv /= self._index._fx + self.pv = _pv + return except ValueError as e: warnings.warn(str(e)) if "ref" in kwargs: |
