diff options
Diffstat (limited to 'python/analytics')
| -rw-r--r-- | python/analytics/tranche_basket.py | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/python/analytics/tranche_basket.py b/python/analytics/tranche_basket.py index 9bbf1c93..ae2d73e2 100644 --- a/python/analytics/tranche_basket.py +++ b/python/analytics/tranche_basket.py @@ -213,15 +213,20 @@ class DualCorrTranche(): names=['spread_shock', 'corr_shock'])) def mark(self, **args): - corr = pd.read_sql_query("select a.attach, a.detach, corr_at_detach from " - "get_tranche_quotes(%s, %s, %s, %s) a LEFT JOIN " - "risk_numbers_new b on a.id = b.tranche_id", - dbengine('serenitasdb'), - params=(self.index_type, self.series, - self.tenor, self.value_date)) - if self.attach > 0: - self.rho[0] = corr[corr['detach'] == self.attach]['corr_at_detach'] - self.rho[1] = corr[corr['detach'] == self.detach]['corr_at_detach'] + sql_string = ("SELECT corr_at_detach FROM get_tranche_quotes(%s, %s, %s, %s) a " + "LEFT JOIN risk_numbers_new b ON a.id = b.tranche_id " + "WHERE a.detach = %s OR a.attach = %s ORDER BY a.attach") + with dbconn('serenitasdb') as conn: + 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.rho[1], = next(c) + elif self.attach == 100: + self.rho[0], = next(c) + else: + self.rho = np.array([corr for corr, in c]) class TrancheBasket(BasketIndex): |
