diff options
Diffstat (limited to 'python')
| -rw-r--r-- | python/intex_scenarios.py | 29 |
1 files changed, 18 insertions, 11 deletions
diff --git a/python/intex_scenarios.py b/python/intex_scenarios.py index 64f6cd29..c43caee7 100644 --- a/python/intex_scenarios.py +++ b/python/intex_scenarios.py @@ -11,8 +11,8 @@ import common import sys
import pdb
-pattern11 = re.compile("(REINVEST\[)\w+(::REINV_TBA1\]\[DEAL,1\]=)(.*$)")
-pattern12 = re.compile("(REINVEST\[)\w+(::REINV_TBA2\]\[DEAL,1\]=)(.*$)")
+pattern11 = re.compile("(REINVEST\[)\w+(::REINV_TBA1\]\[DEAL,\d+\]=)(.*$)")
+pattern12 = re.compile("(REINVEST\[)\w+(::REINV_TBA2\]\[DEAL,\d+\]=)(.*$)")
# reinv end date
pattern2 = re.compile("(STANDARD_VAR\[)\w+(::#REINV_END,\d+\]=)(\d.*$)")
# reinvprices float
@@ -23,7 +23,7 @@ pattern4 = re.compile("(STANDARD_VAR\[)\w+(::#PRICE100_TBA2,\d+\]=)(.*$)") 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")
+pattern7 = re.compile("GOLDL3")
reinvfloatpercentage = 85
reinvfixedpercentage = 15
@@ -68,6 +68,7 @@ def convert_reinvtoperct(d): def generate_scenarios(workdate, dealnames, conn, cursor):
prometheus = os.path.join(common.root, "Scenarios", "prometheus.sss")
+ n_scenarios = 100
for dealname in dealnames:
cursor.execute('SELECT \"Reinv End Date\" from latest_clo_universe where dealname=%s', (dealname,))
reinvenddate = cursor.fetchone()[0]
@@ -79,9 +80,15 @@ def generate_scenarios(workdate, dealnames, conn, cursor): reinv_assets = get_reinv_assets(dealname)
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 + "-reinvprices.csv"), "r") as fhreinv:
- floatreinvprices = fhreinv.readline().rstrip("\n").split(",")
- fixedreinvprices = fhreinv.readline().rstrip("\n").split(",")
+ floatreinvprices = []
+ fixedreinvprices = []
+
+ with open(os.path.join(basedir, "csv", dealname + "-floatreinvprices.csv"), "rb") as fhreinv:
+ for line in fhreinv:
+ floatreinvprices.append(line.rstrip("\n").split(","))
+ with open(os.path.join(basedir, "csv", dealname + "-fixedreinvprices.csv"), "rb") as fhreinv:
+ for line in fhreinv:
+ fixedreinvprices.append(line.rstrip("\n").split(","))
output = os.path.join(basedir, "sss", dealname + ".sss")
if not os.path.exists(os.path.join(basedir, "sss")):
@@ -127,16 +134,16 @@ def generate_scenarios(workdate, dealnames, conn, cursor): continue
if pattern3.match(line):
if reinv_assets['REINV_TBA1'] == 'Fixed':
- line = re.sub(pattern3, r"\1{0}\2{1}", line).format(dealname.upper(), " ".join(fixedreinvprices))
+ line = re.sub(pattern3, r"\1{0}\2{1}", line).format(dealname.upper(), " ".join(fixedreinvprices[i-2]))
elif reinv_assets['REINV_TBA1'] == 'Float':
- line = re.sub(pattern3, r"\1{0}\2{1}", line).format(dealname.upper(), " ".join(floatreinvprices))
+ line = re.sub(pattern3, r"\1{0}\2{1}", line).format(dealname.upper(), " ".join(floatreinvprices[i-2]))
fh2.write(line)
continue
if pattern4.match(line):
if reinv_assets['REINV_TBA2'] == 'Fixed':
- line = re.sub(pattern4, r"\1{0}\2{1}", line).format(dealname.upper(), " ".join(fixedreinvprices))
+ line = re.sub(pattern4, r"\1{0}\2{1}", line).format(dealname.upper(), " ".join(fixedreinvprices[i-2]))
elif reinv_assets['REINV_TBA2'] == 'Float':
- line = re.sub(pattern4, r"\1{0}\2{1}", line).format(dealname.upper(), " ".join(floatreinvprices))
+ line = re.sub(pattern4, r"\1{0}\2{1}", line).format(dealname.upper(), " ".join(floatreinvprices[i-2]))
fh2.write(line)
continue
if pattern5.match(line):
@@ -167,7 +174,7 @@ def generate_scenarios(workdate, dealnames, conn, cursor): newrecoveryline = "LOSS_SEVERITY[DEAL,{0}]=".format(i) + recoveryline
fh2.write(newrecoveryline)
i = i + 1
- if i <= 100:
+ if i <= n_scenarios:
cdrline = csvcdr.next()
cdrline = "\t".join(["{0:.3f}".format(float(cdr)) for cdr in cdrline]) + "\n"
recoveryline = csvrecovery.next()
|
