aboutsummaryrefslogtreecommitdiffstats
path: root/python
diff options
context:
space:
mode:
Diffstat (limited to 'python')
-rw-r--r--python/intex_scenarios.py90
1 files changed, 78 insertions, 12 deletions
diff --git a/python/intex_scenarios.py b/python/intex_scenarios.py
index abdc9b49..da1fdfb8 100644
--- a/python/intex_scenarios.py
+++ b/python/intex_scenarios.py
@@ -5,7 +5,9 @@ from datetime import date
from csv import reader
import json
import codecs
-import pdb
+import re
+import psycopg2
+
if os.name =='nt':
root = "//WDsentinel/share/CorpCDOs/Scenarios"
@@ -13,10 +15,40 @@ elif os.name == 'posix':
root = '/home/share/CorpCDOs/Scenarios'
input = os.path.join(root, "prometheus.sss")
+pattern1 = re.compile("(REINVEST\[)\w+(::.*$)")
+# maturity
+pattern2 = re.compile("(STANDARD_VAR\[)\w+(::#REINV_END,\d+\]=)(\d*$)")
+# reinvprices float
+pattern3 = re.compile("(STANDARD_VAR\[)\w+(::#PRICE100_TBA1,\d+\]=)(.*$)")
+# reinvprices fixed
+pattern4 = re.compile("(STANDARD_VAR\[)\w+(::#PRICE100_TBA2,\d+\]=)(.*$)")
+# reinv float percentage
+pattern5 = re.compile("(STANDARD_VAR\[)\w+(::#REINVPCT_TBA1,\d+\]=)(.*$)")
+# reinv fixed percentage
+pattern6 = re.compile("(STANDARD_VAR\[)\w+(::#REINVPCT_TBA2,\d+\]=)(.*$)")
+pattern7 = re.compile("GOLDL5")
+
+reinvfloatpercentage = 85
+reinvfixedpercentage = 15
+
+conn = psycopg2.connect(database="ET",
+ user="et_user",
+ password="Serenitas1",
+ host="192.168.1.108")
+cursor = conn.cursor()
+
+maturity = "20141017"
for dealname in ["oceant2", "atr4cdo"]:
- reinvprices = os.path.join(root, "Intex curves", "csv", dealname + "-reinvprices.csv")
+ cursor.execute('SELECT "Reinv End Date" from latest_clo_universe where dealname=%s', dealname)
+ reinvenddate = cursor.fetchone()[0]
+ if not reinvenddate:
+ print "missing reinvstment end date"
+ pdb.set_trace()
+
with open(reinvprices, "r") as fhreinv:
- reinvprices = [line.rstrip("\n") for line in fhreinv]
+ floatreinvprices = fhreinv.readline().rstrip("\n").split(",")
+ fixedreinvprices = fhreinv.readline().rstrip("\n").split(",")
+
output = os.path.join(root, "Intex curves", "sss", dealname + ".sss")
cdrscenarios = os.path.join(root, "Intex curves", "csv", dealname + "-cdr.csv")
recoveryscenarios = os.path.join(root, "Intex curves", "csv", dealname + "-recovery.csv")
@@ -33,9 +65,41 @@ for dealname in ["oceant2", "atr4cdo"]:
i=1
with open(input) as fh:
for line in fh:
- if "STANDARD_VAR" in line:
- newline = "STANDARD_VAR[REINVEST_PRICE,1]=" + " ".join(reinvprices)
+ if "DEAL_NAME" in line:
+ newline = "DEAL_NAME=" + dealname.upper()
+ fh2.write(newline)
+ if pattern1.match(line):
+ line = re.sub(pattern1, r"\1{0}\2", line).format(dealname.upper())
+ fh2.write(line)
+ continue
+ if pattern2.match(line):
+ line = re.sub(pattern2, r"\1{0}\2{1}", line).format(dealname.upper(), reinvenddate)
+ fh2.write(line)
continue
+ if pattern3.match(line):
+ line = re.sub(pattern3, r"\1{0}\2{1}", line).format(dealname.upper(), " ".join(floatreinvprices))
+ fh2.write(line)
+ continue
+ if pattern4.match(line):
+ line = re.sub(pattern4, r"\1{0}\2{1}", line).format(dealname.upper(), " ".join(fixedreinvprices))
+ fh2.write(line)
+ continue
+ if pattern5.match(line):
+ line = re.sub(pattern5, r"\1{0}\2{1}", line).format(dealname.upper(), reinvfloatpercentage)
+ fh2.write(line)
+ continue
+ if pattern6.match(line):
+ line = re.sub(pattern6, r"\1{0}\2{1}", line).format(dealname.upper(), reinvfixedpercentage)
+ fh2.write(line)
+ continue
+ if pattern7.search(line):
+ line = re.sub(pattern7, dealname.upper(), line)
+ fh2.write(line)
+ continue
+ # if "STANDARD_VAR" in line:
+ # newline = "STANDARD_VAR[REINVEST_PRICE,1]=" + " ".join(reinvprices)
+ # fh2.write(newline)
+ # continue
if "LOSS_RATE[DEAL,{0}]".format(i) in line:
newcdrline = "LOSS_RATE[DEAL,{0}]=".format(i) + cdrline
fh2.write(newcdrline)
@@ -51,16 +115,18 @@ for dealname in ["oceant2", "atr4cdo"]:
recoveryline = "\t".join(["{0:.3f}".format(float(recovery)) \
for recovery in recoveryline]) + "\n"
continue
- if "REINV_GLOBAL" in line:
- jsondict = line.split("=")[1]
- reinvdict = json.loads(jsondict)
- reinvdict['STANDARD_VAR[REINVEST_PRICE]']['value'] = \
- ' '.join(["{0:.3f}".format(float(price)) for price in reinvprices])
- fh2.write("=".join(["REINV_GLOBAL", json.dumps(reinvdict)]) + "\n")
- continue
+ # if "REINV_GLOBAL" in line:
+ # jsondict = line.split("=")[1]
+ # reinvdict = json.loads(jsondict)
+ # reinvdict['STANDARD_VAR[REINVEST_PRICE]']['value'] = \
+ # ' '.join(["{0:.3f}".format(float(price)) for price in reinvprices])
+ # fh2.write("=".join(["REINV_GLOBAL", json.dumps(reinvdict)]) + "\n")
+ # continue
fh2.write(line)
fh2.close()
fhrecovery.close()
fhcdr.close()
+cursor.close()
+conn.close()
# sed -i -e "s/\(LOSS_NONPERF_SEVERITY\\[DEAL,[0-9]*\\]\)=.*$/\1=mkt(70)/g" stonln1_100.sss