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)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 optiont 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 optiont 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:
prob.below(spot, upper, mean = 0, dsd, dte, p, quantile = FALSE)Arguments:
spot Current price of the underlying assetlower Lower price of the price rangemean The average daily price movement, default = 0dsd Daily standard deviation of the underlying returns (Annual vol/sqrt(256))dte 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:
prob.above(spot, lower, mean = 0, dsd, dte, p, quantile = FALSE)Arguments:
spot Current price of the underlying assetlower Lower price of the rangemean The average daily price movement, default = 0dsd Daily standard deviation of the underlying returns (Annual vol/sqrt(256))dte 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:
prob.btwn(spot, lower, upper, mean = 0, dsd, dte, 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 = 0dsd Daily standard deviation of the underlying returns (Annual vol/sqrt(256))dte 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 implied volatility estimations, numerical time differences, and converting a nominal rate into a continuously compounded rate.
Implied Volatility (estimation):
iv.est(C, S, t)
Arguments:
C The price of a call optionS The spot price of the underlying assett Time to expiration (in years)Numerical 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.