diff options
Diffstat (limited to 'python/notify_bowdst.py')
| -rw-r--r-- | python/notify_bowdst.py | 31 |
1 files changed, 17 insertions, 14 deletions
diff --git a/python/notify_bowdst.py b/python/notify_bowdst.py index 66ce9911..e5d8df58 100644 --- a/python/notify_bowdst.py +++ b/python/notify_bowdst.py @@ -10,25 +10,26 @@ from serenitas.utils import SerenitasFileHandler import logging fh = SerenitasFileHandler("mismatched_trades.log") -logger = logging.getLogger("notify_bowdst") +logger = logging.getLogger(__name__) logger.addHandler(fh) logger.setLevel(logging.WARNING) conn = dbconn("dawndb") cob = (datetime.date.today() - BDay(1)).date() -dates = [str((cob - datetime.timedelta(days=days))) for days in range(60)] +dates = pd.bdate_range(end=cob, periods=50) df = pd.concat( { - date: pd.read_sql_query( - f"""SELECT *, notional * factor as db_notional FROM list_cds_marks( %(date)s , NULL, 'BOWDST');""", + d: pd.read_sql_query( + "SELECT *, notional * factor AS db_notional " + "FROM list_cds_marks(%s, NULL, 'BOWDST')", conn, - params={"date": str(date)}, + params=(d,), ) - for date in dates + for d in dates.date } ).droplevel(level=1) -data = df[df.index == str(cob)][ - ["tenor", "security_desc", "security_id", "globeop_notional", "db_notional"] +data = df.loc[ + cob, ["tenor", "security_desc", "security_id", "globeop_notional", "db_notional"] ] inaccurate_balances = data[data["db_notional"] != data["globeop_notional"]] @@ -45,21 +46,23 @@ for row in inaccurate_balances.itertuples(): date = data.name globeop_notional = data.globeop_notional except IndexError: - print("No matches") + logger.info("No matches") continue buf = StringIO() - csv = pd.read_sql_query( - f"""SELECT * FROM cds WHERE trade_date > %(date)s and fund = 'BOWDST' and security_desc = %(security_desc)s and orig_detach is null and orig_attach is null order by trade_date desc""", + df = pd.read_sql_query( + "SELECT * FROM cds WHERE trade_date > %s " + "AND fund = 'BOWDST' AND security_desc = %s " + "AND orig_detach IS NULL AND orig_attach IS NULL ORDER BY trade_date DESC", conn, - params={"date": date, "security_desc": security_desc}, + params=(date, security_desc), ) - if len(csv[pd.to_datetime(csv["trade_date"]) >= (cob - BDay(1))].index) != 0: + if not df[df.trade_date >= cob - BDay(1)].empty: logger.error( f"Mismatch balance {row.security_desc} {row.globeop_notional} :{row.db_notional} Trades Recently" ) continue - csv.to_csv(buf) + df.to_csv(buf) attachments = [ FileAttachment(name=f"{security_desc}.csv", content=buf.getvalue().encode()) ] |
