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 value_tree[i][j].

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

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:

• Write for loops to move backwards through the vector array caculating the value of the option at each node.
• Print out the tree to screen (with n=3) and compare to the simple example in the lectures to check your code is working.
• If your values don't match - try to work out why!!
• Now print out the value at increasing the number of steps in the tree. Do the results look feasible? Compare them against the exact values from the formula.

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 and one for . How will your algorithm change?

• Write a code storing two time-levels, and compare (at every stage if needed) with the previous code.
• Is it possible to store just one time-level? Try to write a code for this.
• Do you notice any difference (time taken for computation) between the codes with different storage requirements?

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