%% Compute the Bond Prices in a Portfolio Using a Set of Zero Curves
% This example uses the function zbtprice to compute a zero curve given a portfolio of coupon bonds and their prices. It then reverses the process, using the zero curve as input to the function prbyzero to compute the prices.

Bonds = [datenum('6/1/1998') 0.0475 100 2 0 0; 
         datenum('7/1/2000') 0.06 100 2 0 0; 
         datenum('7/1/2000') 0.09375 100 6 1 0; 
         datenum('6/30/2001') 0.05125 100 1 3 1;
         datenum('4/15/2002') 0.07125 100 4 1 0;
         datenum('1/15/2000') 0.065 100 2 0 0; 
         datenum('9/1/1999') 0.08 100 3 3 0; 
         datenum('4/30/2001') 0.05875 100 2 0 0; 
         datenum('11/15/1999') 0.07125 100 2 0 0; 
         datenum('6/30/2000') 0.07 100 2 3 1; 
         datenum('7/1/2001') 0.0525 100 2 3 0; 
         datenum('4/30/2002') 0.07 100 2 0 0];

Prices = [ 99.375;
           99.875;
          105.75 ;
           96.875;
          103.625;
          101.125;
          103.125;
           99.375;
          101.0  ;
          101.25 ;
           96.375;
          102.75 ];

Settle = datenum('12/18/1997');

%
% Set semiannual compounding for the zero curve, on an actual/365 basis.

OutputCompounding = 2;

%
% Execute the function zbtprice which returns the zero curve at the maturity dates.

[ZeroRates, ZeroDates] = zbtprice(Bonds, Prices, Settle,...
OutputCompounding)

%
% Execute the function prbyzero.

BondPrices = prbyzero(Bonds, Settle, ZeroRates, ZeroDates)

% In this example zbtprice and prbyzero do not exactly reverse each other. Many of the bonds have the end-of-month rule off (EndMonthRule = 0). The rule subtly affects the time factor computation. If you set the rule on (EndMonthRule = 1) everywhere in the Bonds matrix, then prbyzero returns the original prices, except when the two incompatible prices fall on the same maturity date.
% Copyright 2015 The MathWorks, Inc.