« exam instructions | Main | next session will not be broadcast »

MATLAB for yield problem

Here is the code I used last night to plot the yield to redemption for a bond with a continuous coupon:

y=@(T,P,c)fzero(@(y)c/y+(1-c/y)*exp(-y*T)-P,c);
fplot(@(T)y(T,1.02,0.04),[1 10])