diff options
| -rw-r--r-- | R/thetas-durations.R | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/R/thetas-durations.R b/R/thetas-durations.R index 3d740eeb..defa54f4 100644 --- a/R/thetas-durations.R +++ b/R/thetas-durations.R @@ -2,6 +2,7 @@ library(ggplot2) library(lubridate) library(doParallel) library(dplyr) +library(tidyr) root.dir <- if(.Platform$OS.type == "unix"){ "/home/share/CorpCDOs" @@ -10,7 +11,7 @@ root.dir <- if(.Platform$OS.type == "unix"){ } hostname <- system("hostname", intern=TRUE) -registerDoParallel(4 if hostname=="debian" else 8) +registerDoParallel(if(hostname=="debian") 4 else 8) source(file.path(root.dir, "code", "R", "serenitasdb.R")) source(file.path(root.dir, "code", "R", "cds_functions_generic.R")) @@ -44,11 +45,9 @@ fastduration <- function(sc, cs, tradedate, maturities){ startdate <- tradedate+1 acc <- cdsAccrued(tradedate, 1) for(i in seq_along(maturities)){ - if(startdate>maturities[i]){ - r[i] <- NA - }else{ - r[i] <- couponleg(cs[cs$unadj.dates<=maturities[i],], sc, - startdate, accruedondefault=TRUE)-acc + r[i] <- if(startdate <= maturitities[i]){ + couponleg(cs[cs$unadj.dates<=maturities[i],], sc, + startdate, accruedondefault=TRUE)-acc } } return( r ) |
