diff options
Diffstat (limited to 'R/cds_functions_generic.R')
| -rw-r--r-- | R/cds_functions_generic.R | 81 |
1 files changed, 0 insertions, 81 deletions
diff --git a/R/cds_functions_generic.R b/R/cds_functions_generic.R index f642ebb5..eb851b2c 100644 --- a/R/cds_functions_generic.R +++ b/R/cds_functions_generic.R @@ -695,52 +695,6 @@ DP2 <- function(sc, dates, startdate=Sys.Date()){ prepayprob = cumsum(pfun(x2T) * Qmid * dT)))
}
-## getdealschedule <- function(dealdata, freq="3 months", startdate = Sys.Date(), lag = 0){
-## calstring <- "UnitedStates/GovernmentBond"
-## settledate <- advance(calendar = calstring,
-## dates = startdate,
-## n = 3,
-## timeUnit = 0)
-## nextpaydate <- dealdata$"Deal Next Pay Date"
-## ## "Deal Next Pay Date" might be stale in the database
-## if(dealdata$"Deal Next Pay Date" < settledate){
-## prevpaydate <- dealdata$"Deal Next Pay Date"
-## nextpaydate <- advance(calendar = calstring,
-## dates = dealdata$"Deal Next Pay Date",
-## n = 3,
-## timeUnit = 2)
-## }else{
-## prevpaydate <- advance(calendar = calstring,
-## dates = dealdata$"Deal Next Pay Date",
-## n = -3,
-## timeUnit = 2)
-## }
-## dates <- seq(prevpaydate, dealdata$maturity + lag, by=freq)
-## dates <- dates[dates>settledate]
-## return( dates )
-## }
-
-getdealschedule <- function(dealdata, freq="1 month", lag=0, adjust=FALSE){
- if(is.null(dealdata$"Pay Day")||(abs(as.numeric(dealdata$"Deal Next Pay Date"- dealdata$"Pay Day") - 90)>10)){
- dealdata$"Pay Day" <- seq(dealdata$"Deal Next Pay Date", length=2, by="-3 months")[2]
- }
- n <- if(freq == "1 month") 1 else 3
- sched <- dealdata$"Pay Day"
- i <- 1
- bdc <- if(adjust) 0 else 4
- nextdate <- advance(calendar = "UnitedStates", dates=dealdata$"Pay Day", n*i, 2, bdc=bdc)
- while(nextdate<= dealdata$"maturity" + lag){
- sched <- c(sched, nextdate)
- i <- i+1
- nextdate <- advance(calendar = "UnitedStates", dates=dealdata$"Pay Day", n*i, 2, bdc=bdc)
- }
- ##always add the maturity
- if(sched[length(sched)] < dealdata$maturity){
- sched <- c(sched, dealdata$maturity)
- }
- return(sched)
-}
-
SPmatrix2 <- function(portfolio, dealdata, freq="3 months", startdate=Sys.Date()){
## computes the default and prepay probability matrix of a portfolio
## at the dates specified from dealdata
@@ -756,41 +710,6 @@ SPmatrix2 <- function(portfolio, dealdata, freq="3 months", startdate=Sys.Date() return(list(DP=DP, PP=PP))
}
-forwardportfolioprice <- function(portfolio, startdate, maturity, coupontype, margin, liborfloor){
- if(missing(liborfloor)||is.na(liborfloor)){
- currentcoupon <- margin
- }else{
- currentcoupon <- margin + liborfloor
- }
- forwardcs <- couponSchedule(nextpaydate=startdate+45, maturity,
- frequency="Q", coupontype, margin,
- currentcoupon, startdate=startdate)
- fixedcs <- couponSchedule(nextpaydate=startdate+45, maturity, frequency="Q", "FIXED", 1,
- startdate=startdate)
- ##select curves that have non zero lengthhazardrates
- idx <- unlist(lapply(portfolio$SC, function(x)length(x@curve@hazardrates)>0))
- price <- function(x, ...){
- cl <- couponleg(forwardcs, x@curve, startdate)
- pl <- contingentleg(forwardcs, x@curve, x@recovery, startdate)
- return( pl + cl)
- }
-
- ## duration <- function(x, ...){
- ## return( couponleg(fixedcs, x@curve))
- ## }
- ## durationvec <- unlist(lapply(portfolio$SC[idx], function(x){couponleg(fixedcs, x@curve)}))
- ## if(all(durationvec==0)){
- ## return(1)
- ## }else{
- ## return(crossprod(portfolio$notional[idx] * durationvec,
- ## vapply(portfolio$SC[idx], price, numeric(1)))/
- ## crossprod(portfolio$notional[idx], durationvec))
- ## }
- return(crossprod(portfolio$notional[idx],
- vapply(portfolio$SC[idx], price, numeric(1)))/
- sum(portfolio$notional[idx]))
-}
-
creditcurve.maturity <- function(creditcurve){
if(class(creditcurve)=="creditcurve"){
dates <- creditcurve@curve@dates
|
