Next: Example - European Put Up: Finite-Difference Methods Previous: Explicit method

## Crank-Nicolson Method

For the Crank-Nicolson method we shall need:

• All parameters for the option, such as and etc.
• The number of divisions in stock, , and divisions in time
• The size of the divisions and
• Vectors to store:
• stock price
• old option values
• new option values
• three diagonal elements (a, b, and c)
• the right hand side of the matrix equation
Again, the easiest thing to do is just to declare these at the top of the program before you start doing anything with them.

A sample program structure for the Crank-Nicolson method may look something like:

where at each timestep we must solve the matrix equation

Since the matrix is tridiagonal we need only use three vectors to store all values in the matrix .

First we must carry out the initial setup phase where we assign values to parameters such as , and resize any vectors that depend on the choice of grid size and . Also we can now assign values to vectors such as stock values (that remain constant throughout) and the final payoff condition to the option values.

Now create a time loop (check that it runs for the appropriate amount of loops) and finishes at the correct time. Try to avoid using while loops that evaluate a condition on a double, use integers instead. Inside the loop the code will be broken into two sections, matrix setup and matrix solver, both of which may be written into functions later. See the example linked below for how to setup and solve the matrix equations.

Subsections

Next: Example - European Put Up: Finite-Difference Methods Previous: Explicit method
Paul Johnson 2009-04-06