%% Compute a Forward Swap Rate Using the Optional Input BusinessDayConvention
% The swapbyzero function generates the cash flow dates based on the Settle and Maturity dates, while using the Maturity date as the "anchor" date from which to count backwards in regular intervals. By default, swapbyzero does not distinguish non-business days from business days. To make swapbyzero move non-business days to the following business days, you can you can set the optional name-value input argument BusinessDayConvention with a value of follow.
% 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('5-Jan-2012');
EndDates = datemnth(Settle,12*[1 2 3 5 7 10 20]');
Compounding = 1;
ZeroCurve = IRDataCurve('Zero',Settle,EndDates,ZeroRates,'Compounding',Compounding);
RateSpec = ZeroCurve.toRateSpec(EndDates);
StartDate = datenum('5-Feb-2012');
Maturity = datenum('5-Feb-2022');
LegRate = [NaN 0];

%
% To demonstrate the optional input BusinessDayConvention, swapbyzero is first used without and then with the optional name-value input argument BusinessDayConvention. Notice that when using BusinessDayConvention, all days are business days.

[Price1,SwapRate1,~,~,RecCFDates1,~,PayCFDates1] = swapbyzero(RateSpec,LegRate,Settle,Maturity,...
    'StartDate',StartDate);
datestr(RecCFDates1)
isbusday(RecCFDates1)

[Price2,SwapRate2,~,~,RecCFDates2,~,PayCFDates2] = swapbyzero(RateSpec,LegRate,Settle,Maturity,...
    'StartDate',StartDate,'BusinessDayConvention','follow');
datestr(RecCFDates2)
isbusday(RecCFDates2)

% Copyright 2012 The MathWorks, Inc.