%% Compute the Implied 2-Year Forward Rates in 1 Year, 2 Years, 5 Years, and 10 Years
% This example shows how to compute the implied 2-year forward rates in 1 year, 2 years, 5 years, and 10 years from the Settle date by using the getForwardRates method.
% Use the following data for an IRFunctionCurve object that is created when using the fitSvensson method.

Settle = datenum('15-Apr-2014');
Maturity = datemnth(Settle,12*[1 2 3 5 7 10 20 30]');

CleanPrice = [100.1 100.1 100.2 99.0 101.8 99.2 101.7 100.2]';
CouponRate = [0.0200 0.0275 0.035 0.042 0.0475 0.0525 0.055 0.052]';
Instruments = [repmat(Settle,size(Maturity)) Maturity CleanPrice CouponRate];

SvenssonModel = IRFunctionCurve.fitSvensson('Zero',Settle,Instruments);

%
% Compute the implied 2-year forward rates in 1 year, 2 years, 5 years, and 10 years from the Settle date.

IntervalMonth = 12.*2;         % Interval months for 2-year forward rates
FwdMonths = 12.*[1 2 5 10]';   % Starting in 1, 2, 5, and 10 years from Settle
N = length(FwdMonths);
FwdRates_2Y = zeros(N,1);

for k = 1:N
    FwdDates = datemnth(SvenssonModel.Settle, [FwdMonths(k) FwdMonths(k)+IntervalMonth]);
    f = getForwardRates(SvenssonModel,FwdDates);
    FwdRates_2Y(k) = f(2);
end

[FwdMonths FwdRates_2Y]

% Copyright 2012 The MathWorks, Inc.