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 a61dc394..32c52e51 100644 --- a/R/cds_functions_generic.R +++ b/R/cds_functions_generic.R @@ -461,7 +461,7 @@ cdshazardrate.shaped <- function(upfront, running, maturity, shape, R=0.4) { return(sc)
}
-cdshazardrate <- function(quotes, R=0.4, tradedate=Sys.Date()){
+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
@@ -474,15 +474,15 @@ cdshazardrate <- function(quotes, R=0.4, tradedate=Sys.Date()){ next
}
maturity <- quotes$maturity[i]
- cs <- couponSchedule(IMMDate(tradedate), maturity, "Q", "FIXED", quotes$running[i],
- tradedate, IMMDate(tradedate, "prev"))
+ cs <- cs.all[cs.all$dates<=maturity,]
+ cs$coupons <- cs$coupons * quotes$running[i]
new.h <- 0.05
flength <- nrow(cs) - nrow(previous.cs)
hvec <- c(previous.hvec, rep(new.h, flength))
sc <- new("defaultcurve", dates=cs$dates, hazardrates=hvec)
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){
+ while(abs(cdspv(cs, sc, R, tradedate) + quotes$upfront[i] - acc) > eps){
new.h <- new.h - (quotes$upfront[i] + cdspv(cs, sc, R, tradedate) - acc)/
dcdspv(cs, sc, R, index, tradedate)
hvec <- c(previous.hvec, rep(new.h, flength))
@@ -618,7 +618,7 @@ tweakcurves <- function(portfolio, index, tradedate=Sys.Date()){ }
epsilon <- optimize(f, c(-0.5, 0.5), portfolio, index, tol=1e-6)$minimum
cat("tweak = ", epsilon, "\n")
- return( tweakportfolio(portfolio, epsilon) )
+ return( list(portfolio=tweakportfolio(portfolio, epsilon), epsilon=epsilon) )
}
survivalProbability1 <- function(startdate, date, survival.curve) {
|
