knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
The optionstrat
package provides full functionality for analyzing option greeks and option strategies.
All option analytics are calculated using the Black-Scholes-Merton option pricing model.
The following functions may be used to calculate all of the option greeks as well as the option premium and provide the information in a data.frame
format:
opteval(s, x, sigma, t, r, d = 0)
calleval(s, x, sigma, t, r, d = 0)
puteval(s, x, sigma, t, r, d = 0)
Alternatively, these functions will return a specific option greek:
calldelta(s, x, sigma, t, r, d = 0)
putdelta(s, x, sigma, t, r, d = 0)
callgamma(s, x, sigma, t, r, d = 0)
putgamma(s, x, sigma, t, r, d = 0)
calltheta(s, x, sigma, t, r, d = 0)
puttheta(s, x, sigma, t, r, d = 0)
callrho(s, x, sigma, t, r, d = 0)
putrho(s, x, sigma, t, r, d = 0)
optiongamma(s, x, sigma, t, r, d = 0)
optionrho(s, x, sigma, t, r, d = 0)
lambda(type = "call", s, x, sigma, t, r, d = 0)
Arguments:
s
Spot price of the underlying assetx
Strike price of the optionsigma
Annualized standard deviation of the underlying asset returnst
Time to expiration in years, use tdiff(date1, date2, "years")
r
Continuously compounded risk-free rate, use r.cont(r, n)
d
Continuously compounded dividend yield, use r.cont(r, n)
Additionally:
callgreek(greek = c("delta", "gamma", "theta", "vega", "rho", "premium"), s, x, sigma, t, r, d = 0))
putgreek(greek = c("delta", "gamma", "theta", "vega", "rho", "premium"), s, x, sigma, t, r, d = 0))
Arguments:
greek
Character string. Specific option greek to be calculateds
Spot price of the underlying assetx
Strike price of the optionsigma
Annualized standard deviation of the underlying asset returnst
Time to expiration in years, use tdiff(date1, date2, "years")
r
Continuously compounded risk-free rate, use r.cont(r, n)
d
Continuously compounded dividend yield, use r.cont(r, n)
The following functions may be used to plot specific option strategies:
plotbullcall(s, x1, x2, t, r, sigma, sigma2 = sigma, d = 0, ll = 0.75, ul=1.25, xlab = "spot", ylab = "profit/loss", main = "Bull Call Spread")
plotbearcall(s, x1, x2, t, r, sigma, sigma2 = sigma, d = 0, ll = 0.75, ul=1.25, xlab = "spot", ylab = "profit/loss", main = "Bear Call Spread")
plotbullput(s, x1, x2, t, r, sigma, sigma2 = sigma, d = 0, ll = 0.75, ul=1.25, xlab = "spot", ylab = "profit/loss", main = "Bull Put Spread")
plotbearput(s, x1, x2, t, r, sigma, sigma2 = sigma, d = 0, ll = 0.75, ul=1.25, xlab = "spot", ylab = "profit/loss", main = "Bear Put Spread")
Arguments:
s
Spot price of the underlying assetx1
Lower option strike pricex2
Higher option strike pricet
Years until expirationr
Annual continuously compounded risk-free ratesigma
Implied volatility of the lower optionsigma2
Implied volatility of the higher optiond
Annual continuously compounded dividend yieldll
lower limit of the plot, set in terms of percent of the spot (price/spot)ul
upper limit 0f the plot, set in terms of percent of the spot (price/spot)Additional plotting function:
plotvertical(options = c("call", "put"), s, x1, x2, t, r, sigma, sigma2 = sigma, d = 0, ll = 0.75, ul = 1.25, xlab = "spot", ylab = "profit/loss", main = "Vertical Spread")
Arguments:
options
Character string. Designate the type of both optionss
Spot price of the underlying assetx1
Strike price of the short option in the vertical spreadx2
Strike price of the long option in the vertical spreadt
Years until expirationr
Annual continuously compounded risk-free ratesigma
Implied volatility of the short optionsigma2
Implied volatility of the long optiond
Annual continuously compounded dividend yieldll
lower limit of the plot, set in terms of percent of the spot (price/spot)ul
upper limit 0f the plot, set in terms of percent of the spot (price/spot)Additional plotting function:
plotdv(s, x1, x2, x3, x4, t, r, sigma, sigma2 = sigma, sigma3 = sigma, sigma4 =sigma, d = 0, ll = 0.75, ul = 1.25, xlab = "spot", ylab = "Profit/Loss", main = "Double Vertical Spread")
Arguments:
s
Spot price of the underlying assetx1
Strike price of the lower strike (long) put optionx2
Strike price of the higher strike (short) put optionx3
Strike price of the lower strike (short) call optionx4
Strike price of the higher strike (long) call option t
Years until expirationr
Annual continuously compounded risk-free ratesigma
Implied volatility of the lower strike (long) put option (annualized)sigma2
Implied volatility of the higher strike (short) put option (annualized)sigma3
Implied volatility of the lower strike (short) call option (annualized)sigma4
Implied volatility of the higher strike (long) call option (annualized)d
Annual continuously compounded dividend yieldll
lower limit of the plot, set in terms of percent of the spot (price/spot)ul
upper limit 0f the plot, set in terms of percent of the spot (price/spot)Vertical Spread Analytics
This function calculates the key analytics of a vertical spread and returns the ouput as a data.frame:
vertical(options = c("call", "put"), s, x1, x2, t, r, sigma, sigma2 = sigma, vol = sigma, d = 0)
Arguments:
options
Character string, specify whether the spread is a call spread or put spreads
Spot price of the underlying assetx1
Strike price of the short optionx2
Strike price of the long optiont
Time to expiration in yearsr
Annual continuously compounded risk-free ratesigma
Implied volatility of the short optionsigma2
Implied volatility of the long option, default = sigmavol
Input for the volatility of the underlying asset, default = sigmad
Annual continuously compounded dividend yieldDetails:
options
= "call" , (x1 < x2)
: Bear Call Credit Spreadoptions
= "call" , (x1 > x2)
: Bull Call Debit Spreadoptions
= "put" , (x1 < x2)
: Bear Put Debit Spreadoptions
= "put" , (x1 > x2)
: Bull Put Credit SpreadDouble Vertical Credit Spread Analytics
This function calculates the key analytics of a double vertical credit spread and returns the output as a data.frame:
dv(s, x1, x2, x3, x4, t, r, sigma, sigma2 = sigma, sigma3 = sigma, sigma4 = sigma, vol = sigma, d = 0)
Arguments:
s
Spot price of the underlying assetx1
Strike price of the lower strike (long) put optionx2
Strike price of the higher strike (short) put optionx3
Strike price of the lower strike (short) call optionx4
Strike price of the higher strike (long) call option t
Years until expirationr
Annual continuously compounded risk-free ratesigma
Implied volatility of the lower strike (long) put option (annualized)sigma2
Implied volatility of the higher strike (short) put option (annualized)sigma3
Implied volatility of the lower strike (short) call option (annualized)sigma4
Implied volatility of the higher strike (long) call option (annualized)vol
Input for the volatility of the underlying asset, default = sigmad
Annual continuously compounded dividend yieldThe "Probability Below" function has two separate possible operations:
Calculates the price the asset will remain below, given the designated probability
prob.below(spot, upper, mean = 0, asd = 0, dsd = 0, dte = 0, p, quantile = FALSE)
Arguments:
spot
Current price of the underlying assetlower
Lower price of the price rangemean
The average daily price movement, default = 0asd
Annualized standard deviationdsd
Daily standard deviation of the underlying returns (Annual vol/sqrt(256)), used in conjunction with the dte
parameter as an alternative to the asd
parameterdte
Days until expiration, designated time framep
Designated probabilityquantile
Logical. If True, calculates the price the asset will remain below, given the designated probabilityThe "Probability Above" function has two separate possible operations:
Calculates the price the asset will remain above, given the designated probability
prob.above(spot, lower, mean = 0, asd = 0 ,dsd = 0, dte = 0, p, quantile = FALSE)
Arguments:
spot
Current price of the underlying assetlower
Lower price of the rangemean
The average daily price movement, default = 0asd
Annualized standard deviationdsd
Daily standard deviation of the underlying returns (Annual vol/sqrt(256)), used in conjunction with the dte
parameter as an alternative to the asd
parameterdte
Days until expiration, designated time framep
Designated probabilityquantile
Logical. If True, calculates the price the asset will remain above, given the designated probabilityThe "Probability Between"
This function has two separate possible operations:
Calculates the probable price range, given a set probability
prob.btwn(spot, lower, upper, mean = 0, asd = 0, dsd = 0, dte = 0, p, quantile = FALSE)
Arguments:
spot
Current price of the underlying assetlower
Lower price of the price rangeupper
Upper price of the price rangemean
The average daily price movement, default = 0asd
Annualized standard deviationdsd
Daily standard deviation of the underlying returns (Annual vol/sqrt(256)), used in conjunction with the dte
parameter as an alternative to the asd
parameterdte
Days until expiration, designated time framep
Designated probabilityquantile
Logical. If True, calculates the price the asset will remain above, given the designated probabilityThe optionstrat package provides additional functions for calculating the implied volatility of either a call or put option, numerical time differences, and converting a nominal rate into a continuously compounded rate.
Implied Volatility:
iv.calc(type, price, s, x, t, r, d=0)
When applying this function over the rows of a dataframe, run it iteratively:
for(i in 1:nrow(dataframe)){
dataframe$iv[i] <- iv.calc(type = "put", price = dataframe$putprice[i],
s = atm, x = dataframe$strike[i], t = ttm, r = rate)
}
Arguments:
type
The type of option, either "call" or "put"price
The option premiums
The spot price of the underlying assetx
The strike price of the optiont
Time to expiration (in years)r
The continuously-compounded risk-free rate d
The dividend yield of the underlying assetNumerical Time Difference:
tdiff(date1, date2, period = c("days", "years"))
Continuously Compounded Rate Conversion:
r.cont(r, n)
Arguments:
r
The nominal rate of interestn
The number of compounding periods in a yearThe optionstrat
package is provided free of charge to the general public.
The indicators, strategies, calculations, functions and all other features are for educational purposes only and should not be construed as investment advice.
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.