aboutsummaryrefslogtreecommitdiffstats
path: root/python/reallocate_iam.py
diff options
context:
space:
mode:
Diffstat (limited to 'python/reallocate_iam.py')
-rw-r--r--python/reallocate_iam.py22
1 files changed, 15 insertions, 7 deletions
diff --git a/python/reallocate_iam.py b/python/reallocate_iam.py
index 2846938d..bbee59d5 100644
--- a/python/reallocate_iam.py
+++ b/python/reallocate_iam.py
@@ -119,7 +119,9 @@ def cancel_old_iam_trades(fund: str, cob: datetime.date, conn) -> "Iterable":
conn.commit()
-def generate_new_iam_trades(fund: str, cob: datetime.date, conn) -> "Iterable":
+def generate_new_iam_trades(
+ fund: str, cob: datetime.date, conn, backfill
+) -> "Iterable":
"""Generates new IAM deals"""
with conn.cursor() as cursor:
cursor.execute(
@@ -127,11 +129,16 @@ def generate_new_iam_trades(fund: str, cob: datetime.date, conn) -> "Iterable":
(cob, fund),
)
for row in cursor:
- trade_data = row._asdict() | {"trade_date": cob}
+ trade_data = row._asdict() | {
+ "trade_date": cob,
+ "maturity": next_business_day(cob) if backfill else None,
+ }
yield IAMDeal.from_dict(**trade_data)
-def generate_new_iam_offset_trades(fund: str, cob: datetime.date, conn) -> "Iterable":
+def generate_new_iam_offset_trades(
+ fund: str, cob: datetime.date, conn, backfill
+) -> "Iterable":
"""Generates offsets if the sma has already updated these IAM deals"""
_ignore = {"BOWDST": ("GS_FCM",)}
with conn.cursor() as cursor:
@@ -147,6 +154,7 @@ def generate_new_iam_offset_trades(fund: str, cob: datetime.date, conn) -> "Iter
"folder": "M_CSH_CASH",
"portfolio": "CASH",
"trade_date": cob,
+ "maturity": next_business_day(cob) if backfill else None,
}
yield IAMDeal.from_dict(**trade_data)
@@ -164,15 +172,15 @@ def update_matured_iam_trades(fund: str, prev_date: datetime.date, conn) -> "Ite
conn.commit()
-def build_iam(fund: str, cob: datetime.date, conn, upload: bool):
+def build_iam(fund: str, cob: datetime.date, conn, upload: bool, backfill):
"""Generates IAM file for globeop"""
service = Service[fund]
for old_iam in cancel_old_iam_trades(fund, cob, conn):
service.push_trade(old_iam, "CANCEL")
- for new_iam in generate_new_iam_trades(fund, cob, conn):
+ for new_iam in generate_new_iam_trades(fund, cob, conn, backfill):
new_iam.stage()
if fund == "BOWDST":
- for new_iam_offset in generate_new_iam_offset_trades(fund, cob, conn):
+ for new_iam_offset in generate_new_iam_offset_trades(fund, cob, conn, backfill):
new_iam_offset.stage()
for iam in IAMDeal.commit(returning=True):
service.push_trade(iam, "NEW")
@@ -203,4 +211,4 @@ if __name__ == "__main__":
conn = dbconn("dawndb")
args = parse_args()
for fund in ("SERCGMAST", "BOWDST"):
- build_iam(fund, args.cob, conn, not args.no_upload)
+ build_iam(fund, args.cob, conn, not args.no_upload, args.backfill)