%% Compute a Forward Par Swap Rate
% To compute a forward par swap rate, set the StartDate parameter to a future date and set the fixed coupon rate in the LegRate input to NaN.
% Define the zero curve data and build a zero curve using IRDataCurve.

ZeroRates = [2.09 2.47 2.71 3.12 3.43 3.85 4.57]'/100;
Settle = datenum('1-Jan-2012');
EndDates = datemnth(Settle,12*[1 2 3 5 7 10 20]');
Compounding = 1;

ZeroCurve = IRDataCurve('Zero',Settle,EndDates,ZeroRates,'Compounding',Compounding)

%
% Create a RateSpec structure using the toRateSpec method.

RateSpec = ZeroCurve.toRateSpec(EndDates)

%
% Compute the forward swap rate (the coupon rate for the fixed leg), such that the forward swap price at time = 0 is zero. The forward swap starts in a month (1-Feb-2012) and matures in 10 years (1-Feb-2022).

StartDate = datenum('1-Feb-2012');
Maturity = datenum('1-Feb-2022');
LegRate = [NaN 0];

[Price, SwapRate] = swapbyzero(RateSpec, LegRate, Settle, Maturity,...
'StartDate', StartDate)

% Copyright 2012 The MathWorks, Inc.