aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--R/build_scenarios.R40
-rw-r--r--python/intex_scenarios.py21
2 files changed, 41 insertions, 20 deletions
diff --git a/R/build_scenarios.R b/R/build_scenarios.R
index 16c995c6..a4b952e2 100644
--- a/R/build_scenarios.R
+++ b/R/build_scenarios.R
@@ -14,6 +14,7 @@ if(length(args) >= 1){
if(length(args) >=2){
dealnames <- args[2:length(args)]
+ reinvflags <- rep(TRUE, length(dealnames))
}else{
data <- read.table(file.path(root.dir, "scripts", "scenarios.txt"))
dealnames <- data$V1
@@ -24,6 +25,7 @@ if(length(args) >=2){
source(file.path(root.dir, "code", "R", "intex_deal_functions.R"))
source(file.path(root.dir, "code", "R", "index_definitions.R"))
source(file.path(root.dir, "code", "R", "etdb.R"))
+source(file.path(root.dir, "code", "R", "cds_functions_generic.R"))
prevBusDay <- function(workdate = Sys.Date()){
i <- 1
@@ -211,14 +213,26 @@ for(j in seq_along(dealnames)){
DC <- DiscountCurve(L3m$params, L3m$tsQuotes, yearFrac(L3m$params$tradeDate, deal.datesmonthlylagged))
df <- DC$discounts
forwards <- DC$forwards
- #we need to jack up the reinvestment prices somehow so let's add 1% tweak...
- reinvprices.tweak <- compute.reinvprices(df, forwards, cdrmonthly, recoverymonthly, reinvspread+0.0075,
- reinvfixed+0.0075, rollingmaturity, reinvlag)
- reinvprices <- compute.reinvprices(df, forwards, cdrmonthly, recoverymonthly, reinvspread,
- reinvfixed, rollingmaturity, reinvlag)
+ #we need to jack up the reinvestment prices somehow so let's add a 75bps tweak...
+ ## reinvprices.tweak <- compute.reinvprices(df, forwards, cdrmonthly, recoverymonthly, reinvspread+0.0075,
+ ## reinvfixed+0.0075, rollingmaturity, reinvlag)
+ loanprices <- c()
+ bondprices <- c()
+ for(i in seq_along(deal.datesmonthly)){
+ loanprices <- c(loanprices,
+ forwardportfolioprice(deal.portfolio, deal.datesmonthly[i],
+ min(deal.datesmonthly[i]+rollingmaturity*30, deal.data$maturity),
+ "float", reinvspread, 0.7))
+ bondprices <- c(bondprices,
+ forwardportfolioprice(deal.portfolio, deal.datesmonthly[i],
+ min(deal.datesmonthly[i]+rollingmaturity*30, deal.data$maturity),
+ "fixed", reinvfixed, 0.4))
+ }
+ ## reinvprices <- compute.reinvprices(df, forwards, cdrmonthly, recoverymonthly, reinvspread,
+ ## reinvfixed, rollingmaturity, reinvlag)
- loanprices <- apply(reinvprices.tweak$loan, 2, mean)
- bondprices <- apply(reinvprices.tweak$bond, 2, mean)
+ ## loanprices <- apply(reinvprices.tweak$loan, 2, mean)
+ ## bondprices <- apply(reinvprices.tweak$bond, 2, mean)
## reinvassets <- convert.reinvtoperct(get.reinvassets(dealnames[j]))
## ## all amounts are in units of current collateral balance
@@ -266,12 +280,12 @@ for(j in seq_along(dealnames)){
file=file.path(save.dir, paste0(dealnames[j],"-recovery.csv")),
row.names=F, col.names=F, sep=",", na="NaN")
if(reinvflags[j]){
- write.table(100 * reinvprices$loan,
- file = file.path(save.dir, paste0(dealnames[j], "-floatreinvprices.csv")),
- row.names=F, col.names=F, sep=",")
- write.table(100 * reinvprices$bond,
- file = file.path(save.dir, paste0(dealnames[j], "-fixedreinvprices.csv")),
- row.names=F, col.names=F, sep=",")
+ ## write.table(100 * reinvprices$loan,
+ ## file = file.path(save.dir, paste0(dealnames[j], "-floatreinvprices.csv")),
+ ## row.names=F, col.names=F, sep=",")
+ ## write.table(100 * reinvprices$bond,
+ ## file = file.path(save.dir, paste0(dealnames[j], "-fixedreinvprices.csv")),
+ ## row.names=F, col.names=F, sep=",")
write.table(cbind(100 * loanprices, 100 * bondprices),
file = file.path(save.dir, paste0(dealnames[j], "-reinvprices.csv")),
row.names=F, col.names=F, sep=",")
diff --git a/python/intex_scenarios.py b/python/intex_scenarios.py
index 537650cb..047f9942 100644
--- a/python/intex_scenarios.py
+++ b/python/intex_scenarios.py
@@ -71,14 +71,21 @@ def generate_scenarios(workdate, dealnames, conn, cursor):
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(","))
- with open(os.path.join(basedir, "csv", dealname + "-fixedreinvprices.csv"), "rb") as fhreinv:
- for line in fhreinv:
- fixedreinvprices.append(line.rstrip("\n").split(","))
+ # 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(","))
+ with open(os.path.join(basedir, "csv", dealname + "-reinvprices.csv"), "rb") as fh:
+ for line in fh:
+ a, b = line.split(",")
+ floatreinvprices.append(a)
+ fixedreinvprices.append(b)
+ floatreinvprices = [floatreinvprices] * 100
+ fixedreinvprices = [fixedreinvprices] * 100
except IOError:
- reinvflag=False
+ reinvflag = False
output = os.path.join(basedir, "sss", dealname + ".sss")
if not os.path.exists(os.path.join(basedir, "sss")):