function binplot1(spot)
% BINPLOT1 plots a binomial tree matrix. The matrix must
% be square.
%
% BINPLOT1(SPOT) where SPOT is the spot interest rates.
% SPOT can be spot prices, interest rates, etc ...
%
% For example :
%
% binplot1(binprice(52,50,.1,5/12,1/12,.4,0,0,2.06,3.5));
% Author: Ashesh Pansuria
% E-mail: ashesh@insnet.com
% Environment: MATLAB 4.2c.1 in Windows 95 %
if length(spot) == 1
error('Please check your spot (prices/rates)')
end
% Strip off the unwanted values
% of the binomial pricing matrix
% First create an index vector
j = 1;
index = 1;
for i = 1:length(spot):(length(spot) - 1).^2
index = [index length(spot) + i : length(spot) + i + j];
j = j + 1;
end
newspot = spot(index);
% Create 4 main vectors :
% (1) xvector - used for plotting dots and text
% (2) yvector - used for plotting dots and text
% (3) xvec - used for connecting the dots
% (4) yvec - used for connecting the dots
xvector = 1;
for i = 2:length(spot)
xvector = [xvector i*ones(1,i)];
end
vec = 0;
for i = 1 : length(spot)
vec = [vec i:-2:-i];
end
yvector = .5;
offset = .02;
for i = 1:length(xvector)
yvector(i) = .5 + vec(i)*offset;
end
for n=1:length(spot)
temp = [n:n+1];
for iter = 1:2*n
xvec = [xvec temp];
end
end
for i=1:2*length(yvector)
dupyvector(i)=yvector(ceil(i/2));
end
for i = 1:2*length(dupyvector)
dupdupyvector(i)=dupyvector(ceil(i/2));
end
for i = 1:length(dupdupyvector)
if isodd(i) == 1
yvec(i) = dupdupyvector(i);
end
if isodd(i) == -1
if isodd(i/2) == 1
yvec(i) = dupdupyvector(i) + offset;
end
if isodd(i/2) == -1
yvec(i) = dupdupyvector(i) - offset;
end
end
end
% Set up the figure, x-axis limits
% y-axis limits
fig = figure( ...
'Name','Tree Output', ...
'NumberTitle','off', ...
'Visible','on', ...
'BackingStore','off');
set(gca,'Xlim',[0 length(spot)]);
set(gca,'Ylim',[0 1]);
% Plot the individual points and the
% corresponding text labels
if length(spot) < 4
for i = 1:length(newspot)
plot(xvector(i),yvector(i),'ro');hold on
text(xvector(i) - .05,yvector(i) + .005,num2str(newspot(i)),'FontSize',10);
hold on
axis off
end
else
for i = 1:length(newspot)
plot(xvector(i),yvector(i),'ro');hold on
text(xvector(i) - .15,yvector(i) + .01,num2str(newspot(i)),'FontSize',8);
hold on
axis off
end
end
% Connect the individual dots
for i = 1:2:length(xvec) - (1 + 4*length(spot))
plot([xvec(i),xvec(i + 1)],[yvec(i),yvec(i + 1)]);
hold on
end