aboutsummaryrefslogtreecommitdiffstats
path: root/python/quote_parsing/parse_emails.py
diff options
context:
space:
mode:
Diffstat (limited to 'python/quote_parsing/parse_emails.py')
-rw-r--r--python/quote_parsing/parse_emails.py21
1 files changed, 13 insertions, 8 deletions
diff --git a/python/quote_parsing/parse_emails.py b/python/quote_parsing/parse_emails.py
index 961e47b5..47a17e9e 100644
--- a/python/quote_parsing/parse_emails.py
+++ b/python/quote_parsing/parse_emails.py
@@ -408,7 +408,7 @@ subject_sg = re.compile(r"SG OPTIONS - CDX (IG|HY) S(\d{2}).* REF[^\d]*([\d.]+)"
subject_citi = re.compile(r"(?:Fwd:)?Citi Options: (IG|HY)(\d{2}) 5Y")
def parse_email(email, date_received):
- with open(email.path, "rt") as fh:
+ with email.open("rt") as fh:
subject = fh.readline().lstrip()
for source in ['BAML', 'GS', 'MS', 'NOM', 'SG', 'CITI']:
@@ -431,11 +431,12 @@ def parse_email(email, date_received):
expiration_dates = list_imm_dates(quotedate)
parse_fun = globals()[f'parse_{source.lower()}']
+ key = (quotedate, indextype, series, source)
if source in ['BAML', 'CITI']:
- return (quotedate, indextype, series), \
+ return (key, parse_fun(fh, indextype, series, quotedate))
parse_fun(fh, indextype, series, quotedate)
elif source == "GS":
- return (quotedate, indextype, series), \
+ return (key, parse_fun(fh, indextype, series, quotedate, ref))
parse_fun(fh, indextype, series, quotedate, ref)
else:
option_stack = parse_fun(fh, indextype, expiration_dates)
@@ -446,7 +447,7 @@ def parse_email(email, date_received):
'expiry': list(option_stack.keys()),
'quote_source': source})
fwd_index.set_index('quotedate', inplace=True)
- return (quotedate, indextype, series), (option_stack, fwd_index)
+ return (key, (option_stack, fwd_index))
else:
raise RuntimeError(f"can't parse subject line: {subject} for email {email.name}")
@@ -469,12 +470,16 @@ def write_todb(swaption_stack, index_data, conn):
continue
else:
try:
- df = swaption_stack.loc[(t.quotedate, t.index, t.series, t.expiry),]
+ df = swaption_stack.loc[
+ (t.quotedate, t.index, t.series, t.expiry, t.quote_source),
+ ]
except KeyError as e:
- logger.warning("missing key in swaption_stack: "
- f"{t.quotedate}, {t.index}, {t.series}, {t.expiry}")
+ logger.warning(
+ "missing key in swaption_stack: "
+ f"{t.quotedate}, {t.index}, {t.series}, {t.expiry}, {t.quote_source}"
+ )
continue
- except IndexingError:
+ except IndexError:
breakpoint()
df['ref_id'] = ref_id
c.executemany(gen_sql_str(query, "swaption_quotes", df.columns),