aboutsummaryrefslogtreecommitdiffstats
path: root/python
diff options
context:
space:
mode:
Diffstat (limited to 'python')
-rw-r--r--python/process_queue.py25
-rw-r--r--python/risk/tranches.py9
2 files changed, 19 insertions, 15 deletions
diff --git a/python/process_queue.py b/python/process_queue.py
index 73242324..fe701dc2 100644
--- a/python/process_queue.py
+++ b/python/process_queue.py
@@ -345,16 +345,22 @@ def build_termination(
with dawndb.cursor() as c:
c.execute(
- f"SELECT dealid, cp_code, notional FROM {table} where id=%s", (dealid,)
+ "SELECT dealid, cp_code, notional, termination_amount, globeop_id "
+ f"FROM {table} where id=%s",
+ (dealid,),
)
- dealid, cp_code, notional = c.fetchone()
+ dealid, cp_code, notional, partial_amounts, globeopid = c.fetchone()
+ remaining_notional = notional - sum(partial_amounts)
+ termination_amount = termination_amount or remaining_notional
c.execute(
f"UPDATE {table} "
- "SET termination_amount=%s, termination_cp=%s, termination_fee=%s, "
- "termination_date=%s "
+ "SET termination_amount=termination_amount||%s::float8, "
+ "termination_cp=termination_cp||%s::text, "
+ "termination_fee=termination_fee||%s::float8, "
+ "termination_date=termination_date||%s::date "
"WHERE dealid=%s",
(
- termination_amount or notional,
+ termination_amount,
termination_cp or cp_code,
fee,
termination_date,
@@ -415,17 +421,18 @@ def build_termination(
headers += ["InitialMargin", "InitialMarginCurrency"]
if termination_cp is None:
headers += ["Reserved"] * 4 + ["CreditEventOccured"]
-
d = {
"DealType": deal_type,
- "DealId": dealid,
+ "GoTradeId": int(globeopid[3:9]),
"Action": "Update",
"Client": "Serenitas",
"SubAction": "Termination",
- "PartialTermination": "N" if termination_amount is None else "Y",
+ "PartialTermination": "Y"
+ if remaining_notional - termination_amount > 0
+ else "N",
"TerminationAmount": termination_amount,
"TerminationDate": termination_date,
- "FeesPaid": fee if fee < 0 else None,
+ "FeesPaid": -fee if fee < 0 else None,
"FeesReceived": fee if fee > 0 else None,
"FeePaymentDate": (termination_date + 3 * bus_day).date(),
}
diff --git a/python/risk/tranches.py b/python/risk/tranches.py
index 8c41b523..c6b41c3e 100644
--- a/python/risk/tranches.py
+++ b/python/risk/tranches.py
@@ -10,13 +10,10 @@ def get_tranche_portfolio(date, conn, by_strat=False, fund="SERCGMAST"):
params = (date, fund)
else:
sql_string = (
- "SELECT folder, id from cds "
- "WHERE orig_attach IS NOT NULL "
- "AND (termination_date IS NULL OR termination_date > %s) "
- "AND maturity > %s AND trade_date <= %s "
- "AND fund = %s ORDER BY trade_date"
+ "SELECT folder, id from list_cds(%s, %s) "
+ "WHERE orig_attach IS NOT NULL ORDER BY trade_date"
)
- params = (date, date, date, fund)
+ params = (date, fund)
with conn.cursor() as c:
c.execute(sql_string, params)
trade_ids = [tuple(e) for e in c]