aboutsummaryrefslogtreecommitdiffstats
path: root/python
diff options
context:
space:
mode:
Diffstat (limited to 'python')
-rw-r--r--python/insert_tranche_quotes.py96
1 files changed, 55 insertions, 41 deletions
diff --git a/python/insert_tranche_quotes.py b/python/insert_tranche_quotes.py
index 6d62b534..3fae9930 100644
--- a/python/insert_tranche_quotes.py
+++ b/python/insert_tranche_quotes.py
@@ -13,7 +13,7 @@ ins = quotes.insert()
def convert(x):
try:
return float(x)
- except:
+ except ValueError:
return None
tenordict = {'3': '3yr', '5': '5yr', '7':'7yr', '10':'10yr'}
@@ -57,17 +57,22 @@ def insert_quotes(year=2014):
continue
if csvdict['Ticker'] == 'CDX-NAHY':
- if csvdict['Price Bid']=='':
- continue
+ trancheupfrontbid = convert(csvdict['Price Bid'])
+ trancheupfrontask = convert(csvdict['Price Ask'])
try:
- trancheupfront = (float(csvdict['Price Bid'])+float(csvdict['Price Ask']))/2
- except ValueError:
- trancheupfront = None
+ trancheupfrontmid = (trancheupfrontbid+trancheupfrontask)/2
+ except TypeError:
+ trancheupfrontmid = None
+ running = 0 if series in [9, 10] and attach==10 else 500
d.update({'indexrefprice': float(csvdict['Ref']),
'indexrefspread': 375 if series==9 else 500,
- 'trancheupfront' : trancheupfront,
- 'trancherunning' : 0 if series in [9, 10] and attach==10 else 500,
+ 'trancheupfrontbid' : trancheupfrontbid,
+ 'trancheupfrontmid' : trancheupfrontmid,
+ 'trancheupfrontask' : trancheupfrontask,
+ 'trancherunningbid' : running,
+ 'trancherunningmid' : running,
+ 'trancherunningask' : running,
'index': 'HY'
})
@@ -75,58 +80,67 @@ def insert_quotes(year=2014):
if series>=22:
continue
+ trancheupfrontbid = convert(csvdict['Upfront Bid'])
+ trancheupfrontask = convert(csvdict['Upfront Ask'])
try:
- trancheupfront = (float(csvdict['Upfront Bid'])+float(csvdict['Upfront Ask']))/2
- except ValueError:
- trancheupfront = None
+ trancheupfrontmid = (trancheupfrontbid + trancheupfrontask)/2
+ except TypeError:
+ trancheupfrontmid = None
+ running = runningdict2[attach] if series<19 else runningdict1[attach]
try:
d.update({'indexrefspread': int(float(csvdict['Ref'])),
- 'trancheupfront' : trancheupfront,
- 'trancherunning' : runningdict2[attach] if series<19 else runningdict1[attach],
+ 'trancheupfrontbid' : trancheupfrontbid,
+ 'trancheupfrontmid' : trancheupfrontmid,
+ 'trancheupfrontask' : trancheupfrontask,
+ 'trancherunningbid' : running,
+ 'trancherunningmid' : running,
+ 'trancherunningask' : running,
'index' : 'IG'})
except KeyError:
continue
elif csvdict['Ticker'] == 'ITRAXX-Europe':
if series<=15:
if attach<=6:
- trancherunning = 500 if attach<=3 else 300
+ trancherunningbid = trancherunningmid = trancherunningask = 500 if attach<=3 else 300
+ trancheupfrontbid = convert(csvdict['Upfront Bid'])
+ trancheupfrontask = convert(csvdict['Upfront Ask'])
try:
- trancheupfront = (float(csvdict['Upfront Bid'])+float(csvdict['Upfront Ask']))/2
- except ValueError:
- trancheupfront = None
+ trancheupfrontmid = (trancheupfrontbid + trancheupfrontask)/2
+ except TypeError:
+ trancheupfrontmid = None
else:
+ trancherunningbid = convert(csvdict['Bid'])
+ trancherunningask = convert(csvdict['Ask'])
try:
- trancherunning=(float(csvdict['Bid'])+float(csvdict['Ask']))/2
- except ValueError:
+ trancherunningmid = (trancherunningbid+trancherunningask)/2
+ except TypeError:
trancherunning = None
- trancheupfront=0
- if series==19:
+ trancheupfrontbid = trancheupfrontmid = trancheupfrontask = 0
+ if series in [19, 21]:
if attach<=3:
- trancherunning = 500
+ trancherunningbid = trancherunningask = trancherunningmid = 500 if series==19 else 100
+ trancheupfrontbid = convert(csvdict['Upfront Bid'])
+ trancheupfrontask = convert(csvdict['Upfront Ask'])
try:
- trancheupfront = (float(csvdict['Upfront Bid'])+float(csvdict['Upfront Ask']))/2
- except ValueError:
- trancheupfront=None
+ trancheupfrontmid = (trancheupfrontbid + trancheupfrontask)/2
+ except TypeError:
+ trancheupfrontmid = None
else:
+ trancherunningbid = convert(csvdict['Bid'])
+ trancherunningask = convert(csvdict['Ask'])
try:
- trancherunning=(float(csvdict['Bid'])+float(csvdict['Ask']))/2
- except ValueError:
- trancherunning=(float(csvdict['Upfront Bid'])+float(csvdict['Upfront Ask']))/2
- trancheupfront = 0
- if series==21:
- if attach<=3:
- trancherunning =100
- try:
- trancheupfront = (float(csvdict['Upfront Bid'])+float(csvdict['Upfront Ask']))/2
- except ValueError:
- trancheupfront = None
- else:
- trancherunning=(float(csvdict['Bid'])+float(csvdict['Ask']))/2
- trancheupfront = 0
+ trancherunningmid = (trancherunningbid+trancherunningask)/2
+ except TypeError:
+ trancherunning = None
+ trancheupfrontbid = trancheupfrontmid = trancheupfrontask = 0
d.update({'indexrefspread': int(float(csvdict['Ref'])),
- 'trancheupfront' : trancheupfront,
- 'trancherunning' : trancherunning,
+ 'trancheupfrontbid' : trancheupfrontbid,
+ 'trancheupfrontmid' : trancheupfrontmid,
+ 'trancheupfrontask' : trancheupfrontask,
+ 'trancherunningbid' : trancherunningbid,
+ 'trancherunningmid' : trancherunningmid,
+ 'trancherunningask' : trancherunningask,
'index' : 'EU',
})
data.append(d)