getImpliedVol: Return dataframe of options data with computed Implied...

Description Usage Arguments Author(s) References Examples

View source: R/b76.r

Description

Given a dataframe with the columns
1) strike # the option strike - in $
2) type # either c for call option or p for a put option
3) optionPrice # the option price - in $
4) futurePrice # the price of the underlying future - in $
5) time_to_expiry

getImpliedVol() computes the Implied Volatility across Call & Put options and option time to expiry. It then returns the input dataframe df with a new column implied_volatility.

Risk Free Rate r is taken from 3-Month US T-Bills of the specified date argument.

Usage

1
getImpliedVol(df, date="2019-09-18", mode="B")

Arguments

df

Data Frame with 5 columns:
1) strike ("numeric" or "double")
2) type ("string")
3) optionPrice ("numeric" or "double")
4) futurePrice ("numeric" or "double")
5) time_to_expiry ("numeric" or "double")

date

Date of option data ("character" in format "yyyy-mm-dd" including quotes)

mode

Specify results to be returned based on mode
1) "C" returns dataframe for Call options only
2) "P" returns dataframe for Put options only
3) default - "B" or "CP" returns dataframe for both Call and Put options

Author(s)

Jason Yip

References

https://www.glynholton.com/notes/black_1976/

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
df = data.frame(
      strike = c(50, 23, 48, 24, 52, 20,51,22,49),
      type = c("C","P","C","P","C","P","C","P","C"),
      optionPrice = c(1.62,0.01,1.62,0.01,1.62,0.01,1.5,0.02,1.7),
      futurePrice = c(48.03, 48.03,48.03, 48.03,48.03, 48.03, 48.03, 48.03, 48.03),
      time_to_expiry = c(0.1423, 0.1423,0.1323, 0.1323,0.1223, 0.1223, 0.12, 0.11, 0.15))

getImpliedVol(df, date="2018-09-18", mode="B")
getImpliedVol(df, date="2018-09-18", mode="C")
getImpliedVol(df, date="2018-09-18", mode="P")
getImpliedVol(df, date="2018-09-18", mode="CP")

jasonyip184/b76 documentation built on May 28, 2019, 7:35 a.m.