aboutsummaryrefslogtreecommitdiffstats
path: root/python/collateral/baml_fcm.py
diff options
context:
space:
mode:
Diffstat (limited to 'python/collateral/baml_fcm.py')
-rw-r--r--python/collateral/baml_fcm.py28
1 files changed, 19 insertions, 9 deletions
diff --git a/python/collateral/baml_fcm.py b/python/collateral/baml_fcm.py
index ff80f480..c7c892a4 100644
--- a/python/collateral/baml_fcm.py
+++ b/python/collateral/baml_fcm.py
@@ -4,14 +4,17 @@ import pandas as pd
from sqlalchemy.exc import IntegrityError
-def download_files(*args, **kwargs):
+def download_files(*args, fund="Serenitas", **kwargs):
+ if fund != "Serenitas":
+ return
sftp = SftpClient.from_creds("baml_fcm")
- sftp.download_files("outgoing", DAILY_DIR / "BAML_reports")
+ sftp.download_files("outgoing", DAILY_DIR / fund / "BAML_reports")
-def collateral(d, positions, *, engine, **kwargs):
+def collateral(d, positions, *, engine, fund="Serenitas", **kwargs):
df = pd.read_csv(
DAILY_DIR
+ / fund
/ "BAML_reports"
/ f"OTC_Open_Positions_-_Credit_-_LMCG_{d:%Y%m%d}.CSV",
usecols=[
@@ -75,13 +78,19 @@ def collateral(d, positions, *, engine, **kwargs):
"Margin Excess/Deficit",
]
df_margin = pd.read_csv(
- DAILY_DIR / "BAML_reports" / f"OTC_Moneyline_{d:%Y%m%d}.CSV",
+ DAILY_DIR / fund / "BAML_reports" / f"OTC_Moneyline_{d:%Y%m%d}.CSV",
usecols=col_names,
parse_dates=["Statement Date"],
index_col=["Statement Date"],
)
df_margin.AT = df_margin.AT.replace(
- {"Q4": "EUR", "F4": "EUR", "Q1": "USD", "F2": "USD", "9Z": "ZZZZZ",}
+ {
+ "Q4": "EUR",
+ "F4": "EUR",
+ "Q1": "USD",
+ "F2": "USD",
+ "9Z": "ZZZZZ",
+ }
)
df_margin = df_margin.set_index("AT", append=True)
df_margin = df_margin.groupby(level=(0, 1)).sum()
@@ -89,10 +98,11 @@ def collateral(d, positions, *, engine, **kwargs):
col_names.pop(2)
try:
place_holders = ",".join(["%s"] * (len(col_names) - 1))
- engine.execute(
- f"INSERT INTO fcm_moneyline VALUES(%s, 'V0NSCLMFCM', {place_holders})",
- list(df_margin[col_names].itertuples(index=False)),
- )
+ with engine.connect() as conn:
+ conn.execute(
+ f"INSERT INTO fcm_moneyline VALUES(%s, 'V0NSCLMFCM', {place_holders})",
+ list(df_margin[col_names].itertuples(index=False)),
+ )
except IntegrityError:
pass
df["date"] = d