diff options
| -rw-r--r-- | R/build_scenarios.R | 6 | ||||
| -rw-r--r-- | R/intex_deal_functions.R | 14 |
2 files changed, 10 insertions, 10 deletions
diff --git a/R/build_scenarios.R b/R/build_scenarios.R index 21f2a401..fd404f20 100644 --- a/R/build_scenarios.R +++ b/R/build_scenarios.R @@ -18,9 +18,9 @@ source("serenitasdb.R") source("tranche_functions.R") if(interactive()) { - tradedate <- as.Date("2016-02-25") - dealnames <- c("beto", "ozlmf5") - reinvflags <- c(TRUE, TRUE) + tradedate <- as.Date("2017-07-07") + dealnames <- c("longf131") + reinvflags <- c(TRUE) }else{ tradedate <- as.Date(args[1]) if(length(args) >=2){ diff --git a/R/intex_deal_functions.R b/R/intex_deal_functions.R index 658cac4e..d5f16af0 100644 --- a/R/intex_deal_functions.R +++ b/R/intex_deal_functions.R @@ -377,7 +377,7 @@ getdealschedule <- function(dealdata, freq = c("Monthly", "Quarterly"), tradedat payday <- getpayday(dealdata, tradedate) freq <- match.arg(freq) bdc <- match.arg(bdc) - params <- list(effectiveDate = getpayday(dealdata, tradedate), + params <- list(effectiveDate = payday, maturityDate = dealdata$maturity, period = freq, businessDayConvention = bdc, @@ -387,7 +387,7 @@ getdealschedule <- function(dealdata, freq = c("Monthly", "Quarterly"), tradedat } intexportfolio.forwardprice <- function(cdrmonthly, recoverymonthly, startdate, maturity, - coupontype, margin, liborfloor){ + coupontype, margin, liborfloor){ if(missing(liborfloor)||is.na(liborfloor)){ currentcoupon <- margin }else{ @@ -400,8 +400,8 @@ intexportfolio.forwardprice <- function(cdrmonthly, recoverymonthly, startdate, .SDcols=paste0("V",1:100)] recovery <- as.matrix(recoverymonthly[date>=startdate, .SD, .SDcols=paste0("V",1:100)])* -apply(rbind(1,as.matrix(notionals)), 2, diff) - if(nrow(recovery)==1){ - recovery <- recovery*last(forwardcs[,df]) + if(nrow(recovery) == 1){ + recovery <- recovery * last(forwardcs[,df]) }else{ recovery <- data.table(dates=cdrmonthly[date>=startdate,date],apply(recovery, 2, cumsum),key="dates") recovery <- recovery[forwardcs, roll=TRUE] @@ -411,7 +411,7 @@ intexportfolio.forwardprice <- function(cdrmonthly, recoverymonthly, startdate, notionals <- data.table(dates=cdrmonthly[date>=startdate,date], notionals, key="dates") outstanding <- notionals[forwardcs, roll=TRUE] mat.outstanding <- as.matrix(outstanding[,.SD,.SDcols=paste0("V",1:100)]) - po <- mat.outstanding[nrow(mat.outstanding),]*last(outstanding)[,df] + po <- mat.outstanding[nrow(mat.outstanding),]*last(outstanding[,df]) io <- outstanding[, df*coupons]%*%mat.outstanding mean(recovery+po+io) } @@ -419,13 +419,13 @@ intexportfolio.forwardprice <- function(cdrmonthly, recoverymonthly, startdate, compute.reinvprices <- function(dealname, cdrmonthly, recoverymonthly, params, rollingmaturity, tradedate){ reinvassets <- get.reinvassets(dealname, tradedate) reinvprices <- list() - if(length(reinvassets)>0){ + if(length(reinvassets) > 0) { maturity <- cdrmonthly$date[nrow(cdrmonthly)] for(assetname in names(reinvassets)){ asset <- reinvassets[[assetname]] coupon <- if(asset$coupontype=="FLOAT") params$reinvfloat else params$reinvfixed reinvprices[[assetname]] <- foreach(date = iter(cdrmonthly$date), .combine=c) %dopar% { - 100 * intexportfolio.forwardprice(cdrmonthly.dt, recoverymonthly.dt, date, + 100 * intexportfolio.forwardprice(cdrmonthly, recoverymonthly, date, min(date+rollingmaturity, maturity), asset$coupontype, coupon, asset$liborfloor/100) } |
