0
$\begingroup$

I am implementing the explicit finite difference method to solve Black Scholes PDE, but I have difficulty to find out why it is not working (my python code below)

Is it an issue of instability in my case? I am implementing it correctly? thank you

from __future__ import division
import numpy as np

T = 2.
N = 200
M = 200
L = 200.
dS = L / float(M)
dt = T / float(N)
r = 0.03
sig = 0.2
K = 90.

f = np.zeros((M,N))

for i in range(0, N):
    f[i][0]=0.
    f[i][M-1]=float(M-1)*dS

for j in range(0, M):
    f[N-1][j]= float(j)*dS-K  if float(j)*dS-K > 0. else 0.

for i in np.arange(N-1, 0, -1):
    for j in np.arange(M-2, 0, -1):
        j_ = float(j)
        i_ = float(i)
        a = 0.5*dt*(sig*sig*j_*j_-r*j_)
        b = 1.- dt*(sig*sig*j_*j_+r)
        c = 0.5*dt*(sig*sig*j_*j_+r*j_)
        f[i-1][j] = a*f[i][j-1]+b*f[i][j]+c*f[i][j+1]
        print (i-1, j, f[i-1][j] )
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.