aboutsummaryrefslogtreecommitdiffstats
path: root/python/collateral_calc.py
diff options
context:
space:
mode:
Diffstat (limited to 'python/collateral_calc.py')
-rw-r--r--python/collateral_calc.py26
1 files changed, 17 insertions, 9 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)