aboutsummaryrefslogtreecommitdiffstats
path: root/python/analytics/tranche_basket.py
diff options
context:
space:
mode:
Diffstat (limited to 'python/analytics/tranche_basket.py')
-rw-r--r--python/analytics/tranche_basket.py43
1 files changed, 21 insertions, 22 deletions
diff --git a/python/analytics/tranche_basket.py b/python/analytics/tranche_basket.py
index 0a4ae8ae..64fc03dd 100644
--- a/python/analytics/tranche_basket.py
+++ b/python/analytics/tranche_basket.py
@@ -6,7 +6,7 @@ from .tranche_functions import (
from .index_data import get_tranche_quotes
from .utils import memoize, build_table
from collections import namedtuple
-from db import dbconn
+from .db import dawn_engine, serenitas_engine
from copy import deepcopy
from lru import LRU
from pyisda.date import cds_accrued
@@ -80,13 +80,11 @@ class DualCorrTranche():
@classmethod
def from_tradeid(cls, trade_id):
- with dbconn('dawndb') as conn:
- with conn.cursor() as c:
- c.execute("SELECT * FROM cds LEFT JOIN index_desc "
- "ON security_id = redindexcode AND "
- "cds.maturity = index_desc.maturity "
- "WHERE id=%s", (trade_id,))
- rec = c.fetchone()
+ r = dawn_engine.execute("SELECT * FROM cds LEFT JOIN index_desc "
+ "ON security_id = redindexcode AND "
+ "cds.maturity = index_desc.maturity "
+ "WHERE id=%s", (trade_id,))
+ rec = r.fetchone()
instance = cls(rec['index'], rec['series'], rec['tenor'],
attach=rec['attach'],
detach=rec['detach'],
@@ -265,20 +263,21 @@ class DualCorrTranche():
"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")
- 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._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)
- self._tranche_id = tranche_id
+ 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)
+ self._tranche_id = tranche_id
+ conn.close()
@property
def tranche_factor(self):