aboutsummaryrefslogtreecommitdiffstats
path: root/python/cds_curve.py
diff options
context:
space:
mode:
Diffstat (limited to 'python/cds_curve.py')
-rw-r--r--python/cds_curve.py43
1 files changed, 22 insertions, 21 deletions
diff --git a/python/cds_curve.py b/python/cds_curve.py
index cdbb545a..14637c2e 100644
--- a/python/cds_curve.py
+++ b/python/cds_curve.py
@@ -7,7 +7,7 @@ import logging
import pandas as pd
from serenitas.utils import SerenitasFileHandler
-from serenitas.utils.db import dbconn
+from serenitas.utils.db2 import serenitas_pool
logger = logging.getLogger(__name__)
@@ -84,19 +84,20 @@ if __name__ == "__main__":
)
args = parser.parse_args()
index, series = args.index, args.series
- conn = dbconn("serenitasdb")
if args.latest:
- with conn.cursor() as c:
- c.execute(
- "SELECT max(date) FROM index_quotes_pre "
- "RIGHT JOIN index_risk2 USING (id) "
- "WHERE index=%s AND series=%s "
- "AND tenor in ('3yr', '5yr', '7yr', '10yr')",
- (index, series),
- )
- (start_date,) = c.fetchone()
- start_date = pd.Timestamp(start_date)
+ with serenitas_pool.connection() as conn:
+ with conn.cursor() as c:
+ c.execute(
+ "SELECT max(date) FROM index_quotes_pre "
+ "RIGHT JOIN index_risk2 USING (id) "
+ "WHERE index=%s AND series=%s "
+ "AND tenor in ('3yr', '5yr', '7yr', '10yr')",
+ (index, series),
+ )
+ (start_date,) = c.fetchone()
+ start_date = pd.Timestamp(start_date)
+ conn.commit()
else:
start_date = None
@@ -118,12 +119,12 @@ if __name__ == "__main__":
for c in ("theta", "duration", "tweak", "dispersion", "gini")
]
)
- with conn.cursor() as c:
- for id, t in g:
- c.execute(
- "INSERT INTO index_risk2 VALUES(%s, %s, %s, %s, %s, %s) ON CONFLICT (id) "
- f"DO UPDATE SET {update_str}",
- (id,) + tuple(t),
- )
- conn.commit()
- conn.close()
+ with serenitas_pool.connection() as conn:
+ with conn.cursor() as c:
+ for id, t in g:
+ c.execute(
+ "INSERT INTO index_risk2 VALUES(%s, %s, %s, %s, %s, %s) ON CONFLICT (id) "
+ f"DO UPDATE SET {update_str}",
+ (id,) + tuple(t),
+ )
+ conn.commit()