diff options
Diffstat (limited to 'python')
| -rw-r--r-- | python/fcm_fx.py | 2 | ||||
| -rw-r--r-- | python/populate_tranche_cashflows.py | 8 | ||||
| -rw-r--r-- | python/report_ops/utils.py | 17 | ||||
| -rw-r--r-- | python/risk/tranches.py | 19 |
4 files changed, 32 insertions, 14 deletions
diff --git a/python/fcm_fx.py b/python/fcm_fx.py index 64edef5d..df7a640e 100644 --- a/python/fcm_fx.py +++ b/python/fcm_fx.py @@ -28,7 +28,7 @@ def email_fcm(em, d, fund): </style> </head> <body> - Hello,<br><br>Please see below details for an FX Spot Trade we did with the desk today for account {account}. {additional_instructions if 'additional_instructions' in globals() else ""}Please let me know if you need more information.<br><br>{to_tabulate(d)} + Hello,<br><br>Please see below details for an FX Spot Trade we did with the desk today for account {account}. {additional_instructions if 'additional_instructions' in locals() else ""}Please let me know if you need more information.<br><br>{to_tabulate(d)} </body> </html>""" ), diff --git a/python/populate_tranche_cashflows.py b/python/populate_tranche_cashflows.py index 1a7264d5..a76aabaf 100644 --- a/python/populate_tranche_cashflows.py +++ b/python/populate_tranche_cashflows.py @@ -49,18 +49,18 @@ def insert_tranche_cashflows( with dawndb.cursor() as c: for tranche_id, principal, accrued in data: c.execute( - "INSERT INTO tranche_cashflows VALUES(%s, %s, %s, %s, %s)", + "INSERT INTO tranche_cashflows VALUES(%s, %s, %s, %s, %s) ON CONFLICT ON CONSTRAINT tranche_cashflows_pkey DO NOTHING", (auction_date + bus_day, tranche_id, principal, accrued, "USD"), ) dawndb.commit() def insert_tranche_accrued(d: datetime.date, dawndb, fund="SERCGMAST"): - portf = get_tranche_portfolio(d, dawndb, fund=fund) + portf = get_tranche_portfolio(d, dawndb, funds=(fund,)) with dawndb.cursor() as c: for t in portf: c.execute( - "INSERT INTO tranche_cashflows(date, tranche_id, accrued, currency) " + "INSERT INTO tranche_cashflows(date, tranche_id, accrued, currency) ON CONFLICT ON CONSTRAINT tranche_cashflows_pkey DO NOTHING" "VALUES(%s, %s, %s, %s)", ( t.cs["payment_dates"][0], @@ -100,4 +100,4 @@ if __name__ == "__main__": serenitas.analytics._include_todays_cashflows = True for fund in ("SERCGMAST", "BOWDST", "BRINKER", "ISOSEL"): - insert_tranche_accrued(datetime.date(2022, 9, 19), dawndb, fund) + insert_tranche_accrued(datetime.date(2022, 12, 16), dawndb, fund) diff --git a/python/report_ops/utils.py b/python/report_ops/utils.py index 035b2e13..54f25526 100644 --- a/python/report_ops/utils.py +++ b/python/report_ops/utils.py @@ -102,13 +102,24 @@ def check_cleared_cds(date, fund, conn): _tolerance = {"IG": 0.10, "HY": 0.20, "EU": 0.20, "XO": 0.30} with conn.cursor() as c: c.execute( - "SELECT *, abs(price-globeop_price) AS difference FROM list_cds_marks(%s, NULL, %s) WHERE abs((notional * factor) - globeop_notional) < 100;", - (date, fund), + "SELECT * FROM list_cds_marks(%s, NULL, %s), fx WHERE date=%s AND abs((notional*factor) - globeop_nav) < 100;", + (date, fund, date), ) for row in c: d = row._asdict() d["serenitas_quote"] = d["price"] - d["admin_quote"] = d["globeop_price"] + match d["index"]: + case "XO" | "EU": + d["admin_quote"] = 100 - ( + ((d["globeop_nav"] - d["accrued"]) / d["eurusd"]) + / (d["globeop_notional"] / 100) + ) + case _: + d["admin_quote"] = 100 - ( + (d["globeop_nav"] - d["accrued"]) + / (d["globeop_notional"] / 100) + ) + d["difference"] = abs(d["price"] - d["admin_quote"]) if d["difference"] > _tolerance[d["index"]]: CDXQuoteMonitor.stage(d) CDXQuoteMonitor.email(fund) diff --git a/python/risk/tranches.py b/python/risk/tranches.py index 01c08951..c5352ba5 100644 --- a/python/risk/tranches.py +++ b/python/risk/tranches.py @@ -1,3 +1,4 @@ +import numpy as np from pyisda.date import cds_accrued from serenitas.analytics.api import Portfolio, DualCorrTranche from serenitas.analytics.dates import prev_business_day @@ -80,8 +81,9 @@ def insert_tranche_pnl_explain(portf, conn): to_insert = [] for trade_id in all_ids: - pnl = 0 - fx_pnl = 0 + pnl = 0.0 + fx_pnl = 0.0 + corr_pnl = 0.0 if trade_id in daily_trades: trade = daily_trades[trade_id] pnl = trade.upfront * get_fx(value_date, trade.currency) @@ -131,6 +133,11 @@ def insert_tranche_pnl_explain(portf, conn): * get_fx(prev_day, trade.currency) ) ) + prev_rho = np.array( + [previous_risk.corr_attach, previous_risk.corr_detach] + ) + rho = trade.rho + corr_pnl = np.nansum((rho - prev_rho) * previous_risk.corr01_vec) else: fx_pnl = 0.0 day_trade = daily_trades[trade_id] @@ -145,12 +152,12 @@ def insert_tranche_pnl_explain(portf, conn): pnl += trade.pv * get_fx(value_date, trade.currency) unexplained = pnl - delta_pnl - fx_pnl to_insert.append( - (value_date, trade_id, pnl, fx_pnl, delta_pnl, unexplained) + (value_date, trade_id, pnl, fx_pnl, delta_pnl, corr_pnl, unexplained) ) c.executemany( - "INSERT INTO tranche_pnl_explain(date, tranche_id, pnl, fx_pnl, delta_pnl, unexplained) " - "VALUES (%s, %s, %s, %s, %s, %s)", + "INSERT INTO tranche_pnl_explain(date, tranche_id, pnl, fx_pnl, delta_pnl, corr_pnl, unexplained) " + "VALUES (%s, %s, %s, %s, %s, %s, %s)", to_insert, ) conn.commit() @@ -168,7 +175,7 @@ def insert_tranche_risk(portf, conn): "gamma", "theta", "theta_amount", - "corr01", + "corr01_vec", "tranche_factor", "upfront", "running", |
