diff options
| -rw-r--r-- | R/load_cf.R | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/R/load_cf.R b/R/load_cf.R index 737638c0..241543b6 100644 --- a/R/load_cf.R +++ b/R/load_cf.R @@ -32,6 +32,7 @@ index <- set.index.desc(index, tradedate) calibration.date <- addBusDay(tradedate, -1)
exportYC(calibration.date)
+cs <- couponSchedule(IMMDate(calibration.date, noadj=TRUE), index$maturity, "Q", "FLOAT", 0, 0.05)
dm <- 0
sanitize.column <- function(vec){
@@ -144,6 +145,7 @@ getdealcf <- function(dealnames, zipfiles, tradedate=Sys.Date()){ cf <- cf+cfdata[[dealname]][[tranche]][,"Cashflow"]
}
cf <- cf-min(dealdata$"Principal Bal", 0)
+ cfdata[[dealname]]$price <- cf/dealdata$mv
cfdata[[dealname]]$wapbasis <- (mean(cf)- dealdata$mv)/dealdata$mv
program <- tryCatch(KLfit(t(cf)/1e8, rep(1/n.scenarios, n.scenarios),
dealdata$mv/1e8), error=function(e) e)
@@ -212,8 +214,7 @@ getcusipcf <- function(params, cfdata, dist, tradedate=Sys.Date()){ wal = crossprod(cfdata[[dealname]]$weight, r[,"wal"]),
duration = crossprod(cfdata[[dealname]]$weight, r[,"duration"]),
price = 100 * temp/indicdata$curr_balance,
- delta = compute.delta(dist, cfdata[[dealname]]$weight,
- r[,"Cashflow"]/indicdata$curr_balance, tradedate),
+ delta = compute.delta(dist, cfdata[[dealname]], r[,"Cashflow"]/indicdata$curr_balance),
fields=r))
})
cat("done", cusip, "\n")
@@ -222,11 +223,9 @@ getcusipcf <- function(params, cfdata, dist, tradedate=Sys.Date()){ return(cusipdata)
}
-compute.delta <- function(indexdist, dealweight, cusip.pv, tradedate=Sys.Date(), K1=0, K2=1){
- calibration.date <- addBusDay(tradedate, -1)
- ## 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(IMMDate(calibration.date), index$maturity, "Q", "FLOAT", 0.05, 0)
+compute.delta <- function(indexdist, dealdata, cusip.pv, K1=0, K2=1){
+ dealweight <- dealdata$weight
+ dealprice <- dealdata$price
nT <- dim(indexdist$L)[2]
Ngrid <- dim(indexdist$L)[1]
scenariosl <- matrix(0, length(dealweight), nT)
@@ -235,12 +234,15 @@ compute.delta <- function(indexdist, dealweight, cusip.pv, tradedate=Sys.Date(), scenariosl[,t] <- interpvalues(indexdist$L[,t], seq(0, 1, length=Ngrid), dealweight)
scenariosr[,t] <- interpvalues(indexdist$R[,t], seq(0, 1, length=Ngrid), dealweight)
}
+ ## we assume the index is fully funded - need to be changed depending
+ ## on how we fund the swaps (hence floating coupon instead of fixed)
indexpv <- c()
for(i in 1:length(dealweight)){
indexpv <- c(indexpv, funded.tranche.pv(scenariosl[i,], scenariosr[i,], cs, K1, K2, TRUE))
}
- model <- lm(cusip.pv~indexpv, weights=dealweight)
- return(model$coef[2])
+ model1 <- lm(cusip.pv~dealprice, weights=dealweight)
+ model2 <- lm(dealprice~indexpv, weights=dealweight)
+ return(model1$coef[2]/model2$coef[2])
}
if(length(args)>=2){
|
