EuropeanOptionArrays: European Option evaluation using Closed-Form solution

Description Usage Arguments Details Value Note Author(s) References See Also Examples

View source: R/arrays.R

Description

The EuropeanOptionArrays function allows any two of the numerical input parameters to be a vector, and a list of matrices is returned for the option value as well as each of the 'greeks'. For each of the returned matrices, each element corresponds to an evaluation under the given set of parameters.

Usage

1
2
3
4
5
EuropeanOptionArrays(type, underlying, strike, dividendYield,
                     riskFreeRate, maturity, volatility)
oldEuropeanOptionArrays(type, underlying, strike, dividendYield,
                        riskFreeRate, maturity, volatility)
plotOptionSurface(EOres, ylabel="", xlabel="", zlabel="", fov=60) 

Arguments

type

A string with one of the values call or put

underlying

(Scalar or list) current price(s) of the underlying stock

strike

(Scalar or list) strike price(s) of the option

dividendYield

(Scalar or list) continuous dividend yield(s) (as a fraction) of the stock

riskFreeRate

(Scalar or list) risk-free rate(s)

maturity

(Scalar or list) time(s) to maturity (in fractional years)

volatility

(Scalar or list) volatilit(y|ies) of the underlying stock

EOres

result matrix produced by EuropeanOptionArrays

ylabel

label for y-axsis

xlabel

label for x-axsis

zlabel

label for z-axsis

fov

viewpoint for 3d rendering

Details

The well-known closed-form solution derived by Black, Scholes and Merton is used for valuation.

Please see any decent Finance textbook for background reading, and the QuantLib documentation for details on the QuantLib implementation.

Value

The EuropeanOptionArrays function allows any two of the numerical input parameters to be a vector or sequence. A list of two-dimensional matrices is returned. Each cell corresponds to an evaluation under the given set of parameters.

For these functions, the following components are returned:

value

(matrix) value of option

delta

(matrix) change in value for a change in the underlying

gamma

(matrix) change in value for a change in delta

vega

(matrix) change in value for a change in the underlying's volatility

theta

(matrix) change in value for a change in delta

rho

(matrix) change in value for a change in time to maturity

dividendRho

(matrix) change in value for a change in delta

parameters

List with parameters with which object was created

The oldEuropeanOptionArrays function is an older implementation which vectorises this at the R level instead but allows more general multidimensional arrays.

Note

The interface might change in future release as QuantLib stabilises its own API.

Author(s)

Dirk Eddelbuettel edd@debian.org for the R interface; the QuantLib Group for QuantLib

References

http://quantlib.org for details on QuantLib.

See Also

AmericanOption,BinaryOption

Examples

 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
# define two vectos for the underlying and the volatility
und.seq <- seq(10,180,by=2)
vol.seq <- seq(0.1,0.9,by=0.1)
# evaluate them along with three scalar parameters
EOarr <- EuropeanOptionArrays("call", underlying=und.seq,
                              strike=100, dividendYield=0.01,
                              riskFreeRate=0.03,
                              maturity=1, volatility=vol.seq)
# and look at four of the result arrays: value, delta, gamma, vega
old.par <- par(no.readonly = TRUE)
par(mfrow=c(2,2),oma=c(5,0,0,0),mar=c(2,2,2,1))
plot(EOarr$parameters.underlying, EOarr$value[,1], type='n',
     main="option value", xlab="", ylab="") 
topocol <- topo.colors(length(vol.seq))
for (i in 1:length(vol.seq))
  lines(EOarr$parameters.underlying, EOarr$value[,i], col=topocol[i])
plot(EOarr$parameters.underlying, EOarr$delta[,1],type='n',
     main="option delta", xlab="", ylab="")
for (i in 1:length(vol.seq))
  lines(EOarr$parameters.underlying, EOarr$delta[,i], col=topocol[i])
plot(EOarr$parameters.underlying, EOarr$gamma[,1],type='n',
     main="option gamma", xlab="", ylab="")
for (i in 1:length(vol.seq))
  lines(EOarr$parameters.underlying, EOarr$gamma[,i], col=topocol[i])
plot(EOarr$parameters.underlying, EOarr$vega[,1],type='n',
     main="option vega", xlab="", ylab="")
for (i in 1:length(vol.seq))
  lines(EOarr$parameters.underlying, EOarr$vega[,i], col=topocol[i])
mtext(text=paste("Strike is 100, maturity 1 year, riskless rate 0.03",
        "\nUnderlying price from", und.seq[1],"to", und.seq[length(und.seq)],
        "\nVolatility  from",vol.seq[1], "to",vol.seq[length(vol.seq)]),
      side=1,font=1,outer=TRUE,line=3)
par(old.par)

Example output

sh: 1: cannot create /dev/null: Permission denied

RQuantLib documentation built on May 2, 2019, 4:48 p.m.