aboutsummaryrefslogtreecommitdiffstats
path: root/python
diff options
context:
space:
mode:
Diffstat (limited to 'python')
-rw-r--r--python/collateral/__main__.py5
-rw-r--r--python/collateral/baml_fcm.py4
-rw-r--r--python/collateral/baml_isda.py4
-rw-r--r--python/collateral/bnp.py27
-rw-r--r--python/collateral/citi.py5
-rw-r--r--python/collateral/cs.py4
-rw-r--r--python/collateral/gs.py4
-rw-r--r--python/collateral/ms.py28
-rw-r--r--python/collateral/wells.py4
9 files changed, 53 insertions, 32 deletions
diff --git a/python/collateral/__main__.py b/python/collateral/__main__.py
index 17a0828e..b1d728d0 100644
--- a/python/collateral/__main__.py
+++ b/python/collateral/__main__.py
@@ -36,7 +36,8 @@ if args.download:
em = ExchangeMessage()
for cp in counterparties:
cp_mod = import_module(f".{cp}", "collateral")
- cp_mod.download_files(em)
+ for fund in ("Serenitas", "Brinker", "BowdSt"):
+ cp_mod.download_files(em, fund=fund)
dawn_trades = get_dawn_trades(args.workdate, dawn_engine)
@@ -60,7 +61,7 @@ for cp in counterparties:
while lookback < 2:
try:
df[cp.upper()] = cp_mod.collateral(
- args.workdate - BDay(lookback), positions, dawn_engine
+ args.workdate - BDay(lookback), positions, engine=dawn_engine
)
except FileNotFoundError as e:
logger.info(e)
diff --git a/python/collateral/baml_fcm.py b/python/collateral/baml_fcm.py
index d97c877b..1f6150b2 100644
--- a/python/collateral/baml_fcm.py
+++ b/python/collateral/baml_fcm.py
@@ -4,12 +4,12 @@ import pandas as pd
from sqlalchemy.exc import IntegrityError
-def download_files(*args):
+def download_files(*args, **kwargs):
sftp = SftpClient.from_creds("baml_fcm")
sftp.download_files("outgoing", DAILY_DIR / "BAML_reports")
-def collateral(d, positions, engine):
+def collateral(d, positions, *, engine):
df = pd.read_csv(
DAILY_DIR
/ "BAML_reports"
diff --git a/python/collateral/baml_isda.py b/python/collateral/baml_isda.py
index 01809bee..92727236 100644
--- a/python/collateral/baml_isda.py
+++ b/python/collateral/baml_isda.py
@@ -56,7 +56,7 @@ def download_from_secure_id(
z.extract(f, path=path)
-def download_files(em, d=None, count=20):
+def download_files(em, d=None, count=20, **kwargs):
DATA_DIR = DAILY_DIR / "BAML_ISDA_reports"
emails = em.get_msgs(path=["NYops", "Margin Calls Baml"], count=count)
for msg in emails:
@@ -136,7 +136,7 @@ def load_excel(fname):
return df
-def collateral(d, dawn_trades, *args):
+def collateral(d, dawn_trades, **kwargs):
report_date = d + BDay()
REPORTS_DIR = DAILY_DIR / "BAML_ISDA_reports"
try:
diff --git a/python/collateral/bnp.py b/python/collateral/bnp.py
index 331a2187..a89dc19c 100644
--- a/python/collateral/bnp.py
+++ b/python/collateral/bnp.py
@@ -2,14 +2,19 @@ import datetime
import pandas as pd
from . import DAILY_DIR
+paths = {
+ "Serenitas": ["NYops", "Margin Calls BNP"],
+ "BowdSt": ["BowdoinOps", "Margin BNP"],
+}
-def download_files(em, count: int = 20):
+
+def download_files(em, count: int = 20, *, fund="Serenitas", **kwargs):
+ if fund not in paths:
+ return
emails = em.get_msgs(
- path=["NYops", "Margin Calls BNP"],
- count=count,
- sender="bnppnycollateralmgmt@us.bnpparibas.com",
+ path=paths[fund], count=count, sender="bnppnycollateralmgmt@us.bnpparibas.com",
)
- DATA_DIR = DAILY_DIR / "BNP_reports"
+ DATA_DIR = DAILY_DIR / fund / "BNP_reports"
for msg in emails:
for attach in msg.attachments:
p = DATA_DIR / attach.name
@@ -17,22 +22,24 @@ def download_files(em, count: int = 20):
p.write_bytes(attach.content)
-def load_file(d: datetime.date, report_type: str):
+def load_file(d: datetime.date, report_type: str, fund: str):
fname = (
f"{report_type} - BNP PARIBAS - SERENITAS CREDIT GAMMA "
f"MASTER FUND, LP - COB {d:%Y%m%d}.XLS"
)
- return pd.read_excel(DAILY_DIR / "BNP_reports" / fname, skiprows=7)
+ return pd.read_excel(DAILY_DIR / fund / "BNP_reports" / fname, skiprows=7)
-def collateral(d: datetime.date, dawn_trades: pd.DataFrame, *args):
- df = load_file(d, "Collateral Positions")
+def collateral(
+ d: datetime.date, dawn_trades: pd.DataFrame, *, fund="Serenitas", **kwargs
+):
+ df = load_file(d, "Collateral Positions", fund)
if df.at[0, "Held/Posted"] == "Posted":
sign = 1.0
else:
sign = -1.0
collateral = sign * df.at[0, "Mkt Val (Agmt Ccy)"]
- df = load_file(d, "Exposure Statement")
+ df = load_file(d, "Exposure Statement", fund)
df = df[["Trade Ref", "Exposure Amount (Agmt Ccy)", "Lock Up (Agmt Ccy)"]]
df["Trade Ref"] = df["Trade Ref"].str.replace("MBO-", "")
df = df.merge(dawn_trades, how="left", left_on="Trade Ref", right_on="cpty_id")
diff --git a/python/collateral/citi.py b/python/collateral/citi.py
index bf3cee16..ce4356af 100644
--- a/python/collateral/citi.py
+++ b/python/collateral/citi.py
@@ -16,7 +16,7 @@ def load_file(d):
return pd.read_excel(fname, skiprows=6, skipfooter=2)
-def download_files(em, count=20):
+def download_files(em, count=20, **kwargs):
emails = em.get_msgs(
path=["NYops", "Margin Calls Citi"], count=count, subject__startswith="262966"
)
@@ -75,12 +75,13 @@ def get_total_collateral(d):
)
-def collateral(d, dawn_trades, *args):
+def collateral(d, dawn_trades, **kwargs):
df = load_file(d + BDay())
collat = get_total_collateral(d)
df = df[["Operations File", "Market Value", "BasicAmt"]].dropna(
subset=["Operations File"]
) # missing Operations File means assignment usually
+ # but could be a fee
df = df.merge(
dawn_trades, how="left", left_on="Operations File", right_on="cpty_id"
)
diff --git a/python/collateral/cs.py b/python/collateral/cs.py
index 24bceb2f..5fe5865e 100644
--- a/python/collateral/cs.py
+++ b/python/collateral/cs.py
@@ -4,7 +4,7 @@ from pandas.tseries.offsets import BDay
from .common import load_pdf
-def download_files(em, count=20):
+def download_files(em, count=20, **kwargs):
DATA_DIR = DAILY_DIR / "CS_reports"
emails = em.get_msgs(
path=["NYops", "Margin Calls CS"], count=count, subject__contains="DERV048829"
@@ -55,7 +55,7 @@ def get_collateral(d):
return collat
-def collateral(d, dawn_trades, *args):
+def collateral(d, dawn_trades, **kwargs):
collateral = get_collateral(d + BDay())
df = pd.read_excel(
f"/home/serenitas/Daily/CS_reports/DERV048829_{d:%b%d%Y}.xlsx",
diff --git a/python/collateral/gs.py b/python/collateral/gs.py
index 3a6ee5be..6b88069f 100644
--- a/python/collateral/gs.py
+++ b/python/collateral/gs.py
@@ -2,7 +2,7 @@ import pandas as pd
from . import DAILY_DIR
-def download_files(em, count=20):
+def download_files(em, count=20, **kwargs):
emails = em.get_msgs(
path=["NYops", "Margin calls"], count=count, subject__contains="Margin"
)
@@ -24,7 +24,7 @@ def load_file(d, pattern):
return pd.read_excel(fname, skiprows=9, skipfooter=77)
-def collateral(d, dawn_trades, *args):
+def collateral(d, dawn_trades, **kwargs):
df = load_file(d, "Collateral_Detail")
df = df.dropna(subset=["Quantity"])
try:
diff --git a/python/collateral/ms.py b/python/collateral/ms.py
index 415b92c8..c1dad7db 100644
--- a/python/collateral/ms.py
+++ b/python/collateral/ms.py
@@ -1,14 +1,24 @@
import pandas as pd
from . import DAILY_DIR
+paths = {
+ "Serenitas": ["NYops", "Margin calls MS"],
+ "Brinker": ["NYops", "Margin Calls MS-Brinker"],
+ "BowdSt": ["BowdoinOps", "Margin MS"],
+}
-def download_files(em, count=20):
+subjects = {
+ "Serenitas": "SERCX **Daily",
+ "Brinker": "061761QY1***BRINKER",
+ "BowdSt": "Margin Statement",
+}
+
+
+def download_files(em, count=20, *, fund="Serenitas", **kwargs):
emails = em.get_msgs(
- path=["NYops", "Margin calls MS"],
- count=count,
- subject__contains="SERCX **Daily",
+ path=paths[fund], count=count, subject__contains=subjects[fund],
)
- DATA_DIR = DAILY_DIR / "MS_reports"
+ DATA_DIR = DAILY_DIR / fund / "MS_reports"
for msg in emails:
for attach in msg.attachments:
if "NETSwaps" in attach.name:
@@ -22,15 +32,17 @@ def download_files(em, count=20):
p.write_bytes(attach.content)
-def collateral(d, dawn_trades, *args):
- df = pd.read_excel(DAILY_DIR / "MS_reports" / f"Collateral_Detail_{d:%Y%m%d}.xls")
+def collateral(d, dawn_trades, *, fund="Serenitas", **kwargs):
+ df = pd.read_excel(
+ DAILY_DIR / fund / "MS_reports" / f"Collateral_Detail_{d:%Y%m%d}.xls"
+ )
collat = df.loc[1, "coll_val_ccy"].replace(",", "")
if "(" in collat:
collat = collat[1:-1]
collat = -float(collat)
else:
collat = float(collat)
- df = pd.read_excel(DAILY_DIR / "MS_reports" / f"Trade_Detail_{d:%Y%m%d}.xls")
+ df = pd.read_excel(DAILY_DIR / fund / "MS_reports" / f"Trade_Detail_{d:%Y%m%d}.xls")
df = df.dropna(subset=["trade_ccy"])
df = df.merge(dawn_trades, how="left", left_on="trade_id", right_on="cpty_id")
missing_ids = df.loc[df.cpty_id.isnull(), "trade_id"]
diff --git a/python/collateral/wells.py b/python/collateral/wells.py
index d31163c3..08760d60 100644
--- a/python/collateral/wells.py
+++ b/python/collateral/wells.py
@@ -4,12 +4,12 @@ from .common import compare_notionals, STRATEGY_CASH_MAPPING
from sqlalchemy.exc import IntegrityError
-def download_files(*args):
+def download_files(*args, **kwargs):
sftp = SftpClient2.from_creds("wells")
sftp.download_files("/RECEIVE/339425_DATO2", DAILY_DIR / "Wells_reports")
-def collateral(d, positions, engine):
+def collateral(d, positions, *, engine, **kwargs):
account = "A5882186"
file_name = (
DAILY_DIR