%% Demonstrate a Roundtrip From zero2pyld to pyld2zero
% Given the following zero curve and its maturity dates, return the ParRates.

Settle = datenum('01-Feb-2013');

CurveDates = [datenum('01-Feb-2014')
    datenum('01-Feb-2015')
    datenum('01-Feb-2016')
    datenum('01-Feb-2018')
    datenum('01-Feb-2020')
    datenum('01-Feb-2023')
    datenum('01-Feb-2033')
    datenum('01-Feb-2043')];

OriginalZeroRates = [.11 0.30 0.64 1.44 2.07 2.61 3.29 3.55]'/100;

OutputCompounding = 1;
OutputBasis = 0;
InputCompounding = 1;
InputBasis = 0;

ParRates = zero2pyld(OriginalZeroRates, CurveDates, Settle, ...
'OutputCompounding', OutputCompounding, 'OutputBasis', OutputBasis, ...
'InputCompounding', InputCompounding, 'InputBasis', InputBasis)

%
% For the ParRates, use the pyld2zero function to return the ZeroRatesOut and determine the roundtrip error.

ZeroRatesOut = pyld2zero(ParRates, CurveDates, Settle, ...
'OutputCompounding', OutputCompounding, 'OutputBasis', OutputBasis, ...
'InputCompounding', InputCompounding, 'InputBasis', InputBasis)

max(abs(OriginalZeroRates - ZeroRatesOut)) % Roundtrip error

% Copyright 2012 The MathWorks, Inc.