aboutsummaryrefslogtreecommitdiffstats
path: root/python
diff options
context:
space:
mode:
Diffstat (limited to 'python')
-rw-r--r--python/quote_parsing/parse_emails.py26
1 files changed, 7 insertions, 19 deletions
diff --git a/python/quote_parsing/parse_emails.py b/python/quote_parsing/parse_emails.py
index 02d0ee94..cf499e29 100644
--- a/python/quote_parsing/parse_emails.py
+++ b/python/quote_parsing/parse_emails.py
@@ -487,31 +487,19 @@ def parse_cs(fh, indextype, series, quotedate):
option_stack = {}
fwd_index = []
d = {"quotedate": quotedate, "index": indextype, "series": series}
- regex_str = r"Ref:\s*([\d.]+)\s*Fwd: ([\d.]+)\s*Expiry: (\d{2}-\w{3}-\d{2})"
- if indextype == "IG":
- regex_str += r"\s*Fwd dv01:\s*([\d.]*).*"
- pat = re.compile(regex_str)
+ regex = {
+ "HY": r"Ref:\s*(?P<ref>[\d.]+)\s*Fwd: (?P<fwdprice>[\d.]+)\s*Expiry: (?P<expiry>\d{2}-\w{3}-\d{2})",
+ "IG": r"Ref:\s*(?P<ref>[\d.]+)\s*Fwd: (?P<fwdspread>[\d.]+)\s*Expiry: (?P<expiry>\d{2}-\w{3}-\d{2})\s*Fwd dv01:\s*(?P<fwdbpv>[\d.]*).*",
+ }
+ pat = re.compile(regex[indextype])
for line in fh:
line = line.strip()
if line.startswith("Ref"):
m = pat.match(line)
if m:
- if indextype == "IG":
- ref, fwdspread, expiry, fwdbpv = m.groups()
- expiry = pd.to_datetime(expiry, format="%d-%b-%y")
- d.update(
- {
- "ref": ref,
- "expiry": expiry,
- "fwdspread": fwd,
- "fwdbpv": fwdbpv,
- }
- )
- else:
- ref, fwdprice, expiry = m.groups()
- expiry = pd.to_datetime(expiry, format="%d-%b-%y")
- d.update({"ref": ref, "expiry": expiry, "fwdprice": fwd})
+ d.update(**m.groupdict())
+ d["expiry"] = pd.to_datetime(d["expiry"], format="%d-%b-%y")
fwd_index.append(d.copy())
option_stack[expiry] = parse_cs_block(fh, indextype)
else: