I am trying to program a binomial tree in Matlab. The tree looks something like this:
The numbers in the picture refer to the index of the array to create a binomial tree.
Problem:
Value of 2 = 0.5*Value of 4 + 0.5*Value of 5
Value of 3 = 0.5*Value of 5 + 0.5*Value of 6
I need to link the value of 2 to value of 4 and value of 5, similarly for value of 3 accordingly.
How do i get the link mathematically so that I can program it, instead of stating it manually?
I hope the problem is clear. Need some guidance on this.
How I am programming it?
Basically I am trying to model an interest rate tree. I am having a array for interest and another for the discounted value. I have a previous qn:Interest Rate Tree in Matlab. Now I am changing to vectors.I programmed it using cell arrays, now changing to vectors.
Interest = [0.03;0;0];
DiscountedValue =zeros(3,1);
Interest = [Interest; zeros(n,1)];
DiscountedValue = [DiscountedValue; zeros(n,1)];
total= size(Interest,1);
DiscountedValue(end:-1:(end-n+1)) = 100;
m=0
for i=total-n:-1:total-2n+2
Interest(i)= (alpha*exp(2^(m)*volatility))/100;
m = m+1;
end
for j= total-n:-1:1
//Stuck here//DiscountedValue(j) = (0.5*DiscountedValue(j+0.5*DiscountedValue{j+1}(2,i+1))/(1+Interest(j));
end