Solution (source code)

= Solution

Write $h=\Delta x$, $k=\Delta t$ and march backward from the terminal payoff. At the interior grid point $(x_i,t_j)$ use
$$
D_xu_i^j=\frac{u_{i+1}^j-u_{i-1}^j}{2h},\qquad
D_{xx}u_i^j=\frac{u_{i+1}^j-2u_i^j+u_{i-1}^j}{h^2}.
$$
The <central finite difference> spatial approximation and backward-in-calendar-time <explicit Euler method> give
$$
\boxed{u_i^{j-1}=u_i^j+k\left[a_i^j\frac{u_{i+1}^j-2u_i^j+u_{i-1}^j}{h^2}
+b_i^j\frac{u_{i+1}^j-u_{i-1}^j}{2h}\right].}
$$
Here $a_i^j=\sigma(e^{x_i},t_j)^2/2$, $b_i^j=r-a_i^j$, and $u_i^m=(e^{x_i}-K)^+$. At a far-left boundary use $u\simeq0$; at a far-right boundary the call asymptotics are $u\simeq e^{r(T-t)}e^x-K$. These boundary values are inserted into the adjacent interior updates. Smooth-solution Taylor expansion gives consistency order $O(k+h^2)$ in the evolution equation.