diff options
Diffstat (limited to 'python/analytics')
| -rw-r--r-- | python/analytics/tranche_basket.py | 36 |
1 files changed, 20 insertions, 16 deletions
diff --git a/python/analytics/tranche_basket.py b/python/analytics/tranche_basket.py index 4dc0bf81..6e9a1f7b 100644 --- a/python/analytics/tranche_basket.py +++ b/python/analytics/tranche_basket.py @@ -603,16 +603,19 @@ class DualCorrTranche: return except ValueError as e: warnings.warn(str(e)) - if "ref" in kwargs and self.index_type != "BS": - quotes = kwargs["ref"] - if isinstance(quotes, dict): - ref = quotes[(self.index_type, self.series, self.tenor)] - elif isinstance(quotes, float): - ref = quotes + + # tweak the index only if we don't skip_tweak, or if it's not a bespoke + if not (kwargs.get("skip_tweak", False) or self.index_type == "BS"): + # figure out what the ref should be + if "ref" in kwargs: + quotes = kwargs["ref"] + if isinstance(quotes, dict): + ref = quotes[(self.index_type, self.series, self.tenor)] + elif isinstance(quotes, float): + ref = quotes + else: + raise ValueError("don't know what to do with ref: {ref}") else: - raise ValueError("don't know what to do with ref: {ref}") - else: - if not self.index_type == "BS": col_ref = "close_price" if self.index_type == "HY" else "close_spread" sql_query = ( f"SELECT {col_ref} from index_quotes_pre " @@ -639,10 +642,11 @@ class DualCorrTranche: f"{type(self).__name__}: No market quote for date {self.value_date}" ) serenitas_pool.putconn(conn) - try: - self._index.tweak([ref]) - except NameError: - pass + # now we can tweak + try: + self._index.tweak([ref]) + except NameError: + pass if "skew" in kwargs: self._skew = kwargs["skew"] @@ -674,7 +678,7 @@ class DualCorrTranche: if self.detach == 100: self.rho[1] = np.nan - def jump_to_default(self, skew): + def jump_to_default(self): curves = self._index.curves orig_factor, orig_cumloss = self._index.factor, self._index.cumloss orig_upf = self.tranche_factor * self.upfront @@ -692,7 +696,7 @@ class DualCorrTranche: self.K = adjust_attachments( self.K_orig, self._index.cumloss, self._index.factor ) - self.mark(skew=skew) + self.mark(skip_tweak=True) upf = self.tranche_factor * self.upfront # we allocate the loss to the different tranches loss = ( @@ -702,7 +706,7 @@ class DualCorrTranche: r.append(upf) tickers.append(curve.ticker) self._index._factor, self._index._cumloss = orig_factor, orig_cumloss - self.K = self.K = adjust_attachments( + self.K = adjust_attachments( self.K_orig, self._index.cumloss, self._index.factor ) self._index.curves = curves |
