diff options
Diffstat (limited to 'python/analytics/tranche_basket.py')
| -rw-r--r-- | python/analytics/tranche_basket.py | 51 |
1 files changed, 28 insertions, 23 deletions
diff --git a/python/analytics/tranche_basket.py b/python/analytics/tranche_basket.py index 863aaebf..21e03a79 100644 --- a/python/analytics/tranche_basket.py +++ b/python/analytics/tranche_basket.py @@ -288,29 +288,34 @@ class DualCorrTranche(): names=['spread_shock', 'corr_shock'])) def mark(self, **args): - sql_string = ("SELECT tranche_id, corr_at_detach FROM tranche_risk b " - "LEFT JOIN tranche_quotes a ON a.id = b.tranche_id " - "WHERE a.index=%s AND a.series=%s AND a.tenor=%s " - "AND quotedate::date=%s " - "AND (a.detach = %s OR a.attach = %s) ORDER BY a.attach") - conn = serenitas_engine.raw_connection() - with conn.cursor() as c: - c.execute(sql_string, (self.index_type, self.series, - self.tenor, self.value_date, - self.attach, self.attach)) - if self.attach == 0: - self._tranche_id, self.rho[1] = next(c) - elif self.detach == 100: - self._tranche_id, self.rho[0] = next(c) - else: - self.rho = [] - for tranche_id, corr in c: - self.rho.append(corr) - try: - self._tranche_id = tranche_id - except UnboundLocalError: - pass - conn.close() + if 'skew' in args: + el, skew_fun = args['skew'] + K_index_eq = np.clip(el/-self.index_pv().protection_leg * self.K, None, .999) + self.rho = expit(skew_fun(logit(K_index_eq))) + else: + sql_string = ("SELECT tranche_id, corr_at_detach FROM tranche_risk b " + "LEFT JOIN tranche_quotes a ON a.id = b.tranche_id " + "WHERE a.index=%s AND a.series=%s AND a.tenor=%s " + "AND quotedate::date=%s " + "AND (a.detach = %s OR a.attach = %s) ORDER BY a.attach") + conn = serenitas_engine.raw_connection() + with conn.cursor() as c: + c.execute(sql_string, (self.index_type, self.series, + self.tenor, self.value_date, + self.attach, self.attach)) + if self.attach == 0: + self._tranche_id, self.rho[1] = next(c) + elif self.detach == 100: + self._tranche_id, self.rho[0] = next(c) + else: + self.rho = [] + for tranche_id, corr in c: + self.rho.append(corr) + try: + self._tranche_id = tranche_id + except UnboundLocalError: + pass + conn.close() @property def tranche_factor(self): |
