diff options
Diffstat (limited to 'R')
| -rw-r--r-- | R/build_scenarios.R | 2 | ||||
| -rw-r--r-- | R/cds_functions_generic.R | 17 | ||||
| -rw-r--r-- | R/intex_deal_functions.R | 8 | ||||
| -rw-r--r-- | R/load_cf.R | 5 |
4 files changed, 17 insertions, 15 deletions
diff --git a/R/build_scenarios.R b/R/build_scenarios.R index b6b3d63f..48082cee 100644 --- a/R/build_scenarios.R +++ b/R/build_scenarios.R @@ -175,7 +175,7 @@ for(j in seq_along(dealnames)){ row.names=F, col.names=T, sep=",")
configfile <- file.path(save.dir, paste0(dealnames[j], ".config"))
- config <- list(rollingmat = as.integer(rollingmaturity),
+ config <- list(rollingmat = as.integer(rollingmaturity/365*12),
reinvflag = reinvflags[j])
cat(as.yaml(config), file = configfile)
save(scenariosd, scenariosr, dist.joint, file=file.path(save.dir, paste0(dealnames[j], ".RData")),
diff --git a/R/cds_functions_generic.R b/R/cds_functions_generic.R index 073075de..f642ebb5 100644 --- a/R/cds_functions_generic.R +++ b/R/cds_functions_generic.R @@ -724,17 +724,20 @@ getdealschedule <- function(dealdata, freq="1 month", lag=0, adjust=FALSE){ if(is.null(dealdata$"Pay Day")||(abs(as.numeric(dealdata$"Deal Next Pay Date"- dealdata$"Pay Day") - 90)>10)){
dealdata$"Pay Day" <- seq(dealdata$"Deal Next Pay Date", length=2, by="-3 months")[2]
}
- sched <- seq(dealdata$"Pay Day", dealdata$"maturity" + lag, by=freq)
+ n <- if(freq == "1 month") 1 else 3
+ sched <- dealdata$"Pay Day"
+ i <- 1
+ bdc <- if(adjust) 0 else 4
+ nextdate <- advance(calendar = "UnitedStates", dates=dealdata$"Pay Day", n*i, 2, bdc=bdc)
+ while(nextdate<= dealdata$"maturity" + lag){
+ sched <- c(sched, nextdate)
+ i <- i+1
+ nextdate <- advance(calendar = "UnitedStates", dates=dealdata$"Pay Day", n*i, 2, bdc=bdc)
+ }
##always add the maturity
if(sched[length(sched)] < dealdata$maturity){
sched <- c(sched, dealdata$maturity)
}
- if(adjust){
- calstring <- "UnitedStates"
- ## never adjust the maturity
- sched <- c(adjust(calstring, sched[-length(sched)]), sched[length(sched)])
- base::names(sched) <- NULL
- }
return(sched)
}
diff --git a/R/intex_deal_functions.R b/R/intex_deal_functions.R index 42d9f452..89fecb40 100644 --- a/R/intex_deal_functions.R +++ b/R/intex_deal_functions.R @@ -348,7 +348,7 @@ get.reinvassets <- function(dealname, tradedate){ return( r )
}
-forwardportfolioprice2 <- function(cdrmonthly, recoverymonthly, startdate, maturity,
+intexportfolio.forwardprice <- function(cdrmonthly, recoverymonthly, startdate, maturity,
coupontype, margin, liborfloor){
if(missing(liborfloor)||is.na(liborfloor)){
currentcoupon <- margin
@@ -387,9 +387,9 @@ compute.reinvprices <- function(dealname, cdrmonthly, recoverymonthly, params, r asset <- reinvassets[[assetname]]
coupon <- if(asset$coupontype=="FLOAT") params$reinvfloat else params$reinvfixed
reinvprices[[assetname]] <- foreach(date = iter(cdrmonthly$date), .combine=c) %dopar% {
- 100 * forwardportfolioprice2(cdrmonthly.dt, recoverymonthly.dt, date,
- min(date+rollingmaturity, maturity),
- asset$coupontype, coupon, asset$liborfloor/100)
+ 100 * intexportfolio.forwardprice(cdrmonthly.dt, recoverymonthly.dt, date,
+ min(date+rollingmaturity, maturity),
+ asset$coupontype, coupon, asset$liborfloor/100)
}
}
}
diff --git a/R/load_cf.R b/R/load_cf.R index 14a4a3c5..27a8abce 100644 --- a/R/load_cf.R +++ b/R/load_cf.R @@ -146,7 +146,7 @@ getdealcf <- function(dealnames, zipfiles, tradedate=Sys.Date()){ program <- tryCatch(KLfit(t(cf)/1e8, rep(1/n.scenarios, n.scenarios),
dealdata$mv/1e8), error=function(e) e)
if(inherits(program, "error")){
- cat("error computing the delta for deal:", dealname,"\n")
+ cat("error computing the weights for deal:", dealname,"\n")
cfdata[[dealname]] <- NULL
next
}else{
@@ -171,7 +171,7 @@ getcusipcf <- function(params, cfdata, dist, tradedate=Sys.Date()){ zip <- params$zipfiles[params$cusips[[cusip]]]
dealname <- dealnames[i]
dealdata <- getdealdata(dealname, tradedate)
- alldates <- getdealschedule(dealdata,"1 month", startdate=tradedate, adjust=TRUE)
+ alldates <- getdealschedule(dealdata,"1 month", adjust=TRUE)
T <- ifelse(alldates>=L3m$params$tradeDate, yearFrac(L3m$params$tradeDate, alldates), 0)
DC <- DiscountCurve(L3m$params, L3m$tsQuotes, T)
df <- data.table(Date=alldates,
@@ -188,7 +188,6 @@ getcusipcf <- function(params, cfdata, dist, tradedate=Sys.Date()){ conn <- unz(zip, filename)
data <- data.table(read.table(conn, sep="\t", header=TRUE, colClasses="character",
check.names=FALSE))
- browser()
data <- data[-c(1,2),]
if("Error" %in% names(data)){
k(NULL)
|
