diff options
Diffstat (limited to 'python')
| -rw-r--r-- | python/clo_universe.py | 14 | ||||
| -rw-r--r-- | python/common.py | 22 | ||||
| -rw-r--r-- | python/cusip_universe.py | 37 | ||||
| -rw-r--r-- | python/facility_download.py | 7 | ||||
| -rw-r--r-- | python/facility_update.py | 4 | ||||
| -rw-r--r-- | python/intex_scenarios.py | 41 | ||||
| -rw-r--r-- | python/load_bloomberg_data.py | 21 | ||||
| -rw-r--r-- | python/load_intex_collateral.py | 30 | ||||
| -rw-r--r-- | python/load_markit_data.py | 11 | ||||
| -rw-r--r-- | python/markit_download.py | 20 | ||||
| -rw-r--r-- | python/monitor.py | 5 | ||||
| -rw-r--r-- | python/query_runner.py | 12 |
12 files changed, 126 insertions, 98 deletions
diff --git a/python/clo_universe.py b/python/clo_universe.py index 03904c53..8c37cd5a 100644 --- a/python/clo_universe.py +++ b/python/clo_universe.py @@ -7,7 +7,7 @@ import pdb import re import sys import common -import psycopg2 +from common import query_db def convertToNone(s): return None if s=="-" or s=="" or s == "NR" else s @@ -20,13 +20,14 @@ def sanitize_float(intex_float): intex_float = float(intex_float) return intex_float -def upload_data(workdate, conn, cursor): - cursor.execute("select dealname, max(\"Latest Update\") from clo_universe group by dealname") - deallist = dict(cursor.fetchall()) +def upload_data(workdate, conn): + sqlstr = "select dealname, max(\"Latest Update\") from clo_universe group by dealname" + deallist = dict(query_db(sqlstr, one=False)) universe = os.path.join("data", "clo_universe_intex_" + workdate + ".txt") with open( os.path.join(common.root, universe), "r") as fh: dr = csv.DictReader(fh, dialect='excel-tab') data = [] + c = conn.cursor() for line in dr: if not line ['Deal Name'] or (line['Deal Name'] == 'Unknown Security'): continue @@ -66,7 +67,7 @@ def upload_data(workdate, conn, cursor): "%(Deal Termination Date)s, %(Deal Next Pay Date)s," \ "%(Reinv End Date)s, %(Latest Update)s, %(Deal CUSIP List)s, %(Paid Down)s)" try: - cursor.execute(sqlstring, line) + c.execute(sqlstring, line) deallist[dealname] = line['Latest Update'] except psycopg2.DataError as detail: print(detail) @@ -81,7 +82,6 @@ if __name__ == "__main__": workdate = sys.argv[1] else: workdate = str(datetime.date.today()) - upload_data(workdate, common.conn, common.cursor) - common.cursor.close() + upload_data(workdate, common.conn) common.conn.close() print("done") diff --git a/python/common.py b/python/common.py index a194b09b..f0cc3fdf 100644 --- a/python/common.py +++ b/python/common.py @@ -10,4 +10,24 @@ conn = psycopg2.connect(database="ET", user="et_user", password="Serenitas1", host="debian") -cursor = conn.cursor() + +def query_db(sqlstr, **kwargs): + c = conn.cursor() + params = kwargs.get('params', None) + one = kwargs.get('one', True) + try: + if params: + c.execute(sqlstr, params) + else: + c.execute(sqlstr) + except psycopg2.Error: + c.close() + conn.rollback() + return None + + if one: + result = c.fetchone() + else: + result = c.fetchall() + c.close() + return result diff --git a/python/cusip_universe.py b/python/cusip_universe.py index b8d2d100..15102f2b 100644 --- a/python/cusip_universe.py +++ b/python/cusip_universe.py @@ -7,6 +7,7 @@ import csv import pdb import sys import common +from common import query_db def convertToNone(s): return None if s=="" else s @@ -21,13 +22,14 @@ def sanitize_float(intex_float): intex_float = float(intex_float) return intex_float -def upload_data(workdate, conn, cursor): +def upload_data(workdate, conn): dealupdate = {} for cusip_universe_file in os.listdir(os.path.join(common.root, "data", "Trinfo_" + workdate)): with open( os.path.join(common.root, "data", "Trinfo_" + workdate, cusip_universe_file), "r") as fh: dr = csv.DictReader(fh, dialect='excel-tab') data = [] deals_to_update = [] + c = conn.cursor() for line in dr: if "ISIN" not in line: line['ISIN'] = None @@ -39,12 +41,12 @@ def upload_data(workdate, conn, cursor): dealname = line['dealname'] line = {k: convertToNone(v) for k, v in line.items()} if dealname not in dealupdate: - cursor.execute("SELECT \"Latest Update\" FROM clo_universe " \ - "WHERE dealname = %s ORDER BY \"Latest Update\" DESC", (dealname,)) - dealupdate[dealname] = cursor.fetchone()[0] + dealupdate[dealname] = query_db("SELECT \"Latest Update\" FROM clo_universe " \ + "WHERE dealname = %s ORDER BY \"Latest Update\" DESC", + params = (dealname,))[0] + sqlstring = "SELECT updatedate FROM latest_cusip_universe WHERE cusip = %s" - cursor.execute(sqlstring, (line['CUSIP'],)) - curr_date = cursor.fetchone() + curr_date = query_db(sqlstring, params = (line['CUSIP'],)) if not curr_date or curr_date[0] < dealupdate[dealname]: if dealname not in deals_to_update: deals_to_update.append(dealname) @@ -71,23 +73,21 @@ def upload_data(workdate, conn, cursor): "%(Curr Detachment Point)s, %(Floater Index)s, %(Floater Spread)s, " \ "%(updatedate)s)" try: - cursor.execute(sqlstring, line) + c.execute(sqlstring, line) except psycopg2.DataError: pdb.set_trace() print("uploaded: {0}".format(line['CUSIP'])) conn.commit() + for dealname in deals_to_update: - try: - cursor.execute("SELECT p_cusip, p_curr_subordination, "\ - "p_curr_thickness from et_deal_subordination(%s)", - (dealname,)) - except psycopg2.DataError: - pdb.set_trace() - data = cursor.fetchall() + data = query_db("SELECT p_cusip, p_curr_subordination, "\ + "p_curr_thickness from et_deal_subordination(%s)", + params = (dealname,), + one = False) data = [ (t[1], t[2], t[0], dealupdate[dealname]) for t in data] - cursor.executemany("UPDATE cusip_universe SET subordination = %s, " - "thickness = %s WHERE cusip = %s AND " - "updatedate = %s", data) + c.executemany("UPDATE cusip_universe SET subordination = %s, " + "thickness = %s WHERE cusip = %s AND " + "updatedate = %s", data) conn.commit() if __name__=="__main__": @@ -96,6 +96,5 @@ if __name__=="__main__": else: workdate = str(datetime.date.today()) - upload_data(workdate, common.conn, common.cursor) - common.cursor.close() + upload_data(workdate, common.conn) common.conn.close() diff --git a/python/facility_download.py b/python/facility_download.py index b189f536..f56dae7c 100644 --- a/python/facility_download.py +++ b/python/facility_download.py @@ -1,6 +1,7 @@ import requests
import os
import common
+from common import query_db
legal = 'serecap'
username = 'serecapuser'
@@ -22,11 +23,12 @@ flag = False # fh.write(r.content.split('\n')[1] + "\n")
# flag = True
+
sqlstring = "select loanxid from markit_prices2 except (select loanxid from latest_markit_prices2)"
-common.cursor.execute(sqlstring)
+loan_ids = query_db(sqlstring, one=False)
with open( os.path.join(common.root, "data", "Facility files",
"facility_test.csv"), "wb") as fh:
- for loanxid in common.cursor.fetchall():
+ for loanxid in loan_ids:
r = requests.get('https://loans.markit.com/loanx/LoanXOneFacility.csv?LEGALENTITY={0}&USERNAME={1}&PASSWORD={2}&LOANXID={3}'.format(legal, username, password, loanxid[0]))
if flag:
fh.write(r.content.split('\n')[1] + "\n")
@@ -35,5 +37,4 @@ with open( os.path.join(common.root, "data", "Facility files", fh.write(r.content.split('\n')[1] + "\n")
flag = True
-common.cursor.close()
common.conn.close()
diff --git a/python/facility_update.py b/python/facility_update.py index 9d2f234a..95d38064 100644 --- a/python/facility_update.py +++ b/python/facility_update.py @@ -52,10 +52,10 @@ with open( filename, "wb") as fh: with open( filename, "r") as fh:
reader = csv.reader(fh)
reader.next()
+ c = common.conn.cursor()
sqlstring = "INSERT INTO markit_facility VALUES( {0} )".format( ",".join(["%s"] * 13))
for line in reader:
newline = [convertToNone(v) for v in line]
- common.cursor.execute(sqlstring, newline)
+ c.execute(sqlstring, newline)
common.conn.commit()
-common.cursor.close()
common.conn.close()
diff --git a/python/intex_scenarios.py b/python/intex_scenarios.py index e948ead5..fa5268d1 100644 --- a/python/intex_scenarios.py +++ b/python/intex_scenarios.py @@ -7,6 +7,7 @@ import json import re
import psycopg2
import common
+from common import query_db, root
import sys
import yaml
@@ -24,49 +25,50 @@ pattern9 = re.compile("(?P<a>SEVERITY\[\w+,\d+\]=)mkt\(70\)") global_reinvfloatpercentage = 84
global_reinvfixedpercentage = 16
-def get_reinv_assets(dealname, workdate, cursor):
+def get_reinv_assets(dealname, workdate):
sqlstr = 'select * from et_historicaldealinfo(%s, %s) where ReinvFlag IS TRUE'
- cursor.execute(sqlstr, (dealname, workdate))
- reinvassets = cursor.fetchall()
+ reinvassets = query_db(sqlstr, params = (dealname, workdate), one = False)
d = {}
for line in reinvassets:
d[line[3]] = line[22]
return d
-def get_recovery(dealname, workdate, cursor):
+def get_recovery(dealname, workdate, defaultrecovery = 50):
""" compute average price of defaulted assets
"""
- defaultrecovery = 50
- sqlstr = "select sum(coalesce(price, {0}) * currentbalance)/sum(currentbalance) ".format(defaultrecovery) + \
+ sqlstr = "select sum(coalesce(price, %s) * currentbalance)/sum(currentbalance) " + \
"from et_aggdealinfo_historical(%s, %s) where defaultedflag is True"
- cursor.execute(sqlstr, (dealname, workdate))
- recovery = cursor.fetchone()[0]
+
+ recovery = query_db(sqlstr, params = (defaultrecovery, dealname, workdate))
+
if not recovery:
- recovery = 50
+ recovery = defaultrecovery
+ else:
+ recovery = recovery[0]
return float(recovery)
-def get_reinvenddate(dealname, cursor):
- cursor.execute('SELECT \"Reinv End Date\" from latest_clo_universe where dealname=%s', (dealname,))
- reinvenddate = cursor.fetchone()[0]
+def get_reinvenddate(dealname):
+ sqlstr = 'SELECT \"Reinv End Date\" from latest_clo_universe where dealname=%s'
+ reinvenddate = query_db(sqlstr, params = (dealname,))[0]
if reinvenddate:
reinvenddate = reinvenddate.strftime("%Y%m%d")
return reinvenddate
else:
raise Exception("missing reinvestment end date")
-def generate_scenarios(workdate, dealnames, conn, cursor):
- prometheus = os.path.join(common.root, "Scenarios", "prometheus.sss")
+def generate_scenarios(workdate, dealnames):
+ prometheus = os.path.join(root, "Scenarios", "prometheus.sss")
n_scenarios = 100
- basedir = os.path.join(common.root, "Scenarios", "Intex curves_" + workdate)
+ basedir = os.path.join(root, "Scenarios", "Intex curves_" + workdate)
for dealname in dealnames:
- defaultedprice = get_recovery(dealname, workdate, cursor)
+ defaultedprice = get_recovery(dealname, workdate)
replace = "\g<a>{0:.3f}".format(defaultedprice)
with open(os.path.join(basedir, "csv", dealname + ".config")) as fh:
config = yaml.load(fh)
reinvflag = config['reinvflag']
if reinvflag:
- reinvenddate = get_reinvenddate(dealname, cursor)
- reinv_assets = get_reinv_assets(dealname, workdate, cursor)
+ reinvenddate = get_reinvenddate(dealname)
+ reinv_assets = get_reinv_assets(dealname, workdate)
n_float_assets = len([v for v in reinv_assets.values() if v == 'FLOAT'])
n_fixed_assets = len([v for v in reinv_assets.values() if v == 'FIXED'])
rollingmat = config['rollingmat']
@@ -221,6 +223,5 @@ if __name__ == "__main__": os.listdir(os.path.join(common.root, "Scenarios",
"Intex curves_" + workdate, "csv"))
if "RData" in d]
- generate_scenarios(workdate, dealnames, common.conn, common.cursor)
- common.cursor.close()
+ generate_scenarios(workdate, dealnames)
common.conn.close()
diff --git a/python/load_bloomberg_data.py b/python/load_bloomberg_data.py index d7b453cb..a03e609a 100644 --- a/python/load_bloomberg_data.py +++ b/python/load_bloomberg_data.py @@ -17,11 +17,14 @@ fields_mtge = ["Cusip", "Issuer", "Maturity", "Coupon", "CouponType", "Frequency root = os.path.join(common.root, "data", "bloomberg")
for filename in os.listdir(root):
- common.cursor.execute("select cusip, pricingdate from historical_bloomberg_corp(%s)", (date.today(),))
- corpcusips = dict(common.cursor)
+ c = common.cursor()
+ c.execute("select cusip, pricingdate from historical_bloomberg_corp(%s)", (date.today(),))
+ corpcusips = dict(c)
+ c.close()
with open( os.path.join(root, filename), "r") as fh:
dr = csv.DictReader(fh)
if "datacorp" in filename:
+ c = common.conn.cursor()
for line in dr:
if line["LAST_UPDATE_DT"] != 'NA':
line["LAST_UPDATE_DT"] = \
@@ -39,13 +42,16 @@ for filename in os.listdir(root): sqlstring = "INSERT INTO bloomberg_corp({0}) " \
"VALUES({1})".format(",".join(fields_corp), ",".join(["%s"] * len(fields_corp)))
try:
- common.cursor.execute(sqlstring, tuple(row))
+ c.execute(sqlstring, tuple(row))
except IndexError:
pdb.set_trace()
- common.conn.commit()
+ common.conn.commit()
+ c.close()
+
elif "datamtge" in filename:
- common.cursor.execute("select * from bloomberg_mtge")
- mtgecusips = {record[0]: None for record in common.cursor}
+ c = common.cursor()
+ c.execute("select * from bloomberg_mtge")
+ mtgecusips = {record[0]: None for record in c}
for line in dr:
if line["MATURITY"] != 'NA':
line["MATURITY"] = datetime.datetime.strptime(line["MATURITY"], '%Y-%m-%d').date()
@@ -57,9 +63,8 @@ for filename in os.listdir(root): sqlstring = "INSERT INTO bloomberg_mtge({0}) " \
"VALUES({1})".format(",".join(fields_mtge),
",".join(["%s"] * len(fields_mtge)))
- common.cursor.execute(sqlstring, tuple(row))
+ c.execute(sqlstring, tuple(row))
common.conn.commit()
-common.cursor.close()
common.conn.close()
print("done")
diff --git a/python/load_intex_collateral.py b/python/load_intex_collateral.py index 60aabbdd..c2cb9c19 100644 --- a/python/load_intex_collateral.py +++ b/python/load_intex_collateral.py @@ -5,6 +5,7 @@ import csv import datetime import pdb import common +from common import query_db import sys fields = ['Asset Name', 'Issuer', 'Contributed Balance', 'Maturity Date', \ @@ -33,12 +34,13 @@ def get_latest_dealupdate(workdate): for line in dr if 'Paid' not in line['Latest Update'] and line['Latest Update']} return deal_table -def upload_data(dealnames, workdate, conn, cursor): +def upload_data(dealnames, workdate, conn): for dealname in dealnames: #dealname, updatedate = line.rstrip().split() # updatedate = datetime.datetime.strptime(updatedate, '%m/%d/%Y') #dealname = dealname.upper() + ",AD.txt - with open( os.path.join(common.root, "data", "Collaterals_" + workdate, dealname.upper() + "_AD.txt"), "r", encoding='windows-1252') as fh: + with open( os.path.join(common.root, "data", "Collaterals_" + workdate, dealname.upper() + "_AD.txt"), + "r", encoding='windows-1252') as fh: dr = csv.DictReader(fh, dialect = 'excel-tab') missingfields = set(fields) - set(dr.fieldnames) if "LoanX ID" in missingfields: @@ -92,8 +94,8 @@ def upload_data(dealnames, workdate, conn, cursor): pdb.set_trace() data.append(r) - cursor.execute( "select distinct(updatedate) from et_collateral where dealname= %s", (dealname,)) - old_update_dates = [date[0] for date in cursor.fetchall()] + sqlstr = "select distinct(updatedate) from et_collateral where dealname= %s" + old_update_dates = [date[0] for date in query_db(sqlstr, params=(dealname,), one=False)] deal_table = get_latest_dealupdate(workdate) try: @@ -105,16 +107,18 @@ def upload_data(dealnames, workdate, conn, cursor): reinsert = False if updatedate in old_update_dates: sqlstr = "SELECT count(*) FROM et_collateral where dealname = %s and updatedate= %s" - cursor.execute(sqlstr, (dealname, updatedate)) - currlen = cursor.fetchone()[0] + currlen = query_db(sqlstr, params = (dealname, updatedate))[0] if currlen != len(data): print("{0} has {1} rows in the database and current collateral file has {2}".format(dealname, currlen, len(data))) + c = conn.cursor() sqlstr = "DELETE FROM et_collateral where dealname = %s and updatedate = %s" - cursor.execute(sqlstr, (dealname, updatedate)) + c.execute(sqlstr, (dealname, updatedate)) conn.commit() + c.close() reinsert = True if reinsert or not old_update_dates or updatedate not in old_update_dates: tag = 0 + c = conn.cursor() for row in data: # these next three ifs are to take care of reinvestment asset lines if not row[0]: @@ -132,7 +136,7 @@ def upload_data(dealnames, workdate, conn, cursor): sqlstr = "INSERT INTO ET_COLLATERAL({0}) VALUES({1})".format(",".join(sql_fields), ",".join(["%s"] * len(sql_fields))) try: - cursor.execute(sqlstr, (dealname, updatedate) + tuple(row)) + c.execute(sqlstr, (dealname, updatedate) + tuple(row)) except psycopg2.DataError as detail: print(detail) pdb.set_trace() @@ -143,11 +147,11 @@ def upload_data(dealnames, workdate, conn, cursor): # make sure the loan name is unique by tagging it row[0] = row[0] + "_tag_" + str(tag) tag = tag + 1 - cursor.execute(sqlstr, (dealname, updatedate) + tuple(row)) + c.execute(sqlstr, (dealname, updatedate) + tuple(row)) except TypeError: pdb.set_trace() conn.commit() - + c.close() if __name__ == "__main__": if len(sys.argv) > 1: workdate = sys.argv[1] @@ -156,8 +160,8 @@ if __name__ == "__main__": if len(sys.argv) > 2: dealnames = sys.argv[2:] else: - dealnames = [re.sub("_AD.txt", "", d).lower() for d in os.listdir(os.path.join(common.root, "data", "Collaterals_" + workdate))] - upload_data(dealnames, workdate, common.conn, common.cursor) - common.cursor.close() + dealnames = [re.sub("_AD.txt", "", d).lower() for d in + os.listdir(os.path.join(common.root, "data", "Collaterals_" + workdate))] + upload_data(dealnames, workdate, common.conn) common.conn.close() print("done") diff --git a/python/load_markit_data.py b/python/load_markit_data.py index 892bf2e5..7c7810a8 100644 --- a/python/load_markit_data.py +++ b/python/load_markit_data.py @@ -14,8 +14,10 @@ fields = ["LoanX ID", "Issuer", "Deal Name", "Facility", "Industry", \ "Final Maturity", "Initial Spread", "Bid", "Offer", "Depth", \ "Spread To Maturity"] -latestdate = common.cursor.execute("SELECT MAX(pricingdate) from markit_prices") -latestdate = common.cursor.fetchone()[0] +c = common.conn.cursor() +c.execute("SELECT MAX(pricingdate) from markit_prices") +latestdate = c.fetchone()[0] +c.close() sql_fields = ["LoanXID", "Issuer", "DealName", "Facility", "Industry", "SP", "Moodys", "Amount", "Maturity", "Spread", "Bid", "Offer", "Depth", @@ -43,11 +45,12 @@ for filename in os.listdir(os.path.join(root, "data", "markit")): pdb.set_trace() data.append(temp) + c = common.conn.cursor() for row in data: sqlstring = "INSERT INTO markit_prices({0}) " \ "VALUES({1})".format(",".join(sql_fields), ",".join(["%s"] * len(sql_fields))) - common.cursor.execute(sqlstring, tuple(row) + (date,)) + c.execute(sqlstring, tuple(row) + (date,)) common.conn.commit() -common.cursor.close() + c.close() common.conn.close() print("done") diff --git a/python/markit_download.py b/python/markit_download.py index 63bd7483..07bce90c 100644 --- a/python/markit_download.py +++ b/python/markit_download.py @@ -28,29 +28,35 @@ sqlstring = "INSERT INTO markit_prices2 VALUES( {0} )".format( ",".join([ "%s" ] with open(marks_filename, "r") as fh:
reader = csv.reader(fh)
reader.next() # we skip the headers
+ c = common.conn.cursor()
for line in reader:
if line[4] == "implied":
line[4] = 0
- common.cursor.execute(sqlstring, (line[0], line[2], line[3], line[4], line[1]))
+ c.execute(sqlstring, (line[0], line[2], line[3], line[4], line[1]))
common.conn.commit()
+c.close()
sqlstring = "INSERT INTO markit_facility VALUES( {0} )".format( ",".join(["%s"] * 13))
with open( facility_filename, "r") as fh:
reader = csv.reader(fh)
reader.next() # we skip the headers
+ c = common.conn.cursor()
for line in reader:
newline = [convertToNone(v) for v in line]
- common.cursor.execute(sqlstring, newline)
+ c.execute(sqlstring, newline)
common.conn.commit()
+c.close()
#we update the missing facility loanxids
+c = common.conn.cursor()
sqlstring = "SELECT loanxid FROM markit_prices2 EXCEPT SELECT loanxid FROM markit_facility";
-common.cursor.execute(sqlstring)
+c.execute(sqlstring)
+
facility_diff_filename = os.path.join(common.root, "data", "Facility files",
"facility_diff_{0}.csv".format(workdate))
with open( facility_diff_filename, "wb") as fh:
flag = False
- for loanxid in common.cursor.fetchall():
+ for loanxid in c.fetchall():
r = requests.get('https://loans.markit.com/loanx/LoanXOneFacility.csv?LEGALENTITY={0}&USERNAME={1}&PASSWORD={2}&LOANXID={3}'.format(legal, username, password, loanxid[0]))
if flag:
fh.write(r.content.split('\n')[1] + "\n")
@@ -58,10 +64,12 @@ with open( facility_diff_filename, "wb") as fh: fh.write(r.content.split('\n')[0] + "\n")
fh.write(r.content.split('\n')[1] + "\n")
flag = True
+c.close()
sqlstring = "INSERT INTO markit_facility(LoanXID, PMDID, IssuerName, dealname, facility_type," \
"loanx_facility_type, initial_amount, initial_spread, maturity, industry, modified_time)" \
"VALUES( {0} )".format( ",".join( ["%s"] * 11))
+c = common.conn.cursor()
if os.path.getsize(facility_diff_filename):
with open(facility_diff_filename, "r") as fh:
reader = csv.reader(fh)
@@ -69,8 +77,8 @@ if os.path.getsize(facility_diff_filename): for line in reader:
newline = [convertToNone(v) for v in line] + [workdate]
newline.pop(9) # remove the spread to maturity value
- common.cursor.execute(sqlstring, newline)
+ c.execute(sqlstring, newline)
common.conn.commit()
+c.close()
-common.cursor.close()
common.conn.close()
diff --git a/python/monitor.py b/python/monitor.py index 1f6001af..a40ad0ee 100644 --- a/python/monitor.py +++ b/python/monitor.py @@ -1,8 +1,8 @@ import os import time import subprocess -import common import datetime +import common from intex_scenarios import generate_scenarios Rpath = os.path.join(common.root, "code", "R") @@ -22,7 +22,6 @@ while True: with open(os.path.join(logpath, "build_scenarios.Rout"), "w") as fh: p = subprocess.Popen(args2, stderr = subprocess.STDOUT, stdout = fh) p.wait() - generate_scenarios(workdate, dealnames, common.conn, common.cursor) + generate_scenarios(workdate, dealnames) time.sleep(3) -common.cursor.close() common.conn.close() diff --git a/python/query_runner.py b/python/query_runner.py deleted file mode 100644 index 45595f98..00000000 --- a/python/query_runner.py +++ /dev/null @@ -1,12 +0,0 @@ -import psycopg2 -conn = psycopg2.connect(database="ET", user="guillaume") -cursor = conn.cursor() - -# cursor.execute("select select a.name,a.issuername,a.loanxid,b.bid from et_collateral a left outer join markit_prices b on a.loanxid=b.loanxid where a.dealname='octagon8'") -cursor.execute("select a.name, COALESCE(b.bid,c.price) as price, a.currentbalance from et_collateral a left outer join markit_prices b on a.loanxid=b.loanxid left outer join bloomberg_prices c on a.cusip=c.cusip where a.dealname='octagon8'") - -for line in cursor: - # import pdb;pdb.set_trace() - print "\t".join(map(str,line)) -cursor.close() -conn.close() |
