Hi,
I am trying to make again my scholar projet.
One of them was to solve the Black and Scholes PDE with finite different methods.
I tried some codes but didnt get a right result.
See below my last try :
import numpy as np
_vol = 0.40
_r = 0.10
_K = 50
T = 0.5
m = 100 # time
n = 200 # space
dt = T / m # time step
dx = 2 * _K / (n+1) # space step
print("dt = ", dt)
print("dx = ", dx)
l = np.zeros((m, n))
def payoff(S):
# Call Euro
# strike = 100
return max(S - _K, 0)
# Maturity condition :
for j in range(n):
l[0][j] = payoff(j * dx)
for i in range(m-1):
for j in range(n):
if (j == 0) :
l[i+1][j] = 0
elif (j == n-1):
l[i+1][j] = j * dx - _K * np.exp(-_r * (T - i * dt))
else:
# explicit method :
l[i+1][j] = (1/2 * (_vol * j)**2 * dt - 1/2 * _r * j * dt) * l[i][j-1] + (1 - (_vol * j)**2 * dt - _r * dt) * l[i][j] + (1/2 * (_vol * j)**2 * dt + 1/2 * _r * j * dt) * l[i][j+1]
You can see this link : http://planetmath.org/solvingtheblackscholespdebyfinitedifferences
I tried the explicit & implicit and never get the correct result..
For example, the price of a call, t=0, K=50, S=50 gives a, explosive negative result : -5.9.e+117 --"
I waited a price close to zero..
Please someone has already get it with a easy to reade code ?
Do not hesitate if you find a mistake in this code.
Thanks & regards,