1 |
o |
|
ttc |
|
IncBT |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | ##---- Should be DIRECTLY executable !! ----
##-- ==> Define data, use random,
##-- or do help(data=index) for the standard data sets.
## The function is currently defined as
function (o = OptPx(Opt(Style = "Chooser")), ttc = 0.5, IncBT = FALSE)
{
stopifnot(is.OptPx(o), o$Style$Chooser, is.numeric(ttc))
NSteps = o$NSteps
p = o$p
K = o$K
step.ttc = ttc/o$ttm * NSteps
S = with(o, S0 * d^(0:NSteps) * u^(NSteps:0))
O.call = pmax((S - K), 0)
O.put = pmax(-(S - K), 0)
O.chooser = c()
ReCalc.O_S.on.Prior.Time.Step = function(i) {
if (i >= step.ttc + 1) {
O.call <<- o$DF_dt * (p * O.call[-i - 1] + (1 - p) *
O.call[-1])
O.put <<- o$DF_dt * (p * O.put[-i - 1] + (1 - p) *
O.put[-1])
S <<- o$d * S[-i - 1]
Payout.call = pmax((S - K), 0)
Payout.put = pmax(-(S - K), 0)
if (o$Style$American == TRUE) {
O.call <<- pmax(O.call, Payout.call)
O.put <<- pmax(O.put, Payout.put)
}
return(cbind(S, O.call, O.put))
}
else if (i == step.ttc) {
S <<- o$d * S[-i - 1]
O.chooser <<- o$DF_dt * (p * pmax(O.call[-i - 1],
O.put[-i - 1]) + (1 - p) * pmax(O.call[-1], O.put[-1]))
Payout.call = pmax((S - K), 0)
Payout.put = pmax(-(S - K), 0)
if (o$Style$American == TRUE) {
O.chooser <<- pmax(O.chooser, Payout.call, Payout.put)
}
return(cbind(S, O.chooser))
}
else {
S <<- o$d * S[-i - 1]
O.chooser <<- o$DF_dt * (p * O.chooser[-i - 1] +
(1 - p) * O.chooser[-1])
Payout.call = pmax((S - K), 0)
Payout.put = pmax(-(S - K), 0)
if (o$Style$American == TRUE) {
O.chooser <<- pmax(O.chooser, Payout.call, Payout.put)
}
return(cbind(S, O.chooser))
}
}
BT = append(list(cbind(S, O.call, O.put)), sapply(NSteps:1,
ReCalc.O_S.on.Prior.Time.Step))
o$ttc <- ttc
o$IncBT <- IncBT
o$PxLT = BT[[length(BT)]][[2]]
if (IncBT)
o$BT = BT
return(o)
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.