aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--R/cds_utils.R6
-rw-r--r--R/load_cf.R10
-rw-r--r--R/script_calibrate_tranches.R2
3 files changed, 10 insertions, 8 deletions
diff --git a/R/cds_utils.R b/R/cds_utils.R
index 9b830cef..3685056e 100644
--- a/R/cds_utils.R
+++ b/R/cds_utils.R
@@ -26,7 +26,7 @@ convertTenor <- function(tenor) {
}else if ( year != -1) {
a <- as.numeric(attr(year, "capture.start"))
b <- a + attr(year, "capture.length") - 1
- l <- as.numeric(substr(tenor, a,b))
+ l <- as.numeric(substr(tenor, a, b))
return ( 365 * l )
}else{
stop("format not recognized")
@@ -77,7 +77,7 @@ creditSchedule <- function(startdate, enddate) {
}
couponSchedule <- function(nextpaydate=NULL, maturity, frequency, coupontype, currentcoupon,
- margin, startdate=today()){
+ margin, startdate=Sys.Date()){
## computes the coupon schedule
## inputs:
## nextpaydate: first payment date of the coupon schedule
@@ -105,7 +105,7 @@ couponSchedule <- function(nextpaydate=NULL, maturity, frequency, coupontype, cu
dates <- c(dates, maturity)
}
}
- dates <- dates[ dates >= today()]
+ dates <- dates[ dates >= startdate]
DC <- switch(frequency,
S = DiscountCurve(L6m$params, L6m$tsQuotes, yearFrac(L6m$params$tradeDate, dates)),
Q = DiscountCurve(L3m$params, L3m$tsQuotes, yearFrac(L3m$params$tradeDate, dates)),
diff --git a/R/load_cf.R b/R/load_cf.R
index f3b41010..215e353f 100644
--- a/R/load_cf.R
+++ b/R/load_cf.R
@@ -248,16 +248,17 @@ getcusipcf <- function(cusips, cfdata, dist, workdate=Sys.Date()){
cusipdata[[cusip]]$delta <-
compute.delta(dist, cfdata[[dealnames[i]]]$weight,
cusipdata[[cusip]]$fields[,"Cashflow"]/cusipdata[[cusip]]$currbal,
- workdate)
+ prevBusDay(workdate))
}
}
return(cusipdata)
}
-compute.delta <- function(indexdist, dealweight, cusip.pv, workdate=Sys.Date()){
+compute.delta <- function(indexdist, dealweight, cusip.pv, workdate=prevBusDay(Sys.Date())){
indexpv <- c()
- cs <- couponSchedule(nextIMMDate(workdate), as.Date("2017-12-20"), "Q", "FLOAT", 0, 0.05)
+ cs <- couponSchedule(nextIMMDate(workdate), as.Date("2017-12-20"), "Q",
+ "FLOAT", 0, 0.05,workdate)
nT <- dim(indexdist$L)[2]
Ngrid <- dim(indexdist$L)[1]
scenariosl <- matrix(0, length(dealweight), nT)
@@ -277,6 +278,7 @@ compute.delta <- function(indexdist, dealweight, cusip.pv, workdate=Sys.Date()){
cfdata <- getdealcf(dealnames, workdate)
availablecusips <- cusips[dealnamefromcusip(cusips) %in% names(cfdata)]
+## load dist into the namespace
load(file.path(root.dir, "Scenarios", "Calibration", sprintf("marketdata-%s.RData", calibration.date)))
cusipdata <- getcusipcf(availablecusips, cfdata, dist, workdate)
save.dir <- file.path(root.dir, "Scenarios", paste0("Prices_", workdate))
@@ -286,7 +288,7 @@ save(cusipdata, cfdata, file=file.path(save.dir, "cashflows.RData"),
## upload wapbasis
for(dealname in names(cfdata)){
sqlstring <- sprintf(paste0("UPDATE et_deal_model_numbers SET ",
- "wapbasis = '%s' WHERE dealname= '%s' AND updatedate = '%s'"),
+ "wapbasis = '%s' WHERE dealname= '%s' AND updatedate = '%s'"),
cfdata[[dealname]]$wapbasis*100,
dealname,
strftime(workdate))
diff --git a/R/script_calibrate_tranches.R b/R/script_calibrate_tranches.R
index ab86218b..8a1830ed 100644
--- a/R/script_calibrate_tranches.R
+++ b/R/script_calibrate_tranches.R
@@ -34,7 +34,7 @@ setEvaluationDate(as.Date(MarkitData$effectiveasof))
## calibrate HY19
## calibrate the single names curves
singlenames.data <- read.csv(file.path(root.dir, "Scenarios", "Calibration",
- paste0("hy19_singlenames_", workdate, ".csv")))
+ paste0("hy19_singlenames_", workdate, ".csv")))
nondefaulted <- singlenames.data[!singlenames.data$ticker %in% hy19$defaulted,]
bps <- 1e-4