aboutsummaryrefslogtreecommitdiffstats
path: root/python/analytics
diff options
context:
space:
mode:
Diffstat (limited to 'python/analytics')
-rw-r--r--python/analytics/index.py19
1 files changed, 10 insertions, 9 deletions
diff --git a/python/analytics/index.py b/python/analytics/index.py
index acf17e79..4c921c38 100644
--- a/python/analytics/index.py
+++ b/python/analytics/index.py
@@ -9,14 +9,14 @@ from quantlib.settings import Settings
from quantlib.time.api import Date, Actual365Fixed
from termcolor import colored
from pandas.tseries.offsets import BDay
-from db import dbconn
-from psycopg2 import DataError
+from db import dbengine
+from sqlalchemy import exc
from pyisda.curve import SpreadCurve
from .utils import previous_twentieth
from scipy.optimize import brentq
from yieldcurve import YC, ql_to_jp, roll_yc, rate_helpers
-serenitasdb = dbconn('serenitasdb')
+engine = dbengine('serenitasdb')
def g(index, spread, exercise_date, forward_yc = None):
"""computes the strike clean price using the expected forward yield curve """
@@ -232,13 +232,14 @@ class Index(object):
def from_name(cls, index, series, tenor, trade_date = datetime.date.today(),
notional = 10e6):
try:
- with serenitasdb.cursor() as c:
- c.execute("SELECT maturity, coupon FROM index_maturity " \
- "WHERE index=%s AND series=%s AND tenor = %s",
- (index.upper(), series, tenor))
- maturity, coupon = next(c)
- except DataError as e:
+ r = engine.execute("SELECT maturity, coupon FROM index_maturity " \
+ "WHERE index=%s AND series=%s AND tenor = %s",
+ (index.upper(), series, tenor))
+ maturity, coupon = r.fetchone()
+ except exc.DataError as e:
raise
+ except TypeError:
+ raise ValueError("Index not found")
else:
recovery = 0.4 if index.lower() == "ig" else 0.3
instance = cls(trade_date, maturity, recovery, coupon)