next up previous
Next: Finite-Difference Methods Up: Binomial Tree - Stock Previous: A stock price tree

A Binomial tree

Let us generate a simple example so that we can compare results at every stage to something that we can work out on paper. This is an important idea in debugging, to solve to problem and do all of your bug checking on a small scale before attempting the full problem.

First declare a 2D vector which shall hold the values of the option

vector < vector < double > > value_tree;

and resize it to the same size as stock_tree. Here we use the same relation $ V_{i,j} \rightarrow $value_tree[i][j].

Now fill in the final values of the tree, given that we have already first generated the stock tree:

$\displaystyle V_{n,j}=payoff(S_{n,j}),
$

and payoff is the appropriate function for the type of option we are solving for. Try with a European call option first. Now we need to loop backwards through the tree to generate the value at each node using the equation:

$\displaystyle V_{ij}=e^{-r\Delta t}(qV_{i+1,j+1}+(1-q)V_{i+1,j}).
$

We don't really need to generate the stock tree, and don't really need to store all of the value tree. Try to think about how you could change your code to just store two time levels for the tree, a vector for $ V_{i,j}$ and one for $ V_{i+1,j}$. How will your algorithm change?


next up previous
Next: Finite-Difference Methods Up: Binomial Tree - Stock Previous: A stock price tree
Paul Johnson 2009-04-06