aboutsummaryrefslogtreecommitdiffstats
path: root/python
diff options
context:
space:
mode:
Diffstat (limited to 'python')
-rw-r--r--python/intex_scenarios.py84
1 files changed, 65 insertions, 19 deletions
diff --git a/python/intex_scenarios.py b/python/intex_scenarios.py
index bcac1966..dd3b2987 100644
--- a/python/intex_scenarios.py
+++ b/python/intex_scenarios.py
@@ -2,6 +2,8 @@ import os
import os.path
import datetime
from datetime import date
+import csv
+from collections import defaultdict
from csv import reader
import json
import codecs
@@ -9,13 +11,15 @@ import re
import psycopg2
if os.name =='nt':
- root = "//WDsentinel/share/CorpCDOs/Scenarios"
+ root = "//WDsentinel/share/CorpCDOs"
elif os.name == 'posix':
- root = '/home/share/CorpCDOs/Scenarios'
-input = os.path.join(root, "prometheus.sss")
+ root = '/home/share/CorpCDOs'
-pattern1 = re.compile("(REINVEST\[)\w+(::.*$)")
-# maturity
+input = os.path.join(root, "Scenarios", "prometheus.sss")
+
+pattern11 = re.compile("(REINVEST\[)\w+(::REINV_TBA1\]\[DEAL,1\]=)(.*$)")
+pattern12 = re.compile("(REINVEST\[)\w+(::REINV_TBA2\]\[DEAL,2\]=)(.*$)")
+# reinv end date
pattern2 = re.compile("(STANDARD_VAR\[)\w+(::#REINV_END,\d+\]=)(\d*$)")
# reinvprices float
pattern3 = re.compile("(STANDARD_VAR\[)\w+(::#PRICE100_TBA1,\d+\]=)(.*$)")
@@ -36,22 +40,37 @@ conn = psycopg2.connect(database="ET",
host="192.168.1.108")
cursor = conn.cursor()
-for dealname in ["abcl071", "ammcclo5", "atr5cdo", "blumt3", "callid6"]:
+workdate = '2013-01-04'
+
+def get_reinv_assets(dealname, date):
+ d = {'REINV_TBA1': None, 'REINV_TBA2': None}
+ filename = dealname.upper() + ",AD.txt"
+ with open(os.path.join(root, "data", "Collaterals_" + date, filename )) as fh:
+ dr = csv.DictReader(fh, dialect = 'excel-tab')
+ headers = dr.fieldnames
+ for line in dr:
+ if line['ID Number'] == 'REINV_TBA1':
+ d['REINV_TBA1'] = line['Fixed or Float']
+ if line['ID Number'] == 'REINV_TBA2':
+ d['REINV_TBA2'] = line['Fixed or Float']
+ return d
+
+for dealname in ["abcl071", "ammcclo5", "atr4cdo", "atr5cdo", "blumt3", "callid6", "goldl5", "limes", "oceant2", "symph4"]:
cursor.execute('SELECT \"Reinv End Date\" from latest_clo_universe where dealname=%s', (dealname,))
reinvenddate = cursor.fetchone()[0]
if reinvenddate:
- reinvenddate = reinvenddate.strftime("%Y%m%d")
+ reinvenddate = reinvenddate.strftime("%Y%m%d")
else:
- print "missing reinvstment end date"
+ print "missing reinvestment end date"
pdb.set_trace()
-
- with open(os.path.join(root, "Intex curves", "csv", dealname + "-reinvprices.csv"), "r") as fhreinv:
+ reinv_assets = get_reinv_assets(dealname, workdate)
+ with open(os.path.join(root, "Scenarios", "Intex curves", "csv", dealname + "-reinvprices.csv"), "r") as 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")
+ output = os.path.join(root, "Scenarios", "Intex curves", "sss", dealname + ".sss")
+ cdrscenarios = os.path.join(root, "Scenarios", "Intex curves", "csv", dealname + "-cdr.csv")
+ recoveryscenarios = os.path.join(root, "Scenarios", "Intex curves", "csv", dealname + "-recovery.csv")
fh2 = open(output, "w")
fhcdr = open(cdrscenarios, "r")
fhrecovery = open(recoveryscenarios, "r")
@@ -68,8 +87,20 @@ for dealname in ["abcl071", "ammcclo5", "atr5cdo", "blumt3", "callid6"]:
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())
+ if pattern11.match(line):
+ line = re.sub(pattern11, r"\1{0}\2", line).format(dealname.upper()).rstrip()
+ if reinv_assets["REINV_TBA1"] == "Float":
+ line = line + "COUP_SPR=2.5|AMORT=Bullet|USE_REINVEST_PIP=1|MAT_DATE=84|\n"
+ elif reinv_assets["REINV_TBA1"] == "Fixed":
+ line = line + "COUP_SPR=7|AMORT=Bullet|USE_REINVEST_PIP=1|MAT_DATE=84|\n"
+ fh2.write(line)
+ continue
+ if pattern12.match(line):
+ line = re.sub(pattern12, r"\1{0}\2", line).format(dealname.upper()).rstrip()
+ if reinv_assets["REINV_TBA2"] == "Float":
+ line = line + "COUP_SPR=2.5|AMORT=Bullet|USE_REINVEST_PIP=1|MAT_DATE=84|\n"
+ elif reinv_assets["REINV_TBA2"] == "Fixed":
+ line = line + "COUP_SPR=7|AMORT=Bullet|USE_REINVEST_PIP=1|MAT_DATE=84|\n"
fh2.write(line)
continue
if pattern2.match(line):
@@ -77,19 +108,34 @@ for dealname in ["abcl071", "ammcclo5", "atr5cdo", "blumt3", "callid6"]:
fh2.write(line)
continue
if pattern3.match(line):
- line = re.sub(pattern3, r"\1{0}\2{1}", line).format(dealname.upper(), " ".join(floatreinvprices))
+ if reinv_assets['REINV_TBA1'] == 'Fixed':
+ line = re.sub(pattern3, r"\1{0}\2{1}", line).format(dealname.upper(), " ".join(fixedreinvprices))
+ elif reinv_assets['REINV_TBA1'] == 'Float':
+ 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))
+ if reinv_assets['REINV_TBA2'] == 'Fixed':
+ line = re.sub(pattern4, r"\1{0}\2{1}", line).format(dealname.upper(), " ".join(fixedreinvprices))
+ elif reinv_assets['REINV_TBA2'] == 'Float':
+ line = re.sub(pattern4, r"\1{0}\2{1}", line).format(dealname.upper(), " ".join(floatreinvprices))
fh2.write(line)
continue
if pattern5.match(line):
- line = re.sub(pattern5, r"\1{0}\2{1}", line).format(dealname.upper(), reinvfloatpercentage)
+ if not reinv_assets['REINV_TBA1']:
+ line = re.sub(pattern5, r"\1{0}\2{1}", line).format(dealname.upper(), 100)
+ elif reinv_assets['REINV_TBA1'] == 'Fixed':
+ line = re.sub(pattern5, r"\1{0}\2{1}", line).format(dealname.upper(), reinvfixedpercentage)
+ elif reinv_assets['REINV_TBA1'] == 'Float':
+ 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)
+ if reinv_assets['REINV_TBA2'] == 'Float':
+ line = re.sub(pattern6, r"\1{0}\2{1}", line).format(dealname.upper(), reinvfloatpercentage)
+ elif reinv_assets['REINV_TBA2'] == 'Fixed':
+ line = re.sub(pattern6, r"\1{0}\2{1}", line).format(dealname.upper(), reinvfixedpercentage)
+ line = re.sub(pattern6, r"\1{0}\2{1}", line).format(dealname.upper(), reinvfloatpercentage)
fh2.write(line)
continue
if pattern7.search(line):