diff options
Diffstat (limited to 'R/cds_functions_generic.R')
| -rw-r--r-- | R/cds_functions_generic.R | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/R/cds_functions_generic.R b/R/cds_functions_generic.R index 37cfb56e..ea44abce 100644 --- a/R/cds_functions_generic.R +++ b/R/cds_functions_generic.R @@ -512,25 +512,25 @@ cdshazardrate <- function(quotes, R=0.4, tradedate=Sys.Date(), cs.all){ ## bootstrap the implied hazard rate curve of the cds based on the upfront
## and running quotes, as well as maturity and recovery
previous.maturity <- tradedate
- hvec <- c()
previous.hvec <- c()
eps <- 1e-8
previous.cs <- data.frame()
sc <- NULL
for(i in 1:nrow(quotes)){
- if(is.na(quotes$upfront[i])){
- next
- }
maturity <- quotes$maturity[i]
if(tradedate+1>=maturity){
next
}
cs <- cs.all[cs.all$unadj.dates<=maturity,]
cs$coupons <- cs$coupons * quotes$running[i]
- new.h <- 0.05
+
+ new.h <- if(is.null(previous.hvec)) 0.05 else previous.hvec[length(previous.hvec)]
flength <- nrow(cs) - nrow(previous.cs)
hvec <- c(previous.hvec, rep(new.h, flength))
sc <- new("defaultcurve", dates=cs$dates, hazardrates=hvec)
+ if(is.na(quotes$upfront[i])){
+ next
+ }
index <- c(rep(0, length(previous.hvec)), rep(1, flength))
acc <- cdsAccrued(tradedate, quotes$running[i])
while(abs(cdspv(cs, sc, R, tradedate) + quotes$upfront[i] - acc) > eps){
|
