aboutsummaryrefslogtreecommitdiffstats
path: root/python/collateral/sg.py
diff options
context:
space:
mode:
Diffstat (limited to 'python/collateral/sg.py')
-rw-r--r--python/collateral/sg.py22
1 files changed, 14 insertions, 8 deletions
diff --git a/python/collateral/sg.py b/python/collateral/sg.py
index 064890b6..9aefd6e1 100644
--- a/python/collateral/sg.py
+++ b/python/collateral/sg.py
@@ -1,6 +1,12 @@
+import logging
+import pandas as pd
+import time
+
from . import DAILY_DIR
from paramiko import Transport, SFTPClient
+logger = logging.getLogger(__name__)
+
def get_sftp_client():
transport = Transport(("prmssp.amer.sgcib.com", 22))
@@ -8,7 +14,7 @@ def get_sftp_client():
return SFTPClient.from_transport(transport)
-def download_sftp_files(
+def download_files(
d=None,
report_types=[
"OTC_CASH_ACTIVITY",
@@ -46,15 +52,15 @@ def download_sftp_files(
if f not in file_list:
logger.info("File not here yet, trying again in 500s...")
logger.info(f"Try count: {retry_count}")
- sleep(500)
+ time.sleep(500)
sftp.close()
- download_sftp_files(d, report_types, retry_count + 1)
+ download_files(d, report_types, retry_count + 1)
else:
sftp.get(f"OTC/{f}", localpath=DATA_DIR / f)
sftp.close()
-def collateral(d):
+def collateral(d, engine):
df_activity = pd.read_csv(
DAILY_DIR / "SG_reports" / f"{d:%Y%m%d}_OTC_CASH_ACTIVITY.csv",
usecols=["Ticket Reference", "Record Type", "Currency", "Amount"],
@@ -85,7 +91,7 @@ def collateral(d):
del ref_entity[0]
ref_entity.columns = ["to_split", "tenor"]
ref_entity = ref_entity.join(
- ref_entity["to_split"].str.extract("(IG|HY|EUROPE)S(\d+)V(\d+)$", expand=True)
+ ref_entity["to_split"].str.extract(r"(IG|HY|EUROPE)S(\d+)V(\d+)$", expand=True)
)
del ref_entity["to_split"]
ref_entity.columns = ["tenor", "index_type", "series", "version"]
@@ -95,12 +101,12 @@ def collateral(d):
positions = pd.read_sql_query(
"SELECT security_desc, folder, notional, currency "
"FROM list_cds_positions_by_strat(%s)",
- dawn_engine,
+ engine,
params=(d.date(),),
)
instruments = positions.security_desc.str.split(expand=True)[[1, 3, 4]]
instruments.columns = ["index_type", "series", "tenor"]
- instruments.series = instruments.series.str.extract("S(\d+)")
+ instruments.series = instruments.series.str.extract(r"S(\d+)")
instruments.index_type[instruments.index_type == "EUR"] = "EU"
positions = positions.join(instruments)
del positions["security_desc"]
@@ -130,7 +136,7 @@ def collateral(d):
df_margin = df_margin.rename(columns={"SG IMR": "amount", "Currency": "currency"})
df_margin["date"] = d
try:
- df_margin.to_sql("fcm_im", dawn_engine, if_exists="append", index=False)
+ df_margin.to_sql("fcm_im", engine, if_exists="append", index=False)
except IntegrityError:
pass
df["date"] = d