aboutsummaryrefslogtreecommitdiffstats
path: root/python
diff options
context:
space:
mode:
Diffstat (limited to 'python')
-rw-r--r--python/quote_parsing/parse_emails.py43
1 files changed, 40 insertions, 3 deletions
diff --git a/python/quote_parsing/parse_emails.py b/python/quote_parsing/parse_emails.py
index 3e51b551..96d82115 100644
--- a/python/quote_parsing/parse_emails.py
+++ b/python/quote_parsing/parse_emails.py
@@ -134,6 +134,17 @@ def parse_refline(line):
return d
+def parse_refline_eu(line):
+ regex = r"Expiry:\s(?P<expiry>\S+)\s+Fwd:\s+(?P<fwd>\S+)\s+Fwd RBPV:\s+(?P<fwd_rbpv>\S+)"
+ m = re.match(regex, line)
+ if m := re.match(regex, line):
+ d = m.groupdict()
+ d["expiry"] = pd.to_datetime(d["expiry"], format="%d-%b-%Y")
+ else:
+ raise RuntimeError(f"can't parse refline {line}")
+ return d
+
+
def parse_baml(fh, index_desc, *args):
option_stack = {}
fwd_index = []
@@ -157,13 +168,39 @@ def parse_baml(fh, index_desc, *args):
return option_stack, fwd_index
+def parse_baml_eu(fh, index_desc, *args):
+ option_stack = {}
+ fwd_index = []
+ line = ""
+ while True:
+ if line == "":
+ try:
+ line = next(fh)
+ except StopIteration:
+ break
+ if line.startswith("BofA"):
+ df, line = parse_baml_block(fh, index_desc["index"])
+ if line == "":
+ line = next(fh)
+ if line.startswith("Expiry"):
+ d = parse_refline_eu(line)
+ d.update(index_desc)
+ option_stack[
+ (d["expiry"], index_desc["series"], index_desc["version"])
+ ] = df
+ fwd_index.append(d)
+ else:
+ line = ""
+ return option_stack, fwd_index
+
+
def parse_baml_block(fh, indextype):
next(fh) # skip header
r = []
line = ""
for line in fh:
line = line.strip()
- if line.startswith("Ref") or line == "":
+ if line.startswith("Ref") or line == "" or line.startswith("Expiry"):
break
line = re.sub("[/|]", " ", line)
vals = re.sub(" +", " ", line).rstrip().split(" ")
@@ -801,10 +838,10 @@ regex_dict = {
),
re.compile(r"(?:Fwd:){0,2}(?:BofA )?(XOVER|MAIN) S(\d{1,2}).*Ref[^\d]*([\d.]+)"): (
"BAML",
- parse_baml,
+ parse_baml_eu,
),
re.compile(
- r"[^$]*(?:\$|\€){1,2} MS (?:CDX|ITX) OPTIONS: (IG|HY|MAIN|XO|FIN SEN)(\d{2})[^-]*- REF[^\d]*([\d.]+)"
+ r"[^$]*(?:\$|\€){1,2} ? MS (?:CDX|ITX) OPTIONS: (IG|HY|MAIN|XO|FIN SEN)(\d{2})[^-]*- REF[^\d]*([\d.]+)"
): ("MS", parse_ms),
re.compile(r"(?:Fwd:)?CDX (IG|HY)(\d{2}).*- REF:[^\d]*([\d.]+)"): (
"NOM",