aboutsummaryrefslogtreecommitdiffstats
path: root/R/build_scenarios.R
diff options
context:
space:
mode:
Diffstat (limited to 'R/build_scenarios.R')
-rw-r--r--R/build_scenarios.R20
1 files changed, 16 insertions, 4 deletions
diff --git a/R/build_scenarios.R b/R/build_scenarios.R
index 7a250a28..4f0ebee5 100644
--- a/R/build_scenarios.R
+++ b/R/build_scenarios.R
@@ -78,7 +78,6 @@ calibration <- read.table(file.path(root.dir, "Scenarios", "Calibration",
Z <- calibration$Z
w <- calibration$w
-rho <- 0.45
Ngrid <- 201
## dealnames <- list.files(file.path(root.dir, "Scenarios", paste0("Portfolios_", calibration.date)),
## pattern="*.RData")
@@ -100,9 +99,9 @@ for(deal.name in dealnames){
dp <- A$DP
pp <- A$PP
- dpmod <- MFupdate.probC(Z, w, rho, dp)
- ppmod <- MFupdate.probC(-Z, w, rho, pp)
- dist.joint <- MFlossdist.prepay.joint(w, Z, rho, dp, dpmod, pp, ppmod,
+ dpmod <- MFupdate.probC(Z, w, deal.portfolio$beta, dp)
+ ppmod <- MFupdate.probC(-Z, w, deal.portfolio$beta, pp)
+ dist.joint <- MFlossdist.prepay.joint(w, Z, deal.portfolio$beta, dp, dpmod, pp, ppmod,
deal.weights, 1-S, Ngrid)
distDR <- dist.transform(dist.joint)
@@ -158,9 +157,11 @@ for(deal.name in dealnames){
deal.datesmonthlylagged <- getdealschedule(deal.data, "1 month", workdate, 92)
cdrmonthly <- matrix(0, n.scenarios, length(deal.datesmonthly))
recoverymonthly <- matrix(0, n.scenarios, length(deal.datesmonthly))
+ scenariosrmonthly <- matrix(0, n.scenarios, length(deal.datesmonthly))
for(i in 1:n.scenarios){
cdrmonthly[i,] <- approx(deal.dates, cdr[i,], deal.datesmonthly, rule=2)$y
recoverymonthly[i,] <- approx(deal.dates, intexrecov[i,], deal.datesmonthly, rule=2)$y
+ scenariosrmonthly[i,] <- approx(deal.dates, intexrecov[i,], deal.datesmonthly, rule=2)$y
}
## compute reinvestment price
@@ -169,6 +170,17 @@ for(deal.name in dealnames){
forwards <- DC$forwards
reinvprices <- compute.reinvprices(df, forwards, cdrmonthly, recoverymonthly, 0.025, 0.07, 84, 3)
+ ## prev <- scenariosrmonthly[,1]
+ ## loanprices <- c()
+ ## bondprices <- c()
+ ## for(t in 2:dim(cdrmonthly)[2]){
+ ## w <- scenariosrmonthly[,t]-scenariosrmonthly[,t-1]+
+ ## prev*cdrmonthly[,t]/100 * intexrecov[,t] + yearFrac(deal.datesmonthly[t-1], deal.datesmonthly[t])
+ ## prev <- w
+ ## loanprices <- c(loanprices, crossprod(w, reinvprices$loan)/sum(w))
+ ## bondprices <- c(bondprices, crossprod(w, reinvprices$bond)/sum(w))
+ ## }
+ ## browser()
save.dir <- file.path(root.dir, "Scenarios", paste("Intex curves", workdate, sep="_"), "csv")
if(!file.exists(save.dir)){
dir.create(save.dir, recursive = T)