diff options
Diffstat (limited to 'R/cds_functions_generic.R')
| -rw-r--r-- | R/cds_functions_generic.R | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/R/cds_functions_generic.R b/R/cds_functions_generic.R index 1db5ea7b..aadd99ba 100644 --- a/R/cds_functions_generic.R +++ b/R/cds_functions_generic.R @@ -720,7 +720,7 @@ DP2 <- function(sc, dates, startdate=Sys.Date()){ ## return( dates )
## }
-getdealschedule <- function(dealdata, freq="1 month", startdate= Sys.Date(), lag=0, adjust=FALSE){
+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]
}
@@ -735,14 +735,18 @@ getdealschedule <- function(dealdata, freq="1 month", startdate= Sys.Date(), lag sched <- c(adjust(calstring, sched[-length(sched)]), sched[length(sched)])
base::names(sched) <- NULL
}
-
return(sched)
}
+getsettledate <- function(tradedate, settledays = 3, calendar="UnitedStates/GovernmentBond"){
+ return(advance(calendar=calendar, tradedate, n = settledays, timeUnit = 0))
+}
+
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
- dates <- getdealschedule(dealdata, freq, startdate)
+ dates <- getdealschedule(dealdata, freq)
+ dates <- dates[dates>=getsettledate(startdate)]
DP <- matrix(0, length(portfolio), length(dates))
PP <- matrix(0, length(portfolio), length(dates))
for(i in seq_along(portfolio)){
|
