The Greeks in R
There are different ways we can obtain the greeks from an option in R. We are going to use derivmkts package by Robert McDonald, as we did in binomial trees in R.
Let’s start by loading the package in the R session:
If you don’t have the package installed, read the instructions in binomial trees in R on how to install it.
Greeks for vanilla options can be computed using the greeks function, which is a wrapper for any pricing function that returns the option price and which uses the default naming of inputs. The greeks function calculates these sensitivities numerically (by perturbing the inputs slightly) rather than using analytical formulas. So we can use it to obtain the greeks for European options priced with the Black-Scholes-Merton model, or for American options priced with the binomial model.
Consider the following parameters:
- Current stock price (s): $40
- Strike price (k): $40
- Risk-free interest rate (r): 4% (0.04)
- Time to expiration (tt): 0.5 years (six months)
- Volatility (v): 20% (0.2) - Dividend yield (d): 0%
We can use the greeks function to get the greeks for a European call option:
The parameters are:
- s: Current stock price
- k: Strike price
- r: Risk-free interest rate
- tt: Time to expiration - d: Dividend yield
- v: Volatility
The function returns the option value along the greeks. Note that the value of Theta (\(\theta\)) is returned on a per-day basis (assuming 365 days per annum). Vega (\(\nu\)) is returned per 1% change in volatility, and Rho (\(\rho\)) is returned per 1% change in the interest rate. Compare this output with the one obtained in The Greeks chapter using the formulas.
We can also use the greeks function to get the greeks for an American call option, using the binomial tree model (with CRR parameters) with 20 steps:
Try changing the parameters and see how the greeks change! Also try using a put option by setting the putopt parameter to TRUE.