aboutsummaryrefslogtreecommitdiffstats
path: root/R/intex_deal_functions.R
diff options
context:
space:
mode:
Diffstat (limited to 'R/intex_deal_functions.R')
-rw-r--r--R/intex_deal_functions.R14
1 files changed, 7 insertions, 7 deletions
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)
}