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

Crank-Nicolson Method

For the Crank-Nicolson method we shall need:

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:

\includegraphics[width=\textwidth]{Figs/CN-structure.eps}
where at each timestep we must solve the matrix equation

$\displaystyle A\mathbf{V} = b.
$

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

First we must carry out the initial setup phase where we assign values to parameters such as $ dS$, $ dt$ and resize any vectors that depend on the choice of grid size $ N$ and $ KMAX$. 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 up previous
Next: Example - European Put Up: Finite-Difference Methods Previous: Explicit method
Paul Johnson 2009-04-06