%	Computes the yield to maturity of a bond paying semi-annual
%	coupon payments
%
%	price, coupon payment, and time to maturity (in years) are set below
%
%	Use the function "bondvalue"
%
price = 1100	%	current price of the bond
C = 25		%	coupon payment
T= 10 		%	time to maturity
par = 1000	%	par value of the bond

lower = .015 ;
upper = .025
r = linspace(lower,upper,300)' ;	%	grid of values of yield to maturity05
value = bondvalue(C,T,r,par) ;	%	prices corresponding to r values

yield2M = interp1(value,r,price,'cubic') ;	%	Find yield to maturity by interpolation

%	Plot of price versus yield to maturity 
%	(not actually needed to find yield to maturity)
%

fsize = 14 ;

figure(1)
clf
p=plot(r,value) ;
xlabel('yield to maturity','fontsize',fsize) ;
ylabel('price of bond','fontsize',fsize) ;
title(['par='  num2str(par)  ', coupon payment='  num2str(C) ...
	  ', T=' num2str(T)],'fontsize',fsize) ;
L1=line( [lower,upper], [price price]) ;
L2 =line( [yield2M yield2M] , [700 1200]) ;
set(p,'linewidth',3) ;
set(gca,'xlim',[lower,upper]) ;
set(gca,'ylim',[700 1200]) ;
print yield2m.ps -deps ;

disp(['yield to maturity = ' num2str(yield2M)]) ;
