Below is some Python code to perform Monte Carlo simulation to price a European call option. In this example, I’ll use the Black-Scholes model for stock price dynamics.
Assumptions for the Black-Scholes model are:
1. The stock price follows a Geometric Brownian Motion (GBM).
2. The risk-free rate is constant.
3. The stock’s volatility (sigma) is constant.
The equation for the stock price at time ‘t‘ following GBM is:
$$S_t = S_0 e^{(r - \frac{1}{2} \sigma^2) t + \sigma \sqrt{t} Z}$$
Where:
- St = stock price at time ‘t‘
- S0 = initial stock price
- r = risk-free interest rate
- σ = stock’s volatility
- t = time period
- Z = standard Normal random variable
Now, let’s simulate to get the call option price. The call option payoff is:
Call Payoff = max(St − K, 0)
Where:
- K = strike price of the option
We will then calculate the expected payoff and discount it back to the present value, as the option price:
European Call Option Price = e − rT * E[Call Payoff]
Here’s the Python code:
import numpy as np
import math
# Parameters
S0 = 100 # initial stock price
K = 110 # strike price
T = 1 # time to maturity (1 year)
r = 0.05 # risk-free interest rate
sigma = 0.20 # stock's volatility
num_simulations = 1000000 # number of Monte Carlo simulations
# Set a random seed for reproducibility
np.random.seed(1234)
# Generate stock prices at time T using GBM model
Z = np.random.normal(0, 1, num_simulations)
St = S0 * np.exp((r - 0.5 * sigma**2) * T + sigma * math.sqrt(T) * Z)
# Calculate the call option's payoff at time T
call_payoff = np.maximum(St - K, 0)
# Discount the expected payoff to obtain the option price
call_price = np.average(call_payoff) * np.exp(-r * T)
print("European Call Option Price:", call_price)
This code prices a European call option using Monte Carlo simulation based on the given parameters. You can change these parameters to get the option price under different conditions.