aboutsummaryrefslogtreecommitdiffstats
path: root/python/intex
diff options
context:
space:
mode:
Diffstat (limited to 'python/intex')
-rw-r--r--python/intex/load_intex_collateral.py26
1 files changed, 16 insertions, 10 deletions
diff --git a/python/intex/load_intex_collateral.py b/python/intex/load_intex_collateral.py
index 60b94f89..9567d18c 100644
--- a/python/intex/load_intex_collateral.py
+++ b/python/intex/load_intex_collateral.py
@@ -26,6 +26,14 @@ def windows1252_encoder(fh):
yield line.decode('windows-1252').encode('utf-8')
def upload_data(conn, dealnames, workdate):
+ sql_fields = ["dealname", "updatedate", "name", "IssuerName", "CurrentBalance",
+ "Maturity", "AssetSubtype", "AssetType", "GrossCoupon",
+ "Spread", "Frequency", "NextPaydate", "SecondLien", "LoanXID",
+ "Cusip", "IntexPrice", "IntexPriceSource", "IntexPriceDate",
+ "FixedOrFloat", "DefaultedFlag", "CovLite", "isCDO",
+ "Liborfloor", "ReinvFlag", "Currency", "Industry", "Country"]
+ sqlstr = "INSERT INTO ET_COLLATERAL({0}) VALUES({1})".format(",".join(sql_fields),
+ ",".join(["%s"] * len(sql_fields)))
for dealname in dealnames:
basedir = os.path.join(root, "data", "Collaterals_" + workdate)
if sys.version_info[0]==2:
@@ -79,6 +87,11 @@ def upload_data(conn, dealnames, workdate):
# we take care of reinvestment asset lines
if not line['Asset Name']:
line['Asset Name'] = 'Reinv'
+ try:
+ line['Asset Maturity Date'] = datetime.datetime.strptime(line['Asset Maturity Date'],
+ '%b %d, %Y').date()
+ except ValueError:
+ line['Asset Maturity Date'] = None
r = [convertToNone(line[field]) for field in fields]
#sometimes the Asset Name is not unique (we add random tag in this case)
if r[0] in data:
@@ -111,21 +124,14 @@ def upload_data(conn, dealnames, workdate):
reinsert = True
if reinsert or not old_update_dates or updatedate not in old_update_dates:
- sql_fields = ["dealname", "updatedate", "name", "IssuerName", "CurrentBalance",
- "Maturity", "AssetSubtype", "AssetType", "GrossCoupon",
- "Spread", "Frequency", "NextPaydate", "SecondLien", "LoanXID",
- "Cusip", "IntexPrice", "IntexPriceSource", "IntexPriceDate",
- "FixedOrFloat", "DefaultedFlag", "CovLite", "isCDO",
- "Liborfloor", "ReinvFlag", "Currency", "Industry", "Country"]
- sqlstr = "INSERT INTO ET_COLLATERAL({0}) VALUES({1})".format(",".join(sql_fields),
- ",".join(["%s"] * len(sql_fields)))
with conn.cursor() as c:
try:
c.executemany(sqlstr, [(dealname, updatedate, k) + tuple(v) for k, v in data.items()])
except (psycopg2.DataError, psycopg2.IntegrityError, TypeError) as detail:
logger.error(detail)
- pdb.set_trace()
- conn.commit()
+ conn.rollback()
+ else:
+ conn.commit()
def intex_data(conn, workdate):
dealnames = [d.replace("_AD.txt", "").lower() for d in