aboutsummaryrefslogtreecommitdiffstats
path: root/python
diff options
context:
space:
mode:
Diffstat (limited to 'python')
-rw-r--r--python/book_bbg.py36
1 files changed, 31 insertions, 5 deletions
diff --git a/python/book_bbg.py b/python/book_bbg.py
index 63f7f2ac..0c4978d0 100644
--- a/python/book_bbg.py
+++ b/python/book_bbg.py
@@ -5,6 +5,7 @@ import pytz
from stat import S_ISREG
import csv
from process_queue import rename_keys
+from serenitas.utils.db import dbconn
fund_dictionary = {"SERENITAS_CGMF": "SERCGMAST", "BOWDOINST": "BOWDST"}
fcm_dictionary = {"Bank of America, N.A.": "BAML", "Goldman Sachs": "GS"}
@@ -30,6 +31,27 @@ def download_files(date):
return downloaded_files
+def get_bbg_data(bbg_id, trade_date):
+ try:
+ _, indextype, _, series, tenor = bbg_id.split()
+ except ValueError:
+ return "not a valid bloomberg description", 400
+ indextype = indextype[:2]
+ tenor = tenor[:-1] + "yr"
+ series = int(series[1:])
+ sql_str = (
+ "SELECT redindexcode, maturity, coupon "
+ "FROM index_desc "
+ "WHERE index=%s and series=%s and tenor=%s "
+ " and lastdate >=%s ORDER BY version"
+ )
+ db = get_db()
+ with db.cursor() as c:
+ c.execute(sql_str, (indextype, series, tenor, trade_date))
+ redcode, maturity, coupon = c.fetchone()
+ return str(maturity), redcode, coupon
+
+
def cdx_booking_process(path):
reader = csv.DictReader(open(path))
for csvdict in reader:
@@ -56,12 +78,16 @@ def cdx_booking_process(path):
csv_dict["folder"] = None
csv_dict["cp_code"] = None
csv_dict["payment_rolldate"] = "Following"
- csv_dict["fixed_rate"] = None
- csv_dict["day_count"] = None
- csv_dict["frequency"] = None
- csv_dict["security_id"] = None
- csv_dict["swap_type"] = None
+ csv_dict["day_count"] = "ACT/360"
+ csv_dict["frequency"] = 4
+ csv_dict["swap_type"] = "CD_INDEX"
csv_dict["portfolio"] = None
+ (
+ csv_dict["maturity"],
+ csv_dict["security_id"],
+ csv_dict["fixed_rate"],
+ ) = get_bbg_data(csv_dict["security_desc"], csv_dict["trade_date"])
+ csv_dict["effective_date"] = datetime.date(2021, 12, 20)
def book_trades(date):