diff options
Diffstat (limited to 'R')
| -rw-r--r-- | R/cds_functions_generic.R | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/R/cds_functions_generic.R b/R/cds_functions_generic.R index a6b83a07..37cfb56e 100644 --- a/R/cds_functions_generic.R +++ b/R/cds_functions_generic.R @@ -660,7 +660,7 @@ indextheta <- function(index, tradedate=Sys.Date(), maturity=index$maturity) { if(nrow(index$cs) <= 4) {
return( NA )
}
- current.pv <- indexpv(index, tradedate=tradedate)$bp
+ current.pv <- indexpv(index, tradedate=tradedate, maturity=maturity)$bp
newmaturity <- 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]
@@ -703,16 +703,17 @@ tweakcurves <- function(index, tradedate=Sys.Date()){ ## computes the tweaking factor
epsilon <- rep(0, nrow(index$quotes))
for(i in 1:nrow(index$quotes)){
- if(i==1){
+ if(i == 1){
forward.tweak <- 1
}else{
- forward.tweak <- which.min(index$cs$dates>index$quotes$maturity[i-1])
+ forward.tweak <- which(index$cs$unadj.dates>index$quotes$maturity[i-1])[1]
}
- f <- function(epsilon, ...){
+ f <- function(epsilon, index, tradedate, forward.tweak, i){
abs(indexpv(index, epsilon, tradedate, maturity=index$quotes$maturity[i],
forward.tweak=forward.tweak)$bp - index$quotes$price[i])
}
- epsilon[i] <- optimize(f, c(-0.25, 0.30), index, tol=1e-6)$minimum
+ epsilon[i] <- optimize(f, c(-0.25, 0.30),
+ index, tradedate, forward.tweak, i, tol=1e-6)$minimum
index$portfolio <- tweakportfolio(index$portfolio, epsilon[i], forward.tweak=forward.tweak)
loginfo(paste("tweak =", epsilon[i]))
}
|
