diff options
Diffstat (limited to 'R/build_scenarios.R')
| -rw-r--r-- | R/build_scenarios.R | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/R/build_scenarios.R b/R/build_scenarios.R index 18099933..82c58562 100644 --- a/R/build_scenarios.R +++ b/R/build_scenarios.R @@ -50,7 +50,7 @@ compute.reinvprices <- function(df, forwards, cdrmonthly, recoverymonthly, floatcoupon <- (forwards[index]+ spread)/12
fixedcoupon <- fixedrate/12
currbalance <- 1 - cdrmonthly[,index]/100/12
- browser()
+
if(i < ncol(cdrmonthly)-1){
currbalance <- t(apply(currbalance, 1, cumprod))
recov <- -t(apply(cbind(1, currbalance), 1, diff)) *
@@ -60,9 +60,11 @@ compute.reinvprices <- function(df, forwards, cdrmonthly, recoverymonthly, pl <- currbalance[,dim(currbalance)[2]]*currdf[length(currdf)] +
recov %*% laggeddf
}else{
- fixedcl <- currbalance*fixedcoupon*df
- floatcl <- currbalance*floatcoupon*df
- pl <- currbalance * df
+ recov <- -t(apply(cbind(1, currbalance), 1, diff)) *
+ recoverymonthly[,index]
+ fixedcl <- as.numeric(currbalance*fixedcoupon*currdf)
+ floatcl <- as.numeric(currbalance*floatcoupon*currdf)
+ pl <- as.numeric(currbalance * currdf + recov * laggeddf)
}
floatbp <- cbind(floatbp, pl+floatcl)
fixedbp <- cbind(fixedbp, pl+fixedcl)
@@ -148,7 +150,8 @@ for(deal.name in dealnames){ cdr <- cdrfromscenarios(scenariosd, deal.dates)
## linear approximation for monthly scenarios
deal.data <- getdealdata(deal.name)
- deal.datesmonthly <- getdealschedule(deal.data, "1 month", lag = recoverylag)
+ deal.datesmonthly <- getdealschedule(deal.data, "1 month")
+ deal.datesmonthlylagged <- getdealschedule(deal.data, "1 month", workdate, 90)
cdrmonthly <- matrix(0, n.scenarios, length(deal.datesmonthly))
recoverymonthly <- matrix(0, n.scenarios, length(deal.datesmonthly))
for(i in 1:n.scenarios){
@@ -157,9 +160,10 @@ for(deal.name in dealnames){ }
## compute reinvestment price
- DC <- DiscountCurve(L3m$params, L3m$tsQuotes, yearFrac(L3m$params$tradeDate, deal.datesmonthly))
+ DC <- DiscountCurve(L3m$params, L3m$tsQuotes, yearFrac(L3m$params$tradeDate, deal.datesmonthlylagged))
df <- DC$discounts
- reinvprices <- compute.reinvprices(df, cdrmonthly, recoverymonthly, 0.025, 0.07, 84)
+ forwards <- DC$forwards
+ reinvprices <- compute.reinvprices(df, forwards, cdrmonthly, recoverymonthly, 0.025, 0.07, 84, 3)
save.dir <- file.path(root.dir, "Scenarios", paste("Intex curves", workdate, sep="_"), "csv")
if(!file.exists(save.dir)){
|
