diff options
Diffstat (limited to 'python/parse_gs.py')
| -rw-r--r-- | python/parse_gs.py | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/python/parse_gs.py b/python/parse_gs.py index 3a14b81e..b7573717 100644 --- a/python/parse_gs.py +++ b/python/parse_gs.py @@ -3,7 +3,7 @@ import pdb import re import os -data_dir = "/home/share/CorpCDOs/data/swaptions/GS swaptions" +data_dir = "/home/share/guillaume/swaptions" all_df = {} fwd_index = [] for index in ["IG", "HY"]: @@ -15,7 +15,7 @@ for index in ["IG", "HY"]: for line in fh: line = line.decode('utf-8', 'ignore') line = line.rstrip() - m = re.search("(IG|HY)(\d{2}) 5y SWAPTION (?:♦GRANULAR♦ )?(?:UPDATE|CLOSES) - Ref\D+(.+)$", line) + m = re.search("(IG|HY)(\d{2}) 5y (?:.*)SWAPTION (?:UPDATE|CLOSES|CLOSE) - Ref\D+(.+)$", line) if m: indextype = m.groups()[0] series = int(m.groups()[1]) @@ -104,16 +104,19 @@ index_df = index_df.drop_duplicates(['quotedate', 'index', 'series', 'expiry']) from db import dbengine serenitasdb = dbengine('serenitasdb') conn = serenitasdb.raw_connection() -## first delete quotes +format_str = "INSERT INTO swaption_ref_quotes({}) VALUES({}) " \ + "ON CONFLICT DO NOTHING" +cols = index_df.columns +sqlstr = format_str.format(",".join(cols), ",".join(["%s"] * len(cols))) with conn.cursor() as c: - c.execute("DELETE FROM swaption_quotes WHERE quote_source='GS'") + c.executemany(sqlstr, index_df.itertuples(index=False)) conn.commit() -all_df.to_sql('swaption_quotes', serenitasdb, if_exists='append', index=False) -sqlstr = "INSERT INTO swaption_ref_quotes(quotedate, index, series, expiry, ref, fwdprice, fwdspread) "\ - "VALUES(%(quotedate)s, %(index)s, %(series)s, %(expiry)s, %(ref)s, %(fwdprice)s, %(fwdspread)s) " \ - "ON CONFLICT DO NOTHING" + +format_str = "INSERT INTO swaption_quotes({}) VALUES({}) ON CONFLICT DO NOTHING" +cols = all_df.columns +sqlstr = format_str.format(",".join(cols), ",".join(["%s"] * len(cols))) with conn.cursor() as c: - c.executemany(sqlstr, index_df.to_dict(orient='records')) + c.executemany(sqlstr, all_df.itertuples(index=False)) conn.commit() conn.close() |
