diff options
Diffstat (limited to 'python')
| -rw-r--r-- | python/intex_scenarios.py | 35 |
1 files changed, 18 insertions, 17 deletions
diff --git a/python/intex_scenarios.py b/python/intex_scenarios.py index 21b9b78e..537650cb 100644 --- a/python/intex_scenarios.py +++ b/python/intex_scenarios.py @@ -26,13 +26,14 @@ pattern7 = re.compile("GOLDL3") reinvfloatpercentage = 85
reinvfixedpercentage = 15
-def get_reinv_assets(dealname, workdate):
+def get_reinv_assets(dealname, workdate, cursor):
d = {'REINV_TBA1': None, 'REINV_TBA2': None}
sqlstr = 'select * from et_historicaldealinfo(%s, %s) where ReinvFlag IS TRUE'
cursor.execute(sqlstr, (dealname, workdate))
reinvassets = cursor.fetchall()
for line in reinvassets:
- d[reinvassets[3]] = d[22]
+ d[line[3]] = line[22]
+ return d
def convert_reinvtoperct(d):
newd = {'REINV_TBA1': None, 'REINV_TBA2': None}
@@ -42,10 +43,10 @@ def convert_reinvtoperct(d): if d['REINV_TBA1'] == d['REINV_TBA2']: # case when we have two float or two fixed assets
newd['REINV_TBA1'] = reinvfloatpercentage
newd['REINV_TBA2'] = reinvfixedpercentage
- elif d['REINV_TBA1'] == 'Float':
+ elif d['REINV_TBA1'] == 'FLOAT':
newd['REINV_TBA1'] = reinvfloatpercentage
newd['REINV_TBA2'] = reinvfixedpercentage
- elif d['REINV_TBA1'] == 'Fixed':
+ elif d['REINV_TBA1'] == 'FIXED':
newd['REINV_TBA1'] = reinvfixedpercentage
newd['REINV_TBA2'] = reinvfloatpercentage
return newd
@@ -58,18 +59,18 @@ def generate_scenarios(workdate, dealnames, conn, cursor): reinvenddate = cursor.fetchone()[0]
if reinvenddate:
reinvenddate = reinvenddate.strftime("%Y%m%d")
- reinvflag=True
+ reinvflag = True
else:
print "missing reinvestment end date"
- reinvflag=False
- reinv_assets = get_reinv_assets(dealname, workdate)
+ reinvflag = False
+ reinv_assets = get_reinv_assets(dealname, workdate, cursor)
perct_reinv_assets = convert_reinvtoperct(reinv_assets)
basedir = os.path.join(common.root, "Scenarios", "Intex curves_" + workdate)
- with open(os.path.join(basedir, "csv", dealname + "-rollingmat"), "rb") as fh:
- rollingmat = fh.readline().rstrip()
floatreinvprices = []
fixedreinvprices = []
try:
+ with open(os.path.join(basedir, "csv", dealname + "-rollingmat"), "rb") as fh:
+ rollingmat = fh.readline().rstrip()
with open(os.path.join(basedir, "csv", dealname + "-floatreinvprices.csv"), "rb") as fhreinv:
for line in fhreinv:
floatreinvprices.append(line.rstrip("\n").split(","))
@@ -109,9 +110,9 @@ def generate_scenarios(workdate, dealnames, conn, cursor): if pattern11.match(line):
line = re.sub(pattern11, r"\1{0}\2", line).format(dealname.upper())
- if reinv_assets["REINV_TBA1"] == "Float":
+ if reinv_assets["REINV_TBA1"] == "FLOAT":
coupon = 4
- elif reinv_assets["REINV_TBA1"] == "Fixed":
+ elif reinv_assets["REINV_TBA1"] == "FIXED":
coupon = 7
line = line + \
"COUP_SPR={0}|AMORT=Bullet|USE_REINVEST_PIP=1|MAT_DATE={1}|".format(coupon,
@@ -120,9 +121,9 @@ def generate_scenarios(workdate, dealnames, conn, cursor): continue
if pattern12.match(line):
line = re.sub(pattern12, r"\1{0}\2", line).format(dealname.upper())
- if reinv_assets["REINV_TBA2"] == "Float":
+ if reinv_assets["REINV_TBA2"] == "FLOAT":
coupon = 4
- elif reinv_assets["REINV_TBA2"] == "Fixed":
+ elif reinv_assets["REINV_TBA2"] == "FIXED":
coupon = 7
line = line + \
"COUP_SPR={0}|AMORT=Bullet|USE_REINVEST_PIP=1|MAT_DATE={1}|".format(coupon,
@@ -134,19 +135,19 @@ def generate_scenarios(workdate, dealnames, conn, cursor): fh2.write(line + "\r\n")
continue
if pattern3.match(line):
- if reinv_assets['REINV_TBA1'] == 'Fixed':
+ if reinv_assets['REINV_TBA1'] == 'FIXED':
line = re.sub(pattern3, r"\1{0}\2{1}", line).format(dealname.upper(),
" ".join(fixedreinvprices[i-2]))
- elif reinv_assets['REINV_TBA1'] == 'Float':
+ elif reinv_assets['REINV_TBA1'] == 'FLOAT':
line = re.sub(pattern3, r"\1{0}\2{1}", line).format(dealname.upper(),
" ".join(floatreinvprices[i-2]))
fh2.write(line + "\r\n")
continue
if pattern4.match(line):
- if reinv_assets['REINV_TBA2'] == 'Fixed':
+ if reinv_assets['REINV_TBA2'] == 'FIXED':
line = re.sub(pattern4, r"\1{0}\2{1}", line).format(dealname.upper(),
" ".join(fixedreinvprices[i-2]))
- elif reinv_assets['REINV_TBA2'] == 'Float':
+ elif reinv_assets['REINV_TBA2'] == 'FLOAT':
line = re.sub(pattern4, r"\1{0}\2{1}", line).format(dealname.upper(),
" ".join(floatreinvprices[i-2]))
fh2.write(line + "\r\n")
|
