aboutsummaryrefslogtreecommitdiffstats
path: root/python
diff options
context:
space:
mode:
Diffstat (limited to 'python')
-rw-r--r--python/collateral_calc.py26
-rw-r--r--python/env.py5
-rw-r--r--python/parse_citi_pdf.py6
3 files changed, 25 insertions, 12 deletions
diff --git a/python/collateral_calc.py b/python/collateral_calc.py
index fb4c1ccc..03418b52 100644
--- a/python/collateral_calc.py
+++ b/python/collateral_calc.py
@@ -1,8 +1,12 @@
-import os
import logging
import pandas as pd
+import sys
from db import dawn_engine
+try:
+ from env import DAILY_DIR, LOG_DIR
+except KeyError:
+ sys.exit("Please set 'DAILY_DIR' and 'LOG_DIR' in the environment")
from exchange import ExchangeMessage
from exchangelib import HTMLBody
from pathlib import Path
@@ -12,9 +16,7 @@ from paramiko import Transport, SFTPClient, RSAKey
from parse_citi_pdf import get_citi_collateral
from sqlalchemy.exc import IntegrityError
-DAILY_DIR = Path(os.environ["DAILY_DIR"])
-logging.basicConfig(filename=os.path.join(os.getenv("LOG_DIR"),
- 'collateral_calc.log'),
+logging.basicConfig(filename=LOG_DIR / 'collateral_calc.log',
level=logging.WARNING,
format='%(asctime)s %(message)s')
@@ -354,6 +356,7 @@ def gs_collateral(d, dawn_trades):
def citi_collateral(d, dawn_trades):
df = load_citi_file(d)
+ collateral = get_citi_collateral(d - BDay())
df = df[['Trade ID', 'Market Value', 'BasicAmt']]
df = df.merge(dawn_trades, how='left', left_on='Trade ID', right_on='cpty_id')
df = df.groupby('folder').sum()
@@ -361,14 +364,14 @@ def citi_collateral(d, dawn_trades):
df['Currency'] = 'USD'
df = df.reset_index()
df.columns = ['Strategy', 'Amount', 'Currency']
- df.amount *=1
+ df.Amount *= -1
df = df.append({"Strategy": "M_CSH_CASH",
- "Amount": - collateral - df.Amount.sum(),
+ "Amount": collateral - df.Amount.sum(),
"Currency": "USD"}, ignore_index=True)
return df
-def send_email(df_ms, df_baml, df_gs):
+def send_email(df_ms, df_baml, df_gs, df_citi):
pd.set_option('display.float_format', '{:.2f}'.format)
content = HTMLBody('<html><body>'
'<h3>At Morgan Stanley:</h3>'
@@ -377,9 +380,12 @@ def send_email(df_ms, df_baml, df_gs):
'{}'
'<h3>At Goldman Sachs:</h3>'
'{}'
+ '<h3>At Citi:</h3>'
+ '{}'
'</body><html>'.format(df_ms.to_html(index=False),
df_baml.to_html(index=False),
- df_gs.to_html(index=False)))
+ df_gs.to_html(index=False),
+ df_citi.to_html(index=False)))
em = ExchangeMessage()
em.send_email("IAM booking", content,
['serenitas.otc@sscinc.com'],
@@ -406,4 +412,6 @@ if __name__ == "__main__":
except FileNotFoundError as e:
logging.info(e)
df_gs = gs_collateral(d - BDay(), dawn_trades)
- send_email(df_ms, df_baml, df_gs)
+ d = pd.Timestamp.today().normalize()
+ df_citi = citi_collateral(d, dawn_trades)
+ send_email(df_ms, df_baml, df_gs, df_citi)
diff --git a/python/env.py b/python/env.py
new file mode 100644
index 00000000..8c952a11
--- /dev/null
+++ b/python/env.py
@@ -0,0 +1,5 @@
+import os
+from pathlib import Path
+
+DAILY_DIR = Path(os.environ["DAILY_DIR"])
+LOG_DIR = Path(os.environ["LOG_DIR"])
diff --git a/python/parse_citi_pdf.py b/python/parse_citi_pdf.py
index ccbcd56b..c4cfa007 100644
--- a/python/parse_citi_pdf.py
+++ b/python/parse_citi_pdf.py
@@ -1,7 +1,7 @@
import pandas as pd
import subprocess
from bs4 import BeautifulSoup
-from pathlib import Path
+from env import DAILY_DIR
def load_pdf(file_path):
proc = subprocess.run(["pdftohtml", "-xml", "-stdout", "-i",
@@ -35,9 +35,9 @@ def get_df(l, col1, col2, col3):
def get_citi_collateral(d):
try:
fname = next((DAILY_DIR / "CITI_reports").
- glob("262966_MarginNotice_*_.pdf"))
+ glob(f"262966_MarginNotice_{d.strftime('%Y%m%d')}_*.pdf"))
except StopIteration:
- raise FileNotFoundError(f"CITI file not found for date {d}")
+ raise FileNotFoundError(f"CITI file not found for date {d.date()}")
l = load_pdf(fname)
col1 = (370, 500, 70, 100)
col2 = (370, 500, 100, 500)