1 | LookbackMC(o = OptPx(Opt(Style = "Lookback"), r = 0.05, q = 0, vol = 0.3, ), NPaths = 10000, div = 1000, Type = c("Floating", "Fixed"))
|
o |
|
NPaths |
|
div |
|
Type |
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 | ##---- 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 = "Lookback"), r = 0.05, q = 0,
vol = 0.3, ), NPaths = 10000, div = 1000, Type = c("Floating",
"Fixed"))
{
stopifnot(is(o, "OptPx"), o$Style$Name == "Lookback", is.character(Type),
is.numeric(NPaths), is.numeric(div))
o.class = class(o)
Type = match.arg(Type)
isFixed = switch(Type, Fixed = T, Floating = F)
isFloating = !isFixed
dt = o$ttm/div
payoffs = replicate(NPaths, {
ds.s = (o$r - o$q) * dt + o$vol * sqrt(dt) * rnorm(div)
st = c(o$S0, o$S0 * cumprod(1 + ds.s))
smax = max(st)
smin = min(st)
if (isFloating) {
K = smax * o$Right$Put + smin * o$Right$Call
ST = st[length(st)]
}
else if (isFixed) {
K = o$K
ST = smin * o$Right$Put + smax * o$Right$Call
}
payoff = exp(-o$r * o$ttm) * o$Right$SignCP * (max(ST -
K))
})
p = mean(payoffs)
o$isFixed = isFixed
o$isFloating = !isFixed
o$NPaths = NPaths
o$PxMC = p
class(o) = o.class
return(o)
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.