diff options
Diffstat (limited to 'R')
| -rw-r--r-- | R/cds_functions_generic.R | 4 | ||||
| -rw-r--r-- | R/cds_utils.R | 5 | ||||
| -rw-r--r-- | R/intex_deal_functions.R | 4 | ||||
| -rw-r--r-- | R/load_cf.R | 20 |
4 files changed, 17 insertions, 16 deletions
diff --git a/R/cds_functions_generic.R b/R/cds_functions_generic.R index 754d789e..16f4cb50 100644 --- a/R/cds_functions_generic.R +++ b/R/cds_functions_generic.R @@ -654,8 +654,8 @@ DP2 <- function(sc, dates){ prepayprob = cumsum(pfun(x2T) * Qmid * dT))
}
-getdealschedule <- function(dealdata, freq="3 months"){
- dates <- seq(dealdata$"Deal Next Pay Date", dealdata$maturity, by=freq)
+getdealschedule <- function(dealdata, freq="3 months", lag = 0){
+ dates <- seq(dealdata$"Deal Next Pay Date", dealdata$maturity + lag, by=freq)
dates <- dates[dates>today()]
return( dates )
}
diff --git a/R/cds_utils.R b/R/cds_utils.R index 9017e655..1186f953 100644 --- a/R/cds_utils.R +++ b/R/cds_utils.R @@ -71,8 +71,8 @@ couponSchedule <- function(nextpaydate=NULL, maturity, frequency, coupontype, cu ## inputs:
## nextpaydate: first payment date of the coupon schedule
## maturity: last payment date of the schedule
- ## frequency: letter specifying the frequency amon "Q", "M", "B", or "S"
- ## if startdate is provided, this generates the forward coupon schedule starting from that date.
+ ## frequency: letter specifying the frequency between "Q", "M", "B", "S" or "A"
+ ## if startdate is provided, we generate the forward coupon schedule starting from that date.
bystring <- switch(frequency,
Q = "3 months",
M = "1 month",
@@ -103,6 +103,7 @@ couponSchedule <- function(nextpaydate=NULL, maturity, frequency, coupontype, cu A = DiscountCurve(L12m$params, L12m$tsQuotes, yearFrac(L12m$params$tradeDate, dates)))
if(coupontype=="FLOAT" && !is.na(margin)){ #if is.na(margin) probably letter of credit
+ #we floor the coupon at the current gross rate
coupons <- pmax(currentcoupon, DC$forwards + margin)
}else{
coupons <- rep(currentcoupon, length(dates))
diff --git a/R/intex_deal_functions.R b/R/intex_deal_functions.R index 8e7d0b43..251c5fed 100644 --- a/R/intex_deal_functions.R +++ b/R/intex_deal_functions.R @@ -33,7 +33,7 @@ getdealdata <- function(dealnames, date){ getcollateral <- function(dealname, date){
if(missing(date)){
- sqlstring <- sprintf("select * from et_aggdealinfo('%s')", dealname, date)
+ sqlstring <- sprintf("select * from et_aggdealinfo('%s')", dealname)
}else{
sqlstring <- sprintf("select * from et_aggdealinfo_historical('%s', '%s')", dealname, date)
}
@@ -252,7 +252,7 @@ buildSC <- function(line.item, reinvdate, dealmaturity, global.params, startdate return( list(SC=SC, notional=line.item$currentbalance, price = line.item$price) )
}
-buildSC.portfolio <- function(dealname, dealdata, cusipdata, global.params, startdate=Sys.Date()) {
+buildSC.portfolio <- function(dealname, dealdata, cusipdata, global.params, startdate = Sys.Date()) {
collatdata <- getcollateral(dealname, startdate)
index <- hash(cusipdata$cusip, 1:length(cusipdata$cusip))
notionalvec <- c()
diff --git a/R/load_cf.R b/R/load_cf.R index 723a53aa..9fe4f207 100644 --- a/R/load_cf.R +++ b/R/load_cf.R @@ -34,13 +34,6 @@ tranches <- c("COLLAT_REINVEST", "COLLAT_INITIAL") n.scenarios <- 100
flag <- FALSE
-dealnames <- c("ares11", "cifc071", "cifc122", "comst", "duanst1", "empf2",
- "galax8", "gulf052", "halcli1", "hals071", "hewett3", "hewett6",
- "hillmf", "ingim2", "ingim3", "katon10", "katonah8", "katonah9",
- "landmrk6", "landmrk8", "latcl3", "madpk6", "mayp", "mtwil2",
- "oakcp3", "oceant1", "pacific3", "primus2", "sappv1", "saratg_1",
- "shack1", "standay", "sumlk", "t2if1", "vent12", "vent7", "vent9",
- "wthrs3")
allfiles <- list.files(file.path(root.dir, "Scenarios", paste0("Prices_", workdate)), "*.txt")
allfiles <- unique(sapply(strsplit(allfiles, "-"), function(x) x[1]))
allfiles <- allfiles[!(allfiles=="Total")]
@@ -63,8 +56,15 @@ for(dealname in dealnames){ for(tranche in tranches){
for(i in 1:n.scenarios){
filename <- paste0(paste(toupper(dealname), tranche, "CF", paste0("Scen", i), sep="-"), ".txt")
- data <- read.table(file.path(root.dir, "Scenarios", paste0("Prices_", workdate), filename),
- sep="\t", header=F, skip=3, colClasses="character", comment.char="")
+ ## we catch the error if there is an error reading the file
+ ## happen if the tranche is missing in intex
+ data <- tryCatch(read.table(file.path(root.dir, "Scenarios", paste0("Prices_", workdate), filename),
+ sep="\t", header=F, skip=3, colClasses="character", comment.char=""),
+ error = function(e) e)
+ if(inherits(data, "error")){
+ cfdata[[dealname]] <- NULL
+ break
+ }
data <- data[,1:4]
colnames(data) <- c("Date", "Cashflow", "Principal", "Interest")
data$Date <- as.Date(data$Date, "%b %d, %Y")
@@ -106,7 +106,7 @@ for(dealname in dealnames){ }
r <- c()
-for(dealname in dealnames){
+for(dealname in names(cfdata)){
r <- rbind(r, c(cfdata[[dealname]]$mv, cfdata[[dealname]]$currbal, apply(cfdata[[dealname]]$COLLAT_REINVEST, 2, mean)[1], apply(cfdata[[dealname]]$COLLAT_INITIAL, 2, mean)[1]))
}
colnames(r) <- c("mv", "currbal", "Reinvest", "Initial")
|
