black76ImVoDF: black76ImVoDF

Description Usage Arguments Value Examples

Description

black76ImVoDF applies black76ImVo on each row of a dataframe with option price, strike price, future price, option type, interest rate, and time to maturity as columns.

Usage

1
2
3
black76ImVoDF(df, Ftdf, Kdf, typedf, Timedf, rdf, optionPricedf,
  sigma_ini = NULL, tol = 1e-10, maxiter = 1000, output = c("dataframe",
  "IV"))

Arguments

df

A dataframe.

Ftdf

Name of a columns in the dataframe corresponding to future price.

Kdf

Name of a columns in the dataframe corresponding to strike price.

typedf

Name of a columns in the dataframe corresponding to option type.

Timedf

Name of a columns in the dataframe corresponding to time to maturity.

rdf

Name of a columns in the dataframe corresponding to interest rate.

optionPricedf

Name of a columns in the dataframe corresponding to option price.

sigma_ini

Initial value for iteration in the Newton-Raphson method. Numeric object or NULL (default). If no value is provided, the sigma which maximizes Vega is choosen.

tol

Error tolerance of the interation step.

maxiter

Maximum number of iteration

output

Argument specifying whether the output is the implied volatility calculated only or implied volatility as a column in the dataframe (default).

Value

Implied volatility calculated in a vector or as a column in the dataframe (default).

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
Ft <- 50
Kvec <- 20:80
Kvec <- 20:80 + floor(runif(n = 61, min = 0, max = 5))
Timevec <- c(c(3, 6, 9)/12, 1:5)
df0 <- data.frame(expand.grid(Kvec, Timevec))

names(df0) <- c('Strike', 'Time')

r <- (log(df0$Time) + 2) / 100
Vol <- (abs(df0$Strike - 50) ^ (1.3) + 50 + 3/df0$Strike) / 200
type <- sample(x = c("C", "P"), size = 488, replace = TRUE, prob = c(0.5, 0.5))
df <- data.frame(df0, Ft, r, Vol, type)
df2 <- black76DF(df = df, Ftdf = 'Ft', sigmadf = 'Vol', Kdf = 'Strike',
                 typedf = 'type', rdf = 'r', Timedf = 'Time')
head(df2)
df3 <- black76ImVoDF(df = df2, Ftdf = 'Ft', Kdf = 'Strike', typedf = 'type',
                     Timedf = 'Time', rdf = 'r', optionPricedf = 'optionPrice',
                     tol = 1e-10, maxiter = 2000)
summary(abs(df3$Vol - df3$IV))
plot(density(df3$Vol - df3$IV))
df3[which.max(abs(df3$Vol - df3$IV)),]
df3[is.na(df3$IV),]
all(abs(df3$Vol - df3$IV) < 1e-10)

OUKUN0705/black76IV documentation built on May 7, 2019, 8:55 p.m.