Execute the following steps to price American options using the Least Squares Monte Carlo method.
- Import the libraries:
import numpy as np
from chapter_6_utils import (simulate_gbm,
black_scholes_analytical,
lsmc_american_option)
- Define the parameters:
S_0 = 36
K = 40
r = 0.06
sigma = 0.2
T = 1 # 1 year
N = 50
dt = T / N
N_SIMS = 10 ** 5
discount_factor = np.exp(-r * dt)
OPTION_TYPE = 'put'
POLY_DEGREE = 5
- Simulate the stock prices using GBM:
gbm_sims = simulate_gbm(s_0=S_0, mu=r, sigma=sigma, n_sims=N_SIMS,
T=T, N=N)
- Calculate the payoff matrix:
payoff_matrix = np.maximum(K - gbm_sims, np.zeros_like(gbm_sims))
- Define the value matrix and fill in the last column (time T):
value_matrix = np.zeros_like(payoff_matrix)
value_matrix[:, -1] = payoff_matrix[:, -1]
- Iteratively calculate the continuation value and the value vector in the given time:
for t in range(N - 1, 0 , -1):
regression = np.polyfit(gbm_sims[:, t],
value_matrix[:, t + 1] *
discount_factor,
POLY_DEGREE)
continuation_value = np.polyval(regression, gbm_sims[:, t])
value_matrix[:, t] = np.where(
payoff_matrix[:, t] > continuation_value,
payoff_matrix[:, t],
value_matrix[:, t + 1] * discount_factor
)
- Calculate the option premium:
option_premium = np.mean(value_matrix[:, 1] * discount_factor)
The premium on the specified American put option is 4.465.
- Calculate the premium of a European put with the same parameters:
black_scholes_analytical(S_0=S_0, K=K, T=T, r=r, sigma=sigma,
type='put')
The price of the European put option with the same parameters is 3.84.
- As an extra check, calculate the prices of the American and European call options:
european_call_price = black_scholes_analytical(S_0=S_0, K=K, T=T,
r=r, sigma=sigma)
american_call_price = lsmc_american_option(S_0=S_0, K=K, T=T, r=r,
sigma=sigma,
n_sims=N_SIMS,
option_type='call',
poly_degree=POLY_DEGREE)
The price of the European call is 2.17, while the American call's price (using 100,000 simulations) is 2.10.