aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--R/cds_functions_generic.R11
-rw-r--r--R/script_calibrate_tranches.R4
-rw-r--r--R/tranche_functions.R7
3 files changed, 11 insertions, 11 deletions
diff --git a/R/cds_functions_generic.R b/R/cds_functions_generic.R
index 32c52e51..ae557729 100644
--- a/R/cds_functions_generic.R
+++ b/R/cds_functions_generic.R
@@ -666,14 +666,14 @@ survivalProbability.exact <- function(credit.curve, date) {
return( exp(as.numeric(logprob)) )
}
-SP <- function(sc){
+SP <- function(sc, startdate=Sys.Date()){
## computes the survival probability associated with the survival curve
- T <- c(0, yearFrac(Sys.Date(), sc@dates))
+ T <- c(0, yearFrac(startdate, sc@dates))
dT <- diff(T)
return( cumprod(exp(-sc@hazardrates * dT)) )
}
-SPmatrix <- function(portfolio, index){
+SPmatrix <- function(portfolio, n.dates){
## computes matrix of survival probability
## inputs:
## portfolio: portfolio of survival curves
@@ -682,10 +682,9 @@ SPmatrix <- function(portfolio, index){
## matrix of survival probabilities of dimensions dim1 x dim2
## with dim1 number of issuers and dim2 number of dates in the
## coupon schedule of index
- cs <- couponSchedule(IMMDate(Sys.Date()), index$maturity, "Q", "FIXED", index$coupon)
- SP <- matrix(0, length(portfolio), length(cs$dates))
+ SP <- matrix(0, length(portfolio), n.dates)
for(i in 1:length(portfolio)){
- SP[i,] <- SP(portfolio[[i]]@curve)[1:length(cs$dates)]
+ SP[i,] <- SP(portfolio[[i]]@curve, portfolio[[i]]@startdate)[1:n.dates]
}
return( SP )
}
diff --git a/R/script_calibrate_tranches.R b/R/script_calibrate_tranches.R
index a0f0afbf..1970ab8d 100644
--- a/R/script_calibrate_tranches.R
+++ b/R/script_calibrate_tranches.R
@@ -73,11 +73,11 @@ tranche.running <- c(0.05, 0.05, 0.05, 0.05)
# get the index ref
hy21$indexref <- market.data$bidRefPrice[1]/100
hy21portfolio.tweaked <- tweakcurves(hy21portfolio, hy21, tradedate)$portfolio
-SurvProb <- SPmatrix(hy21portfolio.tweaked, hy21)
+cs <- couponSchedule(IMMDate(tradedate), hy21$maturity,"Q", "FIXED", 0.05, 0, tradedate, IMMDate(tradedate, "prev"))
+SurvProb <- SPmatrix(hy21portfolio.tweaked, length(cs$dates))
Ngrid <- 2 * nrow(nondefaulted) + 1
recov <- sapply(hy21portfolio.tweaked, attr, "recovery")
-cs <- couponSchedule(IMMDate(tradedate), hy21$maturity,"Q", "FIXED", 0.05, 0, tradedate, IMMDate(tradedate, "prev"))
acc <- cdsAccrued(tradedate, 0.05)
##calibrate by modifying the factor distribution
bottomup <- 1:3
diff --git a/R/tranche_functions.R b/R/tranche_functions.R
index 39fd0b4d..ea3c2e32 100644
--- a/R/tranche_functions.R
+++ b/R/tranche_functions.R
@@ -712,7 +712,8 @@ BClossdistC <- function(defaultprob, issuerweights, recov, rho, Z, w,
return(list(L=r$L,R=r$R))
}
-BCtranche.pv <- function(portfolio, index, coupon, K1, K2, rho1, rho2, N=length(portfolio)+1){
+BCtranche.pv <- function(portfolio, index, coupon, K1, K2, rho1, rho2, N=length(portfolio)+1,
+ tradedate=Sys.Date()){
## computes the protection leg, couponleg, and bond price of a tranche
## in the base correlation setting
if(K1==0){
@@ -720,8 +721,8 @@ BCtranche.pv <- function(portfolio, index, coupon, K1, K2, rho1, rho2, N=length(
stop("equity tranche must have 0 lower correlation")
}
}
- SurvProb <- SPmatrix(portfolio, index)
- cs <- couponSchedule(IMMDate(Sys.Date()), index$maturity, "Q", "FIXED", coupon, 0)
+ cs <- couponSchedule(IMMDate(tradedate), index$maturity, "Q", "FIXED", coupon, 0, tradedate)
+ SurvProb <- SPmatrix(portfolio, length(cs$dates))
recov <- sapply(portfolio, attr, "recovery")
issuerweights <- rep(1/length(portfolio), length(portfolio))
K <- adjust.attachments(c(K1,K2), index$loss, index$factor)