LessonThis is a lesson restated in new words. Any figure in it is an example from the source, not this desk's record.

Finite differences approximate a derivative by a small step, rearrange that approximation, and walk from a known boundary to the rest of the pricing function. Black–Scholes has a closed form, so the walk is a check. A Heston pricing equation does not, so the walk is how you get a price at all.

Why it matters

Give Black–Scholes a spot, a strike, a rate, a volatility, and a maturity, and the closed form returns a price. Those assumptions do not line up with listed prices. A Heston-style equation can fit more of that surface and has no comparable closed form. Finite differences are the replacement. The lecture's toy, solved by integrating, is the square root of x plus 1. The method is rebuilt from the definition of a derivative so it still works when that integral is unavailable.

The idea in plain words

The derivative is a limit as the step h goes to zero. A computer can use a small h instead of an infinitesimal and accept an approximation. The lecture's example is x squared, whose derivative at 1 is 2. With a very small h the difference quotient prints 2.0000001. Only the original function was evaluated, at x and at x plus h. No power rule was required.

Rearrange that quotient and you have Euler's forward step. The value at the next grid point is the value here plus h times the derivative here. A differential equation tells you the derivative. An initial condition tells you the first value. Everything after that is iteration. The lecture's animation paints a green pricing curve the solver does not know in advance. At a stock price of 1 the painted curve says the contract is worth 1. Stop the grid at 5 and the values at 10, 50, or 100 are not a safe extension. Even a price at 3 wants the grid carried well past 3. A closed form, when you have one, does not have that fence.

How to use it

The toy pricing equation has derivative one half times x to the power minus one half, and the condition that the function equals 1 at zero. Zero itself cannot be fed to that derivative, so the lecture's grid starts just off zero and stores the condition separately. NumPy builds the inputs. A loop of 2,000 steps appends the latest value plus the derivative times the spacing. Those few lines are the whole scheme: the printed array is the approximated pricing function, set next to the closed form square root of x plus 1.

A partial differential equation adds a dimension. The lecture uses the one-dimensional heat equation because Black–Scholes is a second-order parabolic equation of that family. Discretize space and time, replace each partial derivative by a difference, and step. Stability is a constraint on the grid, not a hope. With diffusion coefficient alpha, the lecture requires alpha times dt, divided by dx squared, to be at most one half. The worked choice alpha = 1, length 1, time 1, dx = 0.1, and dt = 0.005 passes. Enlarge the time step until the ratio exceeds one half and the errors grow as you march forward. Initial and boundary values are written onto the grid before the loops, the same role as f of 0 equals 1 in one dimension.

Black–Scholes uses stock price and time as the two axes. Plug the difference quotients into the pricing equation and the loop is the same shape. The lecture compares a coarse grid, a finer grid, and the closed form for a European call. The finer grid sits nearer the formula. A different contract changes the boundary values. The recipe does not.

What usually goes wrong

A grid that stops inside the region you will actually quote is the failure the animation is built to show. A heat-equation grid that breaks the one-half rule looks locally plausible and then blows up. Treating the European-call boundaries as universal is the third miss: the lecture's Black–Scholes demo is a European call, and another payoff changes the conditions you load before the first step. The scheme also does not derive the pricing equation. That derivation is a hedging argument. Finite differences only solve the equation once you have it.

Questions people ask

Why approximate a derivative you could differentiate?

Because the unknown is the pricing function, not its slope. The differential equation gives you the slope. The recurrence rebuilds the function from a boundary.

What grid passed the heat-equation test?

Alpha 1, dx 0.1, and dt 0.005, on a unit square in space and time. The ratio alpha dt over dx squared stayed at or below one half.

Does a finer grid replace a closed form?

On the lecture's European call it moves the surface toward the formula. Where no formula exists, as with the Heston pricing equation, the grid is the price, and it is only as wide as the inputs you covered.