aboutsummaryrefslogtreecommitdiffstats
path: root/R/cds_functions_generic.R
diff options
context:
space:
mode:
Diffstat (limited to 'R/cds_functions_generic.R')
-rw-r--r--R/cds_functions_generic.R20
1 files changed, 10 insertions, 10 deletions
diff --git a/R/cds_functions_generic.R b/R/cds_functions_generic.R
index 8ed227a0..a61dc394 100644
--- a/R/cds_functions_generic.R
+++ b/R/cds_functions_generic.R
@@ -27,7 +27,7 @@ setClass("defaultprepaycurve", representation(prepayrates="numeric"), contains="
setClass("creditcurve", representation(issuer="character", startdate="Date",
recovery="numeric", curve="defaultcurve"))
-shapedtodpc <- function(cs, sc, startdate){
+shapedtodpc <- function(cs, sc, startdate=Sys.Date()){
## convert a shaped curve to a standard defaultprepaycuve
T <- yearFrac(startdate, cs$dates)
hvec <- sc@shape(T) * sc@h
@@ -428,14 +428,14 @@ dcdspv <- function(cs, sc, recovery, index, tradedate){
}
bondpv <- function(cs, sc, recovery, tradedate=Sys.Date()){
- return( contingentleg(cs, sc, recovery) + couponleg(cs, sc) )
+ return( contingentleg(cs, sc, recovery, tradedate) + couponleg(cs, sc, tradedate) )
}
-dbondpv <- function(cs, sc, recovery, index){
+dbondpv <- function(cs, sc, recovery, index, startdate){
if(missing(index)){
- return( dcontingentleg(cs, sc, recovery) + dcouponleg(cs, sc))
+ return( dcontingentleg(cs, sc, recovery, ,startdate) + dcouponleg(cs, sc, ,startdate))
}else{
- return( dcontingentleg(cs, sc, recovery, index)+dcouponleg(cs, sc, index) )
+ return( dcontingentleg(cs, sc, recovery, index, startdate)+dcouponleg(cs, sc, index, startdate) )
}
}
@@ -495,22 +495,22 @@ cdshazardrate <- function(quotes, R=0.4, tradedate=Sys.Date()){
return(sc)
}
-bondhazardrate.shaped <- function(collateral, shape, R=0.4, alpha=0.25, beta=15){
+bondhazardrate.shaped <- function(collateral, shape, R=0.4, alpha=0.25, beta=15, startdate=Sys.Date()){
## calibrate a default prepay curve to the collateral information
cs <- couponSchedule(collateral$nextpaydate, collateral$maturity,
collateral$frequency, collateral$fixedorfloat,
- collateral$grosscoupon*0.01, collateral$spread*0.01)
+ collateral$grosscoupon*0.01, collateral$spread*0.01, startdate)
sc <- new("shapedcurve", h=0.05, shape=shape, alpha=alpha, beta=beta)
eps <- 1e-8
counter <- 0
if(collateral$price<2){
cat("price is too low\n")
sc <- new("shapedcurve", h=1e6, shape=shape, alpha=alpha, beta=beta)
- return( shapedtodpc(cs, sc) )
+ return( shapedtodpc(cs, sc, startdate) )
}
while(abs(bondpv(cs, sc, R) - collateral$price/100) > eps){
- dh <- (collateral$price/100 - bondpv(cs, sc, R))/dbondpv(cs, sc, R)
+ dh <- (collateral$price/100 - bondpv(cs, sc, R, startdate))/dbondpv(cs, sc, R, ,startdate)
while(sc@h+dh<0){
dh <- 0.5 * dh
}
@@ -521,7 +521,7 @@ bondhazardrate.shaped <- function(collateral, shape, R=0.4, alpha=0.25, beta=15)
stop("didn't reach convergence")
}
}
- return( shapedtodpc(cs, sc) )
+ return( shapedtodpc(cs, sc, startdate) )
}
tweakportfolio <- function(portfolio, epsilon, multiplicative=TRUE){