diff options
Diffstat (limited to 'R/load_cf.R')
| -rw-r--r-- | R/load_cf.R | 35 |
1 files changed, 21 insertions, 14 deletions
diff --git a/R/load_cf.R b/R/load_cf.R index 82bc33cd..fe8727e8 100644 --- a/R/load_cf.R +++ b/R/load_cf.R @@ -23,17 +23,21 @@ source(file.path(root.dir, "code", "R", "cds_utils.R")) source(file.path(root.dir, "code", "R", "intex_deal_functions.R"))
source(file.path(root.dir, "code", "R", "optimization.R"))
source(file.path(root.dir, "code", "R", "interpweights.R"))
+source(file.path(root.dir, "code", "R", "index_definitions.R"))
calibration.date <- prevBusDay(workdate)
MarkitData <- getMarkitIRData(calibration.date)
-L1m <- buildMarkitYC(MarkitData, dt = 1/12)
-L2m <- buildMarkitYC(MarkitData, dt = 1/6)
-L3m <- buildMarkitYC(MarkitData)
-L6m <- buildMarkitYC(MarkitData, dt = 1/2)
-L12m <- buildMarkitYC(MarkitData, dt = 1)
+futurequotes <- read.csv(file.path(root.dir, "data", "Yield Curves",
+ sprintf("futures-%s.csv", calibration.date)), header=F)
setEvaluationDate(as.Date(MarkitData$effectiveasof))
-dm <- 0
+setCalendarContext("UnitedStates/GovernmentBond")
+L1m <- buildMarkitYC(MarkitData, futurequotes[,2], dt = 1/12)
+L2m <- buildMarkitYC(MarkitData, futurequotes[,2], dt = 1/6)
+L3m <- buildMarkitYC(MarkitData, futurequotes[,2])
+L6m <- buildMarkitYC(MarkitData, futurequotes[,2], dt = 1/2)
+L12m <- buildMarkitYC(MarkitData, futurequotes[,2], dt = 1)
+dm <- 0
sanitize.column <- function(vec){
vec <- gsub(",", "", vec)
index <- grep("\\(", vec)
@@ -117,7 +121,7 @@ getdealcf2 <- function(tb){ wal=sum(-diff(Balance)*T[-1])/cusipdata[Dealname]$curr_balance,
duration=if(temp==0) 0 else sum(Cashflow * Discounts * T)/temp
), by=list(Dealname,Scenario)]
-
+
setkey(data, "Dealname")
cfdata <- list()
for(dealname in dealnames){
@@ -182,6 +186,9 @@ getdealcf <- function(dealnames, workdate=Sys.Date()){ tranches <- "COLLAT"
}else{
tranches <- c("COLLAT_INITIAL", "COLLAT_REINVEST")
+ if(dealname=="octag11"){
+ tranches <- c("COLLAT_USD_INITIAL", "COLLAT_USD_REINVEST")
+ }
}
for(tranche in tranches){
for(i in 1:n.scenarios){
@@ -355,12 +362,12 @@ getcusipcf <- function(cusips, cfdata, dist, workdate=Sys.Date()){ }else{
val <- crossprod(cfdata[[dealname]]$weight, r[,c("Cashflow", "wal", "duration")])
cusipdata[[cusip]] <- c(cusipdata[[cusip]],
- fields = r,
- price = 100 * val[,"Cashflow"]/cusipdata[[cusip]]$currbal,
- wal = val[,"wal"],
- duration = val[,"duration"],
- delta = compute.delta(dist, cfdata[[dealname]]$weight,
- r[,"Cashflow"]/cusipdata[[cusip]]$currbal, workdate))
+ list(fields = r,
+ price = 100 * val[,"Cashflow"]/cusipdata[[cusip]]$currbal,
+ wal = val[,"wal"],
+ duration = val[,"duration"],
+ delta = compute.delta(dist, cfdata[[dealname]]$weight,
+ r[,"Cashflow"]/cusipdata[[cusip]]$currbal, workdate)))
cat("done", cusip, "\n")
}
}
@@ -371,7 +378,7 @@ compute.delta <- function(indexdist, dealweight, cusip.pv, workdate=Sys.Date()){ calibration.date <- prevBusDay(workdate)
## we assume the index is fully funded - need to be changed depending
## on how we fund the swaps (hence floating coupon instead of fixed)
- cs <- couponSchedule(nextIMMDate(workdate), as.Date("2017-12-20"), "Q",
+ cs <- couponSchedule(nextIMMDate(workdate), hy21$maturity, "Q",
"FLOAT", 0.05, 0, calibration.date)
nT <- dim(indexdist$L)[2]
Ngrid <- dim(indexdist$L)[1]
|
