%% Compute Discount Factors From Interest Rates
% This example shows the two uses of rate2disc.
%% Interval Points Are Input as Times in Periodic Units
% Compute discounts from a zero curve at 6 months, 12 months, and 24 months. The times to the cash flows are 1, 2, and 4. Use rate2disc to compute the present value (at time 0) of the cash flows.

Compounding = 2;
Rates = [0.05; 0.06; 0.065];
EndTimes   = [1; 2; 4];
Disc = rate2disc(Compounding, Rates, EndTimes)

%
%% Interval Points Are Input as Dates
% Compute discounts from a zero curve at 6 months, 12 months, and 24 months. Use dates to specify the ending time horizon.

Compounding = 2;
Rates = [0.05; 0.06; 0.065];
EndDates = ['10/15/97'; '04/15/98'; '04/15/99'];
ValuationDate = '4/15/97'; 
Disc = rate2disc(Compounding, Rates, EndDates, [], ValuationDate)

% Copyright 2020 The MathWorks, Inc.