aboutsummaryrefslogtreecommitdiffstats
path: root/R/load_cf.R
diff options
context:
space:
mode:
Diffstat (limited to 'R/load_cf.R')
-rw-r--r--R/load_cf.R31
1 files changed, 28 insertions, 3 deletions
diff --git a/R/load_cf.R b/R/load_cf.R
index 383d7649..3c62e75e 100644
--- a/R/load_cf.R
+++ b/R/load_cf.R
@@ -12,7 +12,7 @@ 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"))
-workdate <- as.Date("2013-02-14")
+workdate <- as.Date("2013-02-11")
MarkitData <- getMarkitIRData(workdate)
L1m <- buildMarkitYC(MarkitData, dt = 1/12)
@@ -142,7 +142,7 @@ getdealcf <- function(dealnames, workdate=Sys.Date()){
return( cfdata )
}
-getcusipcf <- function(cusips, cfdata, workdate=Sys.Date()){
+getcusipcf <- function(cusips, cfdata, dist, workdate=Sys.Date()){
flag <- FALSE
cusipdata <- list()
dealnames <- dealnamefromcusip(cusips)
@@ -235,6 +235,11 @@ getcusipcf <- function(cusips, cfdata, workdate=Sys.Date()){
cusipdata[[cusip]]$fields[,"wal"])
cusipdata[[cusip]]$duration <- crossprod(cfdata[[dealnames[i]]]$weight,
cusipdata[[cusip]]$fields[,"duration"])
+ cusipdata[[cusip]]$delta <-
+ compute.delta(dist, cfdata[[dealnames[i]]]$weight,
+ cusipdata[[cusip]]$fields[,"Cashflow"]/cusipdata[[cusip]]$currbal,
+ workdate)
+
}
}
return(cusipdata)
@@ -242,7 +247,8 @@ getcusipcf <- function(cusips, cfdata, workdate=Sys.Date()){
cfdata <- getdealcf(dealnames, workdate)
availablecusips <- cusips[dealnamefromcusip(cusips) %in% names(cfdata)]
-cusipdata <- getcusipcf(availablecusips, cfdata, workdate)
+load(file.path(root.dir, "Scenarios", "Calibration", sprintf("marketdata-%s.RData", workdate)))
+cusipdata <- getcusipcf(availablecusips[1:3], cfdata, dist, workdate)
## upload wapbasis
for(dealname in names(cfdata)){
sqlstring <- sprintf(paste0("UPDATE et_deal_model_numbers SET ",
@@ -286,3 +292,22 @@ for(cusip in names(cusipdata)){
dbSendQuery(dbCon, sqlstring)
}
+compute.delta <- function(indexdist, dealweight, cusip.pv, workdate=Sys.Date()){
+ indexpv <- c()
+ cs <- couponSchedule(nextIMMDate(workdate), as.Date("2017-12-20"), "Q", "FLOAT", 0, 0.05)
+ nT <- dim(indexdist$L)[2]
+ Ngrid <- dim(indexdist$L)[1]
+ scenariosl <- matrix(0, length(dealweight), nT)
+ scenariosr <- matrix(0, length(dealweight), nT)
+ for(t in 1:nT){
+ scenariosl[,t] <- interpvalues(indexdist$L[,t], seq(0, 1, length=Ngrid), dealweight)
+ scenariosr[,t] <- interpvalues(indexdist$R[,t], seq(0, 1, length=Ngrid), dealweight)
+ }
+
+ indexpv <- c()
+ for(i in 1:length(dealweight)){
+ indexpv <- c(indexpv, funded.tranche.pv(scenariosl[i,], scenariosr[i,], cs, 0, 1))
+ }
+ model <- lm(cusip.pv~0+indexpv, weights=dealweight)
+ return(model$coef)
+}