Skip to content
All library documents

Explicit Finite Differences for Black-Scholes Option Pricing

Article Quant Q&A · Author: user1654183

Summary

The document presents a Python implementation of an explicit finite-difference scheme for the Black-Scholes equation, applied to a European call. It lays out a stock-price grid and a time grid, initializes terminal values with the call payoff, and steps backward through time using coefficients for the diffusion, drift, and interest-rate terms. The lower boundary is set to zero, while the upper boundary is extrapolated from neighboring grid values.

The author reports that some choices of time and asset increments produce stable but inaccurate values, while others cause divergence, and asks readers to identify implementation errors. The post itself supplies no diagnosis, numerical comparison, or convergence results, so it cannot establish whether the issue lies in coefficient formulas, boundary handling, grid resolution, or stability conditions. It is useful as an example of the setup and pitfalls of explicit option-pricing schemes, but the code alone is not a validated pricing method.

Key ideas

  • The example prices a European call by marching an explicit finite-difference grid backward from expiry.
  • The terminal grid values are initialized from the option payoff, and the interior update combines neighboring asset nodes.
  • Boundary values are specified separately, including a linear extrapolation at the upper asset limit.
  • The author observes both stable inaccurate outputs and divergent outputs as grid increments change.
  • The document asks for debugging help but does not provide a verified correction or convergence analysis.

Tags

Full text
# Black-Scholes explicit Euler implementation python


# Black-Scholes explicit Euler implementation python












I've written some code for the explicit finite difference method to solve the BS equation.

For certain sets of parameters (time-steps and asset-steps) I get a stable but wrong solution. For others, I get everything diverging to nonsense. I can't spot any errors in my implementation. Can you?

```
import numpy as np
import matplotlib.pyplot as plt

def A(vol, asset_step, risk_free_rate, dividend_rate, time_step):
    return 0.5*time_step*(vol**2*asset_step**2 - (risk_free_rate - dividend_rate)*asset_step)

def B(vol, asset_step, risk_free_rate, time_step):
    return 1 - time_step*(vol**2*asset_step**2 + risk_free_rate)

def C(vol, asset_step, risk_free_rate, dividend_rate, time_step):
    return 0.5*time_step*(vol**2*asset_step**2 + (risk_free_rate - dividend_rate)*asset_step)

def call_payoff(asset_price, strike_price):
    return max(asset_price - strike_price, 0)

S_max          = 140.
strike         = 100.
expiry         = 2.
asset_step     = 1
risk_free_rate = 0.05
dividend_rate  = 0.0
vol            = 0.2
t_step         = 0.001

no_asset_steps = int(S_max/asset_step)
print "Number of asset steps: ", no_asset_steps

no_time_steps = int(expiry/t_step)
print "Number of time steps: ", no_time_steps

S = np.zeros(no_asset_steps+1)
V = np.zeros((no_asset_steps+1, no_time_steps+1))

for i in xrange(no_asset_steps+1):
    S[i] = i*asset_step
    V[i,no_time_steps] = call_payoff(S[i], strike)

for k in range(no_time_steps, 0, -1):
    for i in xrange(1,no_asset_steps):
        A_co = A(vol, i, risk_free_rate, dividend_rate, t_step)
        B_co = B(vol, i, risk_free_rate, t_step)
        C_co = C(vol, i, risk_free_rate, dividend_rate, t_step)
        V[i, k-1] = A_co*V[i-1, k] + B_co*V[i,k] + C_co*V[i+1,k]

    V[0, k-1] = 0
    V[no_asset_steps, k-1] = 2*V[no_asset_steps-1, k-1] - V[no_asset_steps-2, k-1]
```

Shown in full with attribution under the source's licence. Licence: CC BY-SA 4.0 (Stack Exchange)

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.