diff options
| -rw-r--r-- | R/cds_functions_generic.R | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/R/cds_functions_generic.R b/R/cds_functions_generic.R index f64c062d..40912cde 100644 --- a/R/cds_functions_generic.R +++ b/R/cds_functions_generic.R @@ -23,9 +23,9 @@ setClass("defaultprepaycurve", representation(prepayrates="numeric"), contains=" setClass("creditcurve", representation(issuer="character", startdate="Date",
recovery="numeric", curve="defaultcurve"))
-shapedtodpc <- function(cs, sc, startdate=today()){
+shapedtodpc <- function(cs, sc){
## convert a shaped curve to a standard defaultprepaycuve
- T <- yearFrac(startdate, cs$dates)
+ T <- yearFrac(today(), cs$dates)
hvec <- sc@shape(T) * sc@h
kvec <- sc@alpha * exp(-sc@beta * hvec)
dpc <- new("defaultprepaycurve", hazardrates=hvec, prepayrates=kvec, dates=cs$dates)
@@ -39,8 +39,8 @@ setGeneric("couponleg", function(cs, sc, ...) { ## write couponleg methods for the four types of curves
setMethod("couponleg", signature("data.frame", "flatcurve"),
- function(cs, sc, accruedondefault=TRUE){
- T <- yearFrac(today(), cs$dates)
+ function(cs, sc, accruedondefault=TRUE, startdate=today()){
+ T <- yearFrac(startdate, cs$dates)
PD <- exp(- sc@h * T )
if(accruedondefault){
PDadj <- 0.5 * (c(1, PD[-length(PD)]) + PD)
@@ -101,7 +101,7 @@ setMethod("couponleg", signature("data.frame", "shapedcurve"), ## default and prepayment are independent, so the intensity of either event
## happenning is the sum of the two.
function(cs, sc, accruedondefault=TRUE, startdate=today()){
- return( couponleg(cs, shapedtodpc(cs, sc, startdate), accruedondefault, startdate) )
+ return( couponleg(cs, shapedtodpc(cs, sc), accruedondefault, startdate) )
})
## define dcouponleg generic
@@ -294,8 +294,8 @@ setGeneric("contingentleg", function(cs, sc, recovery, ...) { setMethod("contingentleg", signature("data.frame", "flatcurve", "numeric"),
## Computes the pv of the contingent leg of a cds based on a given
## coupon schedule, flat hazard rate, and recovery.
- function(cs, sc, recovery){
- T <- yearFrac(today(), cs$dates)
+ function(cs, sc, recovery, startdate=today()){
+ T <- yearFrac(startdate, cs$dates)
dT <- diff(c(0, T))
Q <- exp(-sc@h * T) * cs$df
Qmid <- 1/2 * (c(1, Q[-length(Q)]) + Q)
@@ -718,7 +718,7 @@ SPmatrix2 <- function(portfolio, dealdata, freq="3 months", startdate=Sys.Date() return(list(DP=DP, PP=PP))
}
-forwardportfolioprice <- function(portfolio, startdate, maturity, coupontype, margin, recovery, liborfloor){
+forwardportfolioprice <- function(portfolio, startdate, maturity, coupontype, margin, liborfloor){
if(missing(liborfloor)){
currentcoupon <- margin
}else{
|
