%% Compute Interest Rates from Cash Flow Discounting Factors
% This example shows the two uses of disc2rate.
%% Interval Points Are Input as Times in Periodic Units
% Compute rates from a zero curve at 6 months, 12 months, and 24 months, given the discount factors for these periods. The times to the cash flows are 1, 2, and 4. disc2rate assumes that the valuation date corresponds to time = 0.

Compounding = 2;
Disc = [0.9756; 0.9426; 0.8799];
EndTimes   = [1; 2; 4];
Rates = disc2rate(Compounding, Disc, EndTimes)

%
%% Interval Points Are Input as Dates
% Compute rates from a zero curve at 6 months, 12 months, and 24 months, given the discount factors for these periods. Use dates to specify the ending time horizon.

Compounding = 2;
Disc = [0.9756; 0.9426; 0.8799];
EndDates = ['10/15/97'; '04/15/98'; '04/15/99'];
ValuationDate = '4/15/97'; 
Rates = disc2rate(Compounding, Disc, EndDates, [], ValuationDate)

% Copyright 2020 The MathWorks, Inc.