aboutsummaryrefslogtreecommitdiffstats
path: root/python
diff options
context:
space:
mode:
Diffstat (limited to 'python')
-rw-r--r--python/collateral/citi.py10
-rw-r--r--python/collateral/common.py8
-rw-r--r--python/collateral/jpm.py25
3 files changed, 32 insertions, 11 deletions
diff --git a/python/collateral/citi.py b/python/collateral/citi.py
index dcd6992c..25fc1b23 100644
--- a/python/collateral/citi.py
+++ b/python/collateral/citi.py
@@ -1,6 +1,6 @@
import pandas as pd
from . import DAILY_DIR
-from .common import load_pdf, get_col, next_business_day
+from .common import load_pdf, get_col, next_business_day, parse_num
def load_file(d):
@@ -28,14 +28,6 @@ def download_files(em, count=20, **kwargs):
p.write_bytes(attach.content)
-def parse_num(s):
- s = s.replace(",", "")
- if s[0] == "(":
- return -float(s[1:-1])
- else:
- return float(s)
-
-
def get_df(l, col1, col2, col3):
df = pd.DataFrame(
{"amount": get_col(l, *col2), "currency": get_col(l, *col3)},
diff --git a/python/collateral/common.py b/python/collateral/common.py
index caaaa965..aaa9d8a9 100644
--- a/python/collateral/common.py
+++ b/python/collateral/common.py
@@ -153,3 +153,11 @@ def next_business_day(d: datetime.date):
return d + datetime.timedelta(days=1)
else:
return d + datetime.timedelta(days=offset)
+
+
+def parse_num(s):
+ s = s.replace(",", "")
+ if s[0] == "(":
+ return -float(s[1:-1])
+ else:
+ return float(s)
diff --git a/python/collateral/jpm.py b/python/collateral/jpm.py
index 8a5123c2..e9f83f47 100644
--- a/python/collateral/jpm.py
+++ b/python/collateral/jpm.py
@@ -3,7 +3,7 @@ import pandas as pd
from io import BytesIO
from pikepdf import Pdf
from . import DAILY_DIR
-from .common import load_pdf
+from .common import load_pdf, get_col, parse_num
def load_file(d, fund):
@@ -37,7 +37,28 @@ def load_file(d, fund):
def get_collateral(d: datetime.date, fund):
pdf_file = load_file(d, fund)
collat_page = load_pdf(pdf_file, pages=True)[3]
- return float(get_col(pomme, 200, 300, 1000, 1100)[0].replace(",", ""))
+ return float(get_col(collat_page, 200, 300, 1000, 1100)[0].replace(",", ""))
+
+
+def load_positions(d: datetime.date, fund):
+ pdf_file = load_file(d, fund)
+ positions_page = load_pdf(pdf_file, pages=True)[4]
+ anchor = next(c for c in positions_page if c.text.startswith("Total Product Group"))
+ bottom = int(anchor["top"])
+ widths = (10, 160, 300, 350, 450, 500, 550, 600, 650, 750, 850, 950, 1000, 1200)
+ cols = [get_col(positions_page, 200, 289, l, r) for l, r in zip(widths, widths[1:])]
+
+ def combine(l):
+ return [f"{l[0]} {l[1]}", *l[2:]]
+
+ cols = [combine(c) if len(c) == 4 else c for c in cols]
+ df = pd.DataFrame({c[0]: c[1:] for c in cols})
+ for col in ["Pay Notional", "Rec Notional", "MTM Amount", "IM Amount"]:
+ df[col] = df[col].apply(parse_num)
+ for col in ["Trade Date", "Maturity Date"]:
+ df[col] = pd.to_datetime(df[col], format="%d-%b-%y")
+ df["Deal ID"] = df["Deal ID"].str.extract(r"[^-]-(.*)")
+ return df
def download_files(em, count=20, *, fund="BowdSt", **kwargs):