Description Usage Arguments Details Value Author(s) References Examples

A collection and description of functions to valuate
options by Monte Carlo methods. The functions include
beside the main Monte Carlo Simulator, example functions
to generate Monte Carlo price paths and to compute
Monte Carlo price payoffs.

The functions are:

`sobolInnovations` | Example for scrambled Sobol innovations, |

`wienerPath` | Example for a Wiener price path, |

`plainVanillaPayoff` | Example for the plain vanilla option's payoff, |

`arithmeticAsianPayoff` | Example for the arithmetic Asian option's payoff, |

`MonteCarloOption` | Monte Carlo Simulator for options. |

1 2 3 |

`antithetic` |
a logical flag, should antithetic variates be used? By default TRUE. |

`delta.t` |
the time step interval measured as a fraction of one
year, by default one day, i.e. |

`init` |
a logical flag, should the random number generator be initialized? By default TRUE. |

`innovations.gen` |
a user defined function to generate the innovations, this can
be the normal random number generator |

`mcLoops, mcSteps` |
the number of Monte Carlo loops and Monte Carlo Steps.
In total |

`path.gen` |
the user defined function to generate the price path. As the only input argument serves the matrix of innovations, the option parameters must be available as global variables. |

`pathLength` |
the length of the price path. This may be calculated
as |

`payoff.calc` |
a user defined function to calculate the payoff of the option. As the only input argument serves the path matrix as returned by the path generator. The option parameters must be available as global variables. |

`standardization` |
a logical flag, should the innovations for one loop be standardized? By default TRUE. |

`trace` |
a logical flag, should the Monte Carlo simulation be traced? By default TRUE. |

`...` |
additional arguments passed to the innovations generator. |

**The Innovations:**

The innovations must created by the user defined innovation generator.
The Generator has to return a numeric matrix of (random) innovations
of size `mcSteps`

times the `pathLength`

. The example
section shows how to write sa function for scrambled Quasi Monte Carlo
Sobol numbers. The package comes with three generators
`rnorm.pseudo`

, `rnorm.halton`

and `rnorm.sobol`

which can easily be used for simulations.

**The Price Paths:**

The user must provide a function which generates the price paths.
In the example section the function `wienerPath`

creates a
Wiener Monte Carlo path from random innovations.
The Wiener price path requires as input `b`

, the annualized
cost-of-carry rate, and `sigma`

, the annualized volatility of
the underlying security, to compute the drift and variance of the
path, these variables must be globally defined.

**The Payoff Function:**

The user must also provide a function which computes the payoff
value of the option. The example sections show how to write
payoff calculators for the plain vanilla option and for the
arithmetic Asian Option. As the only input argument the path matrix
is required. Again, the option parameters must be globally available.

**The Monte Carlo Simulator:**

The simulator is the heart of the Monte Carlo valuation process.
This simulator performs `mcLoops`

Monte Carlo loops each with
`mcSteps`

Monte Carlo steps. In each loop the following steps
are done: first the innovation matrix is created from the specified
innovation generator (usually build from the normal pseudo random
number or low discrepancy generators), then anththetic innovations
are added if desired (by default `anththetic=TRUE`

), then the
innovations can be standardized within each loop (by default
`standardization=FALSE`

), and finally the average payoff of
all samples in the loop is computed. The simulation can be traced
loop by loop setting the argument `trace=TRUE`

.

*The user defined innovation generator*

returns a numeric matrix of (random) innovations to build the Monte
Carlo Paths.

*The user defined path generator*

returns a numeric matrix of the Monte Carlo paths for the calculation
of the option's payoffs.
To be more precise, as an example the function returns for a Wiener
process the matrix
`(b-sigma*sigma/2)*delta.t + sigma*sqrt(delta.t)*innovations`

,
where the first term corresponds to the drift and the second to the
volatility.

*The user defined payoff calculator*,

returns the vector of the option's payoffs calculated from the generated
paths. As an example this becomes for an arithmetic Asian call option
with a Wiener Monte Carlo path `payoff = exp(-r*Time)*max(SM-X, 0)`

where `SM = mean(S*exp(cumsum(path)))`

and `path`

denotes
the MC price paths.

**MonteCarloOption:**

returns a vector with the option prices for each Monte Carlo loop.

Diethelm Wuertz for the Rmetrics **R**-port.

Birge J.R. (1994);
*Quasi-Monte Carlo Approaches to Option Pricing*,
Department of Industrial and Operations Engineering,
Technical Report 94–19, University of Michigan.

Boyle P. (1977);
*Options: A Monte Carlo approach*,
Journal of Finance, 32, 323–338.

Glasserman P. (2004);
*Monte Carlo Methods in Financial Engineering*,
Springer-Verlag New York, Inc., 596 pp.

Jaeckel P. (2002);
*Monte Carlo Methods in Finance*,
John Wiley and Sons Ltd, 222 pp.

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 64 65 66 67 68 69 70 71 72 73 74 | ```
## How to perform a Monte Carlo Simulation?
## First Step:
# Write a function to generate the option's innovations.
# Use scrambled normal Sobol numbers:
sobolInnovations <- function(mcSteps, pathLength, init, ...) {
# Create and return Normal Sobol Innovations:
rnorm.sobol(mcSteps, pathLength, init, ...)
}
## Second Step:
# Write a function to generate the option's price paths.
# Use a Wiener path:
wienerPath <- function(eps) {
# Note, the option parameters must be globally defined!
# Generate and return the Paths:
(b-sigma*sigma/2)*delta.t + sigma*sqrt(delta.t)*eps
}
## Third Step:
# Write a function for the option's payoff
# Example 1: use the payoff for a plain Vanilla Call or Put:
plainVanillaPayoff <- function(path) {
# Note, the option parameters must be globally defined!
# Compute the Call/Put Payoff Value:
ST <- S*exp(sum(path))
if (TypeFlag == "c") payoff <- exp(-r*Time)*max(ST-X, 0)
if (TypeFlag == "p") payoff <- exp(-r*Time)*max(0, X-ST)
# Return Value:
payoff
}
# Example 2: use the payoff for an arithmetic Asian Call or Put:
arithmeticAsianPayoff <- function(path) {
# Note, the option parameters must be globally defined!
# Compute the Call/Put Payoff Value:
SM <- mean(S*exp(cumsum(path)))
if (TypeFlag == "c") payoff <- exp(-r*Time)*max(SM-X, 0)
if (TypeFlag == "p") payoff <- exp(-r*Time)*max(0, X-SM)
# Return Value:
payoff
}
## Final Step:
# Set Global Parameters for the plain Vanilla / arithmetic Asian Options:
TypeFlag <- "c"; S <- 100; X <- 100
Time <- 1/12; sigma <- 0.4; r <- 0.10; b <- 0.1
# Do the Asian Simulation with scrambled random numbers:
mc <- MonteCarloOption(delta.t = 1/360, pathLength = 30, mcSteps = 5000,
mcLoops = 50, init = TRUE, innovations.gen = sobolInnovations,
path.gen = wienerPath, payoff.calc = arithmeticAsianPayoff,
antithetic = TRUE, standardization = FALSE, trace = TRUE,
scrambling = 2, seed = 4711)
# Plot the MC Iteration Path:
par(mfrow = c(1, 1))
mcPrice <- cumsum(mc)/(1:length(mc))
plot(mcPrice, type = "l", main = "Arithmetic Asian Option",
xlab = "Monte Carlo Loops", ylab = "Option Price")
# Compare with Turnbull-Wakeman Approximation:
if(FALSE) { # ... requires(fExoticOptions)
TW <- TurnbullWakemanAsianApproxOption(
TypeFlag = "c", S = 100, SA = 100, X = 100,
Time = 1/12, time = 1/12, tau = 0 , r = 0.1,
b = 0.1, sigma = 0.4)$price
print(TW)
} else
TW <- 2.859122
abline(h = TW, col = 2)
``` |

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.