import numpy as np
import matplotlib.pyplot as plt
def explicit_fd(isCall, S0, K, r, T, sigma, Smax, M, N):
dt = T/N
ds = Smax/M
iValues = np.arange(M)
jValues = np.arange(N)
S = iValues*ds
t = jValues*dt
alpha = 0.5*sigma**2*dt/ds**2
beta = 0.5*r*dt/ds
gamma = r*dt
# Initialize the grid
V = np.zeros(shape=(M+1, N+1))
S = np.zeros(M+1)
# Terminal condition at time T
for i in range(0, M+1):
S[i] = i*ds
V[i,N] = max(S[i]-K, 0) if isCall else max(K-S[i], 0)
# Explicit finite difference method
for j in reversed(range(0, N)):
for i in range(1, M):
V[i,j] = alpha*V[i+1,j+1] + (1-2*alpha-beta+gamma)*V[i,j+1] + alpha*V[i-1,j+1] + beta*V[i+1,j+1]
# Apply boundary conditions
V[0,j] = 0
V[M,j] = Smax - K*np.exp(-r*(N-j)*dt) if isCall else 0
return np.interp(S0, S, V[:,0])
T = 1
S0 = 34.523
K = 32.9352
sigma = 0.32
r = 0.094
S_max = K*2
N = 2000
M = 2000
call_price = explicit_fd(True, S0, K, r, T, sigma, S_max, M, N)
print(f"European Call Option Price: {call_price}")
Im trying to price an European Call with the Explicit Finite Difference method but the price I get is very different to the one calculated with Black-Scholes.
Price with Black Scholes = 6.757338059973058, Precio Crank Nicolson = 6.691067076466618
When I calculate it with the code above it gives me a price of 1.7959190949954134. I dont know where the error is.