# How to easily solve volatility for American options

# How to easily solve volatility for American options

Understanding implied volatility in American call options can be a real headache. Misjudging it can lead to overpaying for options or missing out on profitable trades. Many traders don’t realize you can’t use Black Scholes for American options (ouch!).

This is where binomial trees and Monte Carlo simulations come in.

These methods can accurately compute implied volatility, but they are complex and time-consuming. Back when I first started trading, I struggled despite my background in quant finance and professional trading.

QuantLib really helped.

By reading today’s newsletter, you’ll be able to use Python to compute implied volatility for American call options.

Let’s go!

## How to easily solve volatility for American options

Implied volatility (IV) is a key metric in options trading. It reflects the market expectations of a stock's future volatility. Unlike historical volatility, which looks at past price movements, IV is forward-looking. American options can be exercised any time. This makes it tricky to compute IV. We need advanced methods like binomial tree models, finite difference methods, and Monte Carlo simulations.

The binomial tree model divides the time to expiration into intervals simulating price movements. Finite difference methods solve partial differential equations governing option prices. Monte Carlo simulations model price paths through random sampling. Professionals use these methods to determine IV.

Good thing we have QuantLib to do the heavy lifting for us.

Accurate IV computation helps traders assess option pricing, manage risks, and develop strategies.

Let's see how it works with Python.

### Imports and set up

First, we import QuantLib which is all we need.

`1import QuantLib as ql`

QuantLib is a powerful library for quantitative finance. We begin by importing it to use its functionality. This will allow us to access various financial instruments and tools needed for our calculations.

### Define the option parameters and market data

Next, we define the parameters for our American call option and the market data, such as the spot price, strike price, volatility, and risk-free rate.

```
1spot_price = 188.64
2risk_free_rate = 0.0525
3dividend_yield = 0.0052
4volatility = 0.20
5days_to_maturity = 148
6strike_price = 190
7option_price = 11.05
```

We define the key parameters for the option, including the spot price of the underlying asset at $188.64, the risk-free interest rate at 5.25%, and the dividend yield at 0.52%. We set the option's volatility at 20%, the number of days to maturity at 148, the strike price at $190, and the market price of the option at $11.05.

Next we set up the environment for valuing the option.

```
1calendar = ql.NullCalendar()
2day_count = ql.Actual360()
3today = ql.Date().todaysDate()
4
5ql.Settings.instance().evaluationDate = today
6risk_free_ts = ql.YieldTermStructureHandle(
7 ql.FlatForward(today, risk_free_rate, day_count)
8)
9dividend_ts = ql.YieldTermStructureHandle(
10 ql.FlatForward(today, dividend_yield, day_count)
11)
12
13spot_handle = ql.QuoteHandle(ql.SimpleQuote(spot_price))
```

This code sets up the environment for option pricing by using QuantLib. It defines the calendar as NullCalendar and the day count convention as Actual360, with today's date as the evaluation date. It also creates yield term structures for the risk-free rate and dividend yield, and sets the spot price of the underlying asset using a QuoteHandle.

### Create the option and set the exercise type

Next, the option itself.

```
1expiration_date = today + ql.Period(days_to_maturity, ql.Days)
2payoff = ql.PlainVanillaPayoff(ql.Option.Call, strike_price)
3exercise = ql.AmericanExercise(today, expiration_date)
4american_option = ql.VanillaOption(payoff, exercise)
```

Next, calculate the expiration date by adding the number of days to maturity to today's date. We set the payoff type to a plain vanilla call option with a specific strike price and defines the exercise style as American (allowing the option to be exercised any time before or on the expiration date).

Finally, it creates the American option with the specified payoff and exercise details.

### Model the option value and compute implied volatility

Now that we have everything in place, we can set up the stochastic process, binomial pricing engine, and compute implied volatility.

```
1bsm_process = ql.BlackScholesMertonProcess(
2 spot_handle, dividend_ts, risk_free_ts, volatility_handle
3)
4
5engine = ql.BinomialVanillaEngine(bsm_process, "crr", 1000)
6american_option.setPricingEngine(engine)
7
8implied_volatility = american_option.impliedVolatility(
9 option_price, bsm_process, 1e-4, 1000, 1e-8, 4.0
10)
```

We set up the Black-Scholes-Merton process for modeling the underlying asset's price, including the spot price, dividend yield, risk-free rate, and volatility. We then uses a Binomial Vanilla Engine with the Cox-Ross-Rubinstein (CRR) method to price the American option. Finally, it calculates the implied volatility by adjusting the model to match the market price of the option.

### Your next steps

Try changing the spot price or strike price in the parameters and observe how the implied volatility changes. Experiment with different volatility values or risk-free rates to see their impact on the option price and implied volatility. This will help you understand the sensitivity of option pricing models to various inputs.