aboutsummaryrefslogtreecommitdiffstats
path: root/python/load_markit_data.py
diff options
context:
space:
mode:
Diffstat (limited to 'python/load_markit_data.py')
-rw-r--r--python/load_markit_data.py14
1 files changed, 8 insertions, 6 deletions
diff --git a/python/load_markit_data.py b/python/load_markit_data.py
index a58341ac..b29cfd18 100644
--- a/python/load_markit_data.py
+++ b/python/load_markit_data.py
@@ -28,6 +28,10 @@ fields = ["LoanX ID", "Issuer", "Deal Name", "Facility", "Industry", \
latestdate = cursor.execute("SELECT MAX(pricingdate) from markit_prices")
latestdate = cursor.fetchone()[0]
+sql_fields = ["LoanXID", "Issuer", "DealName", "Facility", "Industry", "SP",
+ "Moodys", "Amount", "Maturity", "Spread", "Bid", "Offer", "Depth",
+ "STM", "PricingDate"]
+
for filename in os.listdir(root):
date = datetime.datetime.strptime(filename.split("_")[2].split(".")[0], '%Y-%m-%d').date()
# only update the new data
@@ -43,7 +47,7 @@ for filename in os.listdir(root):
if line['Final Maturity'] !='':
print 'Maturity non empty'
if line['Depth'] == 'implied':
- line['Depth']=0
+ line['Depth'] = 0
try:
temp = [convertToNone(line[key]) for key in fields]
except KeyError:
@@ -51,9 +55,7 @@ for filename in os.listdir(root):
data.append(temp)
for row in data:
- cursor.execute("INSERT INTO markit_prices(LoanXID, Issuer, DealName,"
- "Facility, Industry, SP, Moodys, Amount, Maturity,"
- "Spread, Bid, Offer, Depth, STM, PricingDate)"
- "VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
- tuple(row) + (date,))
+ sqlstring = "INSERT INTO markit_prices({0}) " \
+ "VALUES({1})".format(",".join(sql_fields), ",".join(["%s"] * len(sql_fields)))
+ cursor.execute(sqlstring, tuple(row) + (date,))
conn.commit()