# options: Pricing Plain-Vanilla Options (European and American) In enricoschumann/NMOF: Numerical Methods and Optimization in Finance

## Description

Functions to calculate the theoretical prices and (some) Greeks for plain vanilla options.

## Usage

 ``` 1 2 3 4 5 6 7 8 9 10``` ```vanillaOptionEuropean(S, X, tau, r, q, v, tauD = 0, D = 0, type = "call", greeks = TRUE, model = NULL, ...) vanillaOptionAmerican(S, X, tau, r, q, v, tauD = 0, D = 0, type = "call", greeks = TRUE, M = 101) vanillaOptionImpliedVol(exercise = "european", price, S, X, tau, r, q = 0, tauD = 0, D = 0, type = "call", M = 101, uniroot.control = list(), uniroot.info = FALSE) ```

## Arguments

 `S` spot `X` strike `tau` time-to-maturity in years `r` risk-free rate `q` continuous dividend yield, see Details. `v` variance (volatility squared) `tauD` vector of times-to-dividends in years. Only dividends with `tauD` greater than zero and not greater than `tau` are kept. `D` vector of dividends (in currency units); default is no dividends. `type` call or put; default is call. `greeks` compute Greeks? Defaults to `TRUE`. But see Details for American options. `model` what model to use to value the option. Default is `NULL` which is equivalent to `bsm`. `...` parameters passed to pricing model `M` number of time steps in the tree `exercise` `european` (default) or `american` `price` numeric; the observed price to be recovered through choice of volatility. `uniroot.control` A list. If there are elements named `interval`, `tol` or `maxiter`, these are passed to `uniroot`. Any other elements of the list are ignored. `uniroot.info` logical; default is `FALSE`. If `TRUE`, the function will return the information returned by `uniroot`. See paragraph Value below.

## Details

For European options the formula of Messrs Black, Scholes and Merton is used. It can be used for equities (set `q` equal to the dividend yield), futures (Black, 1976; set `q` equal to `r`), currencies (Garman and Kohlhagen, 1983; set `q` equal to the foreign risk-free rate). For future-style options (e.g. options on the German Bund future), set `q` and `r` equal to zero.

The Greeks are provided in their raw (‘textbook’) form with only one exception: Theta is made negative. For practical use, the other Greeks are also typically adjusted: Theta is often divided by 365 (or some other yearly day count); Vega and Rho are divided by 100 to give the sensitivity for one percentage-point move in volatility/the interest rate. Raw Gamma is not much use if not adjusted for the actual move in the underlier.

For European options the Greeks are computed through the respective analytic expressions. For American options only Delta, Gamma and Theta are computed because they can be directly obtained from the binomial tree; other Greeks need to be computed through a finite difference (see Examples).

For the European-type options, the function understands vectors of inputs, except for dividends. American options are priced via a Cox-Ross-Rubinstein tree; no vectorisation is implemented here.

The implied volatility is computed with `uniroot` from the stats package (the default search interval is ```c(0.00001, 2)```; it can be changed through `uniroot.control`).

Dividends (`D`) are modelled via the escrowed-dividend model.

## Value

Returns the price (a numeric vector of length one) if `greeks` is `FALSE`, else returns a list.

## Note

If `greeks` is `TRUE`, the function will return a list with named elements (`value`, `delta` and so on). Prior to version 0.26-3, the first element of this list was named `price`.

Enrico Schumann

## References

Gilli, M., Maringer, D. and Schumann, E. (2011) Numerical Methods and Optimization in Finance. Elsevier. http://www.elsevierdirect.com/product.jsp?isbn=9780123756626

Schumann, E. (2016) Financial Optimisation with R (NMOF Manual). http://enricoschumann.net/NMOF.htm#NMOFmanual

`EuropeanCall`, `callCF`
 ``` 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 75 76 77 78 79 80 81``` ```S <- 100; X <- 100; tau <- 1; r <- 0.02; q <- 0.06; vol <- 0.3 unlist(vanillaOptionEuropean(S, X, tau, r, q, vol^2, type = "put")) S <- 100; X <- 110; tau <- 1; r <- 0.1; q <- 0.06; vol <- 0.3; type <- "put" unlist(vanillaOptionAmerican(S, X, tau, r, q, vol^2, type = type, greeks = TRUE)) ## compute rho for 1% move h <- 0.01 (vanillaOptionAmerican(S, X, tau, r + h, q, vol^2, type = type, greeks = FALSE) - vanillaOptionAmerican(S, X, tau, r, q, vol^2, type = type, greeks = FALSE)) / (h*100) ## compute vega for 1% move h <- 0.01 (vanillaOptionAmerican(S, X, tau, r, q,(vol + h)^2, type = type, greeks = FALSE) - vanillaOptionAmerican(S, X, tau, r, q, vol^2, type = type, greeks = FALSE)) / (h*100) S <- 100; X <- 100 tau <- 1; r <- 0.05; q <- 0.00 D <- c(1,2); tauD <- c(0.3,.6) type <- "put" v <- 0.245^2 ## variance, not volatility p <- vanillaOptionEuropean(S = S, X = X, tau, r, q, v = v, tauD = tauD, D = D, type = type, greeks = FALSE) vanillaOptionImpliedVol(exercise = "european", price = p, S = S, X = X, tau = tau, r = r, q = q, tauD = tauD, D = D, type = type) p <- vanillaOptionAmerican(S = S, X = X, tau, r, q, v = v, tauD = tauD, D = D, type = type, greeks = FALSE) vanillaOptionImpliedVol(exercise = "american", price = p, S = S, X = X, tau = tau, r = r, q = q, tauD = tauD, D = D, type = type, uniroot.control = list(interval = c(0.01, 0.5))) ## compute implied q S <- 100; X <- 100 tau <- 1; r <- 0.05; q <- 0.072 v <- 0.22^2 ## variance, not volatility call <- vanillaOptionEuropean(S=S, X = X, tau=tau, r=r, q=q, v=v, type = "call", greeks = FALSE) put <- vanillaOptionEuropean(S=S, X = X, tau=tau, r=r, q=q, v=v, type = "put", greeks = FALSE) # ... the simple way -(log(call + X * exp(-tau*r) - put) - log(S)) / tau # ... the complicated way :-) volDiffCreate <- function(exercise, call, put, S, X, tau, r) { f <- function(q) { cc <- vanillaOptionImpliedVol(exercise = exercise, price = call, S = S, X = X, tau = tau, r = r, q = q, type = "call") pp <- vanillaOptionImpliedVol(exercise = exercise, price = put, S = S, X = X, tau = tau, r = r, q = q, type = "put") abs(cc - pp) } f } f <- volDiffCreate(exercise = "european", call = call, put = put, S = S, X = X, tau = tau, r) optimise(f,interval = c(0, 0.2))\$minimum ## S <- 100; X <- 100 tau <- 1; r <- 0.05; q <- 0.072 v <- 0.22^2 ## variance, not volatility vol <- 0.22 vanillaOptionEuropean(S=S, X = X, tau=tau, r=r, q=q, v=v, ## with variance type = "call", greeks = FALSE) vanillaOptionEuropean(S=S, X = X, tau=tau, r=r, q=q, vol=vol, ## with vol type = "call", greeks = FALSE) vanillaOptionEuropean(S=S, X = X, tau=tau, r=r, q=q, vol=vol, ## with vol type = "call", greeks = FALSE, v = 0.2^2) ```