aboutsummaryrefslogtreecommitdiffstats
path: root/R/cds_functions_generic.R
diff options
context:
space:
mode:
Diffstat (limited to 'R/cds_functions_generic.R')
-rw-r--r--R/cds_functions_generic.R20
1 files changed, 9 insertions, 11 deletions
diff --git a/R/cds_functions_generic.R b/R/cds_functions_generic.R
index 5407ccaa..6ccf7c37 100644
--- a/R/cds_functions_generic.R
+++ b/R/cds_functions_generic.R
@@ -608,10 +608,9 @@ indexpv <- function(index, epsilon=0, tradedate=Sys.Date(), clean=TRUE,
portfolio <- index$portfolio
}
startdate <- tradedate + 1
- #ugly hack
- cs <- index$cs[index$cs$dates-maturity< 3,]
- cl.list <- unlist(lapply(portfolio, function(x){couponleg(cs, x@curve, startdate)}))
- pl.list <- unlist(lapply(portfolio, function(x){defaultleg(cs, x@curve, x@recovery, startdate)}))
+ cs <- index$cs[index$cs$unadj.dates <= maturity,]
+ cl.list <- unlist(lapply(portfolio, function(x) couponleg(cs, x@curve, startdate)))
+ pl.list <- unlist(lapply(portfolio, function(x) defaultleg(cs, x@curve, x@recovery, startdate)))
if(check){
if(any(is.na(cl.list))){
logerror(paste("couldn't compute single name protection leg for",
@@ -639,7 +638,7 @@ indexduration <- function(index, tradedate, maturity=index$maturity){
## compute the duration of a portfolio of survival curves
cs <- index$cs[index$cs$dates-maturity< 3,]
startdate <- tradedate+1
- cl.list <- unlist(lapply(index$portfolio, function(x){couponleg(cs, x@curve, startdate)}))
+ cl.list <- unlist(lapply(index$portfolio, function(x) couponleg(cs, x@curve, startdate) ))
return( mean(cl.list) )
}
@@ -656,15 +655,14 @@ indexspread <- function(index, tradedate=Sys.Date()){
return(S)
}
-indextheta <- function(index, tradedate=Sys.Date()){
- if(nrow(index$cs)<=4){
+indextheta <- function(index, tradedate=Sys.Date()) {
+ if(nrow(index$cs) <= 4) {
return( NA )
}
current.pv <- indexpv(index, tradedate=tradedate)$bp
- newmaturity <- index$cs$unadj.dates[nrow(index$cs)-4]
- index$quotes$maturity <- newmaturity
- forward.pv <- indexpv(index, tradedate=tradedate, maturity=newmaturity)$bp
- theta <- forward.pv-current.pv+index$quotes$spread
+ newmaturity <- index$maturity - lubridate::years(1)
+ rolled.pv <- indexpv(index, tradedate=tradedate, maturity=newmaturity)$bp
+ theta <- rolled.pv - current.pv + index$quotes$spread[index$quotes$maturity == index$maturity]
return( theta )
}