diff options
| -rw-r--r-- | python/load_indicative.py | 41 |
1 files changed, 28 insertions, 13 deletions
diff --git a/python/load_indicative.py b/python/load_indicative.py index 90c9ac6f..32017e37 100644 --- a/python/load_indicative.py +++ b/python/load_indicative.py @@ -46,7 +46,8 @@ def upload_cusip_data(conn, filename): try: for key in ['Curr Balance', 'Orig Balance', 'Orig Attachment Point', 'Curr Attachment Point (def at MV)', 'Orig Detachment Point', - 'Curr Detachment Point (def at MV)', 'Factor', 'Coupon', 'Floater Spread']: + 'Curr Detachment Point (def at MV)', 'Factor', 'Coupon', + 'Floater Spread/Margin']: if line[key]: line[key] = sanitize_float(line[key]) line[key] = convertToNone(line[key]) @@ -64,7 +65,7 @@ def upload_cusip_data(conn, filename): "%(Orig Balance)s, %(Curr Balance)s, %(Factor)s, %(Orig Moody)s, %(Curr Moody)s, " \ "%(Orig Attachment Point)s, %(Orig Detachment Point)s, "\ "%(Curr Attachment Point)s, %(Curr Detachment Point)s, " \ - "%(Floater Index)s, %(Floater Spread)s, %(updatedate)s)" + "%(Floater Index)s, %(Floater Spread/Margin)s, %(updatedate)s)" try: with conn.cursor() as c: c.execute(sqlstring, line) @@ -104,15 +105,17 @@ def upload_deal_data(conn, filename): if "Paid Down" in line["Latest Update"]: line["Paid Down"] = re.sub("Paid Down: ","", line["Latest Update"]) line["Latest Update"] = line["Paid Down"] - for field in ["Deal Issue Date", "Deal Termination Date", \ - "Deal Next Pay Date", "Reinv End Date", "Latest Update", "Pay Day"]: + for field in ["Deal Issue Date", "Deal Termination Date", "Reinv End Date", \ + "Latest Update", "Pay Day", "Deal First Pay Date"]: if line[field]: try: line[field] = datetime.datetime.strptime(line[field], '%b %d, %Y').date() except ValueError: pdb.set_trace() + if line["Pay Day"]: + line["Pay Day"] = line["Pay Day"].day for key in ["Collection Account Principal Balance", "Collection Account Interest Balance", - "Orig Deal Bal", "Curr Deal Bal", "Tranche Curr Bal", "Tranche Orig Bal", + "Curr Deal Bal", "Tranche Curr Bal", "CDO Pct of Assets that are Structured Finance Obligations", "CDO Defaulted Security Balance (Reported)"]: if line[key]: @@ -120,21 +123,33 @@ def upload_deal_data(conn, filename): dealname = line['Deal/Tranche ID'] line['defaultedbal'] = line["CDO Defaulted Security Balance (Reported)"] - line['Deal CUSIP List'] = line['Deal CUSIP List'].split(",") + if dealname not in deallist: + for key in ["Orig Deal Bal", "Tranche Orig Bal"]: + if line[key]: + line[key] = sanitize_float(line[key]) + if line['Deal CUSIP List']: + line['Deal CUSIP List'] = line['Deal CUSIP List'].split() + sqlstr = "INSERT INTO deal_indicative VALUES( %(Deal/Tranche ID)s, %(Deal Name)s, " \ + "%(Collateral Manager)s, %(Deal Issue Date)s, %(Deal Termination Date)s, " \ + "%(Pay Day)s, %(Reinv End Date)s, %(Deal First Pay Date)s, %(Orig Deal Bal)s, " \ + "%(Tranche Orig Bal)s, %(Deal CUSIP List)s, %(Paid Down)s)" + try: + with conn.cursor() as c: + c.execute(sqlstr, line) + except (psycopg2.DataError, KeyError) as detail: + logging.error(detail) + pdb.set_trace() if dealname not in deallist or line['Latest Update'] not in deallist[dealname]: sqlstring = \ "INSERT INTO clo_universe " \ - "VALUES (%(Deal/Tranche ID)s, %(Deal Name)s, %(Collateral Manager)s, %(Orig Deal Bal)s," \ - "%(Curr Deal Bal)s, %(Tranche Orig Bal)s, %(Tranche Curr Bal)s, %(Tranche Factor)s," \ - "%(Collection Account Principal Balance)s," \ + "VALUES (%(Deal/Tranche ID)s, %(Curr Deal Bal)s, %(Tranche Curr Bal)s, " \ + "%(Tranche Factor)s, %(Collection Account Principal Balance)s, " \ "%(Collection Account Interest Balance)s, %(CDOpercent)s, %(defaultedbal)s, " \ - "%(Coupon)s, %(Deal Issue Date)s," \ - "%(Deal Termination Date)s, %(Deal Next Pay Date)s, %(Reinv End Date)s, " \ - "%(Latest Update)s, %(Deal CUSIP List)s, %(Paid Down)s, %(Pay Day)s)" + "%(Coupon)s, %(Latest Update)s)" try: with conn.cursor() as c: c.execute(sqlstring, line) - deallist[dealname] = line['Latest Update'] + deallist[dealname] = [line['Latest Update']] except (psycopg2.DataError, KeyError) as detail: logging.error(detail) pdb.set_trace() |
