Binomial trees in R

There are different R packages that can be used to implement binomial trees. Here we use the derivmkts package by Robert McDonald, which provides a simple and intuitive interface for building and analyzing binomial trees for option pricing.

You can find more information about the package and its functions in this documentOption Pricing Functions to Accompany Derivatives Markets

You can install the package from CRAN using the following command:

#| edit: false
#| autorun: false
#| runbutton: false
install.packages("derivmkts")

Once you have installed the package,1 you can load it into your R session using the following command:

The main functions to use when valuing options using binomial trees are binomopt and binomplot. The binomopt function is used to price options using a binomial tree, while the binomplot function is used to visualize the binomial tree.

We will consider binomial trees with the Cox-Ross-Rubinstein (CRR) model.

Example: Pricing a European call option

Let’s consider a European call option with the following parameters:
- Current stock price (s): $40
- Strike price (k): $40
- Risk-free interest rate (r): 4% (0.04)
- Volatility (v): 30% (0.30)
- Time to expiration (tt): 0.5 years (six months)
- Dividend yield (d): 0%
- Number of steps in the binomial tree (nstep): 100

The binomopt function takes several arguments to specify the option parameters. Here is how you can use the function to price the European call option:

where putopt = FALSE indicates that we are pricing a call option (set to TRUE for put options), crr = TRUE specifies that we are using the Cox-Ross-Rubinstein model, and american = FALSE indicates that it is a European option. The other parameters correspond to the option’s characteristics:
- s: Current stock price
- k: Strike price
- r: Risk-free interest rate
- v: Volatility
- tt: Time to expiration
- d: Dividend yield
- nstep: Number of steps in the binomial tree

By default, the function will return the option price. Try changing the nstep parameter to see how the option price converges as the number of steps increases.

We can also ask the function to return the trees and the parameters used in the calculation by setting the returntrees argument to TRUE and returnparams to TRUE:

This will return a list containing the following trees: for the price of the underlying asset (stree), the option price (oppricetree), where the option is exercised (exertree), and the probability of being at each node; additionaly it returns the option price (price), the parameters used in the calculation (params). the greeks (greeks) and other list elements.

For more details on the output, you can refer to the documentation of the binomopt function by running ?binomopt:

press the Run button to see the documentation.

We can use the binomplot function to visualize the binomial tree for the option. Here is how you can use the function:

The plotvalues argument specifies whether to plot the option values at each node, and the returnprice argument indicates whether to return the option price along with the plot.

Example: Pricing an American put option

Let’s consider a put option with the same parameters as above but now with American exercise. We can price the American put option using the same parameters as before, but setting putopt = TRUE and american = TRUE:

You can also visualize the binomial tree for the American call option using the binomplot function:

This will generate a plot of the binomial tree for the American call option, showing the option values at each node and indicating where early exercise occurs.

Pricing options using different number of steps

You can experiment with different numbers of steps in the binomial tree to see how it affects the option price. For example, you can try pricing the European call option with 10, 50, and 100 steps:

This code will calculate the option prices for the specified number of steps and display them in a data frame. The sapply function is used to apply the binomopt function over the vector of steps. We are creating a data frame to neatly display the results.

Press the Run button to execute the code and see the option prices for different numbers of steps.

As you increase the number of steps, you should observe that the option price converges to its true value. But notice that the convergence is not necessarily monotonic; that is, the price may oscillate around the true value before settling down as the number of steps increases. Why do you think this happens?

You can create a plot showing the convergence of the option price as the number of steps increases:

Footnotes

  1. You only need to install the package once. After installation, you can load it in any R session.↩︎