Implied volatility in R
As the name suggests, implied volatility is the volatility value that, when input into an option pricing model (like Black-Scholes-Merton), yields a theoretical option price equal to the current market price of that option. In other words, it is the market’s expectation of the future volatility of the underlying asset as implied by the option’s market price.
To obtain an implied volatility from an option price, we typically use numerical methods, iteratively since there is no closed-form solution for implied volatility.
There are different ways we can obtain an implied volatility from an option price 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.
European options
The main functions to use to estimate the implied volatility using the Black-Scholes-Merton model are: bscallimpvol and bsputimpvol. The bscallimpvol function is used to estimate the implied volatility for European call options, while the bsputimpvol function is used for European put options.
Example: Implied volatility from a European call option
If the current price of an European call option is 3.2, and we know 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)
- Dividend yield (d): 0%
We can use the bscallimpvol function to get the implied volatility from that option price:
The parameters are:
- s: Current stock price
- k: Strike price
- r: Risk-free interest rate
- tt: Time to expiration
- d: Dividend yield
The function returns the value of the implied volatility for the given option price and set of option parameters.
The function internally uses the unitroot base R function to perform the numerical estimation of the implied volatility which root finding method is based on the Brent’s minimization algorithm.
The bsputimpvol function works similarly for put options.
American options
For American options, the derivmkts package does not provide a direct function to calculate implied volatility. We must therefore build our own function using the binomopt pricing function and R’s built-in uniroot solver.
The process involves two steps: 1. Define a function that calculates the difference between the option’s market price and its theoretical price from the binomial model for a given volatility. 2. Use uniroot to find the volatility that makes this difference zero.
Let’s create a reusable function, american_implied_vol, to encapsulate this logic. This makes it easier to calculate implied volatility for different American options without rewriting the root-finding code.
This function takes all the necessary option parameters, including the market_price, and returns the implied volatility. We’ve set a search interval for volatility between 0.01% and 200% (lower_vol, upper_vol), which is a reasonably wide range for most assets. We also added basic error handling using try() to prevent the code from stopping if uniroot fails to find a solution.
Example: Implied volatility from an American put option
Now, let’s use our new function to find the implied volatility for an American put option with a market price of 3.03 and 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)
- Dividend yield (d): 0% - Number of steps (nstep): 1000
The uniroot function, wrapped inside our helper function, searches for a root of the objective_function within the specified interval. The result is the implied volatility for the American put option.