In generating a binomial tree, we have to first generate a tree of stock prices. Using the centered tree approach of Cox-Rubenstein-Ross, we define Si,j =S0,0 uj di-j
If we want to generate a tree that looks like the one below,
|
 |
 |
 |
 |
100.1 |
 |
 |
 |
 |
100.08 |
 |
 |
 |
 |
100.06 |
 |
100.06 |
 |
 |
100.04 |
 |
100.04 |
 |
 |
100.02 |
 |
100.02 |
 |
100.02 |
100 |
 |
100 |
 |
100 |
 |
 |
99.98 |
 |
99.98 |
 |
99.98 |
 |
 |
99.96 |
 |
99.96 |
 |
 |
 |
 |
99.94 |
 |
99.94 |
 |
 |
 |
 |
99.92 |
 |
 |
 |
 |
 |
 |
99.9 |
We can use code such as
StockTree=Table[S[i,j],{i,0,n},{j,i,0,-1}];Â Show[Graphics[{Text[“Stock Price”,{2,2}],Table[Text[Reverse[StockTreePi\[RightDoubleBracket]],{2,2-i}],{i,1,n+1}]}]]
However there is a problem when we want to evaluate the StockTree for calculation of puts or calls. In standard form, our stock tree looks like this:
{{100},{100.02,99.98},{100.04,100.,99.96},{100.06,100.02,99.98,99.94},{100.08,100.04,100.,99.96,99.92},{100.1,100.06,100.02,99.98,99.94,99.9}}
Suppose we want to calculate a call tree, where we want Max[S-K,0].Â
The Max function won’t map across the list.Â
For a simpler example, consider the list created as
myTable = Table[Table[i,{i,1,j}],{j,1,5}]{{1},{1,2},{1,2,3},{1,2,3,4},{1,2,3,4,5}}
If you try taking Max[myTable-3,0], you will just get the value of 2 (from the last element 5), when what we really wanted was to have the Max function applied across all elements.Â
We could flatten and restructure the list, applying Max element by element, but it seems there should be a better way. The reason you can’t get the result you want is because the built in Max function does not have the Listable attribute. To see the attributes, just type Attributes[Max]. The result is:
{Flat,NumericFunction,OneIdentity,Orderless,Protected,ReadProtected}
Not that it’s a good idea to change the attributes of built in functions, but you can type Attributes[Max]={Listable}. Now look what happens when you type Max[myTable]: you get the desired result of {{0},{0,0},{0,0,0},{0,0,0,1},{0,0,0,1,2}}
Now, we can go ahead and define our call and put functions CallTree = Max[StockTree-K,0] whose result is
{{0},{0.020002,0},{0.040008,0.,0},{0.060018,0.020002,0,0},{0.080032,0.040008,0,0,0},{0.10005,0.060018,0.020002,0,0,0}} and so forth.