I would like to calibrate a interest rate tree using the optimization tool in matlab. Need some guidance on doing it.
The interest rate tree looks like this:
How it works:
3.73% = 2.5%*exp(2*0.2)
96.40453 = (0.5*100 + 0.5*100)/(1+3.73%)
94.15801 = (0.5*96.40453+ 0.5*97.56098)/(1+2.50%)
The value of 2.5% is arbitrary and the upper node is obtained by multiplying with an exponential of 2*volatility(here it is 20%).
I need to optimize the problem by varying different values for the lower node.
How do I do this optimization in Matlab?
What I have tried so far?
InterestTree{1}(1,1) = 0.03;
size = size(InterestTree,2);
InterestTree{size-1}(1,size-1)= 2.5/100;
InterestTree{size}(2,:) = 100;
InterestTree{size-1}(1,size-2)= (2.5*exp(2*0.2))/100;
InterestTree{size-1}(2,size-1)=(0.5*InterestTree{size}(2,size)+0.5*InterestTree{size}(2,size-1))/(1+InterestTree{size-1}(1,size-1));
j = size-2;
InterestTree{size-1}(2,size-2)=(0.5*InterestTree{size}(2,j+1)+0.5*InterestTree{size}(2,j))/(1+InterestTree{size-1}(1,j));
InterestTree{size-2}(2,size-2)=(0.5*InterestTree{size-1}(2,j+1)+0.5*InterestTree{size-1}(2,j))/(1+InterestTree{size-2}(1,j));
New Edit:
function [ diff ] = InterestTreeComputation(Interest,DiscountedValue,alpha)
total= size(Interest,1);
n = ceil(0.5*(-1+sqrt(1+8*total)));
DiscountedValue(end:-1:(end-n+1)) = 100;
m=0;
for i=total-n:-1:total-2*n+2
Interest(i)= (alpha*exp(2^(m)*0.005))/100;
m = m+1;
end
for j= total-n:-1:1
columnnumber =ceil(0.5*(-1+sqrt(1+8*j)));
DiscountedValue(j) = (0.5*DiscountedValue(j+columnnumber)+0.5*DiscountedValue(j+columnnumber+1))/(1+Interest(j));
end
Data = xlsread('InterestData.xlsx');
ActualValue = Data(:,4);
diff = (DiscountedValue(1) - ActualValue(n-1))^2;
end
How I call it:
clear all;close all;clc;
Interest = [0.0954;0;0];
DiscountedValue =zeros(3,1);
Interest = [Interest; zeros(3,1)];
DiscountedValue = [DiscountedValue; zeros(3,1)];
fhand = @(x)InterestTreeComputation(Interest,DiscountedValue,x);
x0 = 2.5;
x_optimal = fminunc(fhand, x0);
How do you optimize this function? Is it like this => x = fminunc(@ITree,x0)?