diff options
Diffstat (limited to 'python/load_intex_collateral.py')
| -rw-r--r-- | python/load_intex_collateral.py | 59 |
1 files changed, 30 insertions, 29 deletions
diff --git a/python/load_intex_collateral.py b/python/load_intex_collateral.py index f03fbffb..417cbee4 100644 --- a/python/load_intex_collateral.py +++ b/python/load_intex_collateral.py @@ -9,22 +9,25 @@ from db import conn, query_db import sys fields = ['Asset Name', 'Issuer', 'Contributed Balance', 'Maturity Date', \ - 'Asset Subtype', 'Asset Type', 'Gross Coupon', 'Spread', 'Frequency', \ - 'Next Paydate', 'Second Lien', 'LoanX ID', 'CUSIP', 'Market Price', \ - 'Market Price Source', 'Price Date', 'Fixed or Float', \ - 'Defaulted Flag', 'Security Sub-Category', \ - 'Structured Finance Security', 'Life Floor', 'Reinvest Collat', 'Native Currency'] + 'Asset Subtype', 'Asset Type', 'Gross Coupon', 'Gross Margin', 'Spread', \ + 'Frequency', 'Next Paydate', 'Second Lien', 'LoanX ID', 'CUSIP', + 'Market Price', 'Market Price Source', 'Price Date', 'Fixed or Float', \ + 'Defaulted Flag', 'Security Sub-Category', 'Structured Finance Security', \ + 'Life Floor', 'Reinvest Collat', 'Native Currency'] def convertToNone(s): return None if s=='' else s def sanitize_float(intex_float): - intex_float = intex_float.replace(",", "") - if "(" in intex_float: - intex_float = - float(intex_float[1:-1]) + try: + intex_float = intex_float.replace(",", "") + except AttributeError: + return intex_float else: - intex_float = float(intex_float) - return intex_float + if "(" in intex_float: + return - float(intex_float[1:-1]) + else: + return float(intex_float) def upload_data(conn, dealnames, workdate): for dealname in dealnames: @@ -39,35 +42,31 @@ def upload_data(conn, dealnames, workdate): print("LoanX ID column is missing. Probably an error in exporting from intex") pdb.set_trace() data = [] - if 'Reinvest Collat' in missingfields: - print('no reinvestment asset') - pdb.set_trace() for line in dr: for f in missingfields: line[f] = None - if 'Gross Margin' not in line: - line['Gross Margin'] = None - if line['Fixed or Float']: + try: line['Fixed or Float'] = line['Fixed or Float'].upper() - if line['LoanX ID']: line['LoanX ID'] = line['LoanX ID'].upper() + line['CUSIP'] = line['CUSIP'].upper() + except AttributeError: + pass + else: if len(line['LoanX ID']) > 8: print("dubious id found: {0}".format(line['LoanX ID'])) line['LoanX ID'] = line['LoanX ID'][:8] - # make sure the string is utf8 safe - line['Issuer'] = line['Issuer'] + if 'Reinvest Collat' not in missingfields and \ line['Reinvest Collat'].upper() == 'Y' or line['Issuer'] == '': # assume it's a reinvestment asset line['Reinvest Collat'] = True line['Issuer'] = line['ID Number'] - if 'Spread' in missingfields or not line['Spread']: + if not line['Spread']: line['Spread'] = line['Gross Margin'] for field in ['Spread', 'Gross Coupon', 'Market Price', 'Contributed Balance']: - if line[field]: - line[field] = sanitize_float(line[field]) - if line['Market Price'] is not None and line['Market Price'] == 0: + line[field] = sanitize_float(line[field]) + if line['Market Price'] == 0: line['Market Price'] = None #we store the Libor FLoor in the database, so Life Floor is really Libor Floor if line['Life Floor'] == "No limit": @@ -79,8 +78,6 @@ def upload_data(conn, dealnames, workdate): line['Life Floor'] = float('Nan') if line['CUSIP']== 'XAQ3930AAB43': line['CUSIP']='BL078321' - if line['CUSIP']: - line['CUSIP'] = line['CUSIP'].upper() r = [convertToNone(line[field]) for field in fields] if r[fields.index('CUSIP')] and len(r[fields.index('CUSIP')])>9: pdb.set_trace() @@ -110,10 +107,13 @@ def upload_data(conn, dealnames, workdate): # these next three ifs are to take care of reinvestment asset lines if not row[0]: row[0] = 'Reinv' - if row[4] and 'Reinvest' in row[4]: - row[4] = row[4].replace("Reinvest ", "") - if row[4] and len(row[4])>10: - row[4] = row[4][:9] + try: + if 'Reinvest' in row[4]: + row[4] = row[4].replace("Reinvest ", "") + if len(row[4])>10: + row[4] = row[4][:9] + except (AttributeError, TypeError): + pass sql_fields = ["dealname", "updatedate", "name", "IssuerName", "CurrentBalance", "Maturity", "AssetSubtype", "AssetType", "GrossCoupon", "Spread", "Frequency", "NextPaydate", "SecondLien", "LoanXID", @@ -141,6 +141,7 @@ def upload_data(conn, dealnames, workdate): else: conn.commit() c.close() + if __name__ == "__main__": if len(sys.argv) > 1: workdate = sys.argv[1] |
