aboutsummaryrefslogtreecommitdiffstats
path: root/R/calibration.R
diff options
context:
space:
mode:
Diffstat (limited to 'R/calibration.R')
-rw-r--r--R/calibration.R24
1 files changed, 24 insertions, 0 deletions
diff --git a/R/calibration.R b/R/calibration.R
index 762c3a53..ca9f9b9e 100644
--- a/R/calibration.R
+++ b/R/calibration.R
@@ -86,3 +86,27 @@ set.tranchedata <- function(index, tradedate){
}
return( index )
}
+
+build.skew <- function(index){
+ require(lossdistrib)
+ aux <- function(rho, index, K, quote, spread){
+ temp <- BCtranche.legs(index, K, rho)
+ return(abs(temp$pl+temp$cl*spread + quote))
+ }
+ rhovec <- c(0)
+ for(j in 1:(length(index$K)-2)){
+ ##use the current tranche coupon
+ ## we compute the 0-index$K[j+1] equivalent quote using the coupon of the jth quote
+ if(j==1){
+ q <- index$tranche.quotes[j]*index$K[j+1]
+ }else{
+ temp <- BCtranche.legs(index, index$K[j], rhovec[j])
+ q <- index$tranche.quotes[j] * (index$K[j+1]-index$K[j])-
+ temp$pl - temp$cl*index$tranche.running[j]
+ }
+ rho <- optimize(aux, interval=c(0,1), index=index, K=index$K[j+1], quote=q,
+ spread=index$tranche.running[j])$minimum
+ rhovec <- c(rhovec, rho)
+ }
+ return( c(rhovec, NA) )
+}