diff options
Diffstat (limited to 'R/test_options.R')
| -rw-r--r-- | R/test_options.R | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/R/test_options.R b/R/test_options.R index 5b8ab782..ef90c1f0 100644 --- a/R/test_options.R +++ b/R/test_options.R @@ -38,3 +38,23 @@ for(i in seq_along(exerciseDates)){ fp <- c(fp, defaultAdjustedForwardIndexPrice(newindex, exerciseDates[i])) fp2 <- c(fp2, forwardflatcds(h, index$cs, tradedate, exerciseDates[i], fixedRate=0.05, R=0.3)) } + +calib <- function(S0, index, fp, exerciseDate, sigma, quad){ + T <- yearFrac(index$tradedate, exerciseDate) + S <- S0 * exp(-sigma^2/2*T+sigma*quad$Z*sqrt(T)) + guess <- crossprod(quad$w, unlist(lapply(S, function(S){ + snacpv(index$cs, S, index$quotes$refspread, index$recovery, exerciseDate)}))) + return( guess - fp ) +} + +option <- function(index, fp, exerciseDate, sigma, strike, quad){ + T <- yearFrac(index$tradedate, exerciseDate) + S0 <- uniroot(calib, interval=c(0.02, 0.05), index, fp, exerciseDate, sigma, quad)$root + S <- S0 * exp(-sigma^2/2*T+sigma*quad$Z*sqrt(T)) + v <- matrix(0, length(S), 2) + for(i in 1:length(S)){ + fw <- snacpv(index$cs, S[i], index$quotes$refspread, index$recovery, exerciseDate) + v[i,] <-c(max(fw-strike, 0), max(strike-fw, 0)) + } + return(crossprod(quad$w, v)) +} |
