diff options
| -rw-r--r-- | python/quote_parsing/parse_emails.py | 42 |
1 files changed, 25 insertions, 17 deletions
diff --git a/python/quote_parsing/parse_emails.py b/python/quote_parsing/parse_emails.py index e5e332e7..b22a3fcc 100644 --- a/python/quote_parsing/parse_emails.py +++ b/python/quote_parsing/parse_emails.py @@ -674,21 +674,29 @@ def parse_jpm(fh, index_desc): # subject_baml = re.compile(r"(?:Fwd:){0,2}(?:BAML )?(\D{2})(\d{1,2})\s") -subject_baml = re.compile(r"(?:Fwd:){0,2}(?:BofA )?(\D{2})(\d{1,2}).*Ref[^\d]*([\d.]+)") -subject_ms = re.compile( - r"[^$]*\${1,2} MS CDX OPTIONS: (IG|HY)(\d{2})[^-]*- REF[^\d]*([\d.]+)" -) -subject_nom = re.compile(r"(?:Fwd:)?CDX (IG|HY)(\d{2}).*- REF:[^\d]*([\d.]+)") -subject_gs = re.compile(r"(?:FW: |Fwd: )?GS (IG|HY)(\d{2}) 5y.*- Ref [^\d]*([\d.]+)") -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") -subject_cs = re.compile( - r"CS CDX (?P<index>IG|HY)(?P<series>\d{2})_?v?(?P<version>\d)? Options -\s+(?:\d{2}/\d{2}/\d{2}\s+)?Ref = (?P<ref>[\d.]+)[^\d]*" -) -subject_bnp = re.compile(r"CDX OPTIONS RUN: (IG|HY)(\d{2}).*") -subject_jpm = re.compile( - r"JPM (?:CDX|iTrx) Options: (?:CDX|ITRAXX).(IG|HY|XOVER|MAIN) S(\d+) 5Y (?:V2&V1 )?\S+-\S+ \[ref ([\d.]*)\].*" -) + +regex_dict = { + ("BAML", "US"): re.compile( + r"(?:Fwd:){0,2}(?:BofA )?(\D{2})(\d{1,2}).*Ref[^\d]*([\d.]+)" + ), + ("MS", "US"): re.compile( + r"[^$]*\${1,2} MS CDX OPTIONS: (IG|HY)(\d{2})[^-]*- REF[^\d]*([\d.]+)" + ), + ("NOM", "US"): re.compile(r"(?:Fwd:)?CDX (IG|HY)(\d{2}).*- REF:[^\d]*([\d.]+)"), + ("GS", "US"): re.compile( + r"(?:FW: |Fwd: )?GS (IG|HY)(\d{2}) 5y.*- Ref [^\d]*([\d.]+)" + ), + ("SG", "US"): re.compile(r"SG OPTIONS - CDX (IG|HY) S(\d{2}).* REF[^\d]*([\d.]+)"), + ("CITI", "US"): re.compile(r"(?:Fwd:)?Citi Options: (IG|HY)(\d{2}) 5Y"), + ("CS", "US"): re.compile( + r"CS CDX (?P<index>IG|HY)(?P<series>\d{2})_?v?(?P<version>\d)? Options -\s+(?:\d{2}/\d{2}/\d{2}\s+)?Ref = (?P<ref>[\d.]+)[^\d]*" + ), + ("BNP", "US"): re.compile(r"CDX OPTIONS RUN: (IG|HY)(\d{2}).*"), + # JPM works on both europe and us so we won't need to make changes + ("JPM", "USEU"): re.compile( + r"JPM (?:CDX|iTrx) Options: (?:CDX|ITRAXX).(IG|HY|XOVER|MAIN) S(\d+) 5Y (?:V2&V1 )?\S+-\S+ \[ref ([\d.]*)\].*" + ), +} def get_current_version(index, series, d, conn): @@ -707,8 +715,8 @@ def parse_email(email: Path, date_received: datetime.date, conn): with email.open("rt") as fh: subject = fh.readline().lstrip() - for source in ["BAML", "GS", "MS", "NOM", "SG", "CITI", "CS", "BNP", "JPM"]: - if (m := globals()[f"subject_{source.lower()}"].match(subject)) : + for (source, region), regex in regex_dict.items(): + if (m := regex.match(subject)) : version = None if source in ["CITI", "BNP"]: indextype, series = m.groups() |
