%% Price a Forward Swap
% Price a forward swap using the StartDate input argument to define the future starting date of the swap.
% Create the RateSpec.

Rates = 0.0325;
ValuationDate = '1-Jan-2012';
StartDates = ValuationDate;
EndDates = '1-Jan-2018';
Compounding = 1;

RateSpec = intenvset('ValuationDate', ValuationDate,'StartDates', StartDates,...
'EndDates', EndDates,'Rates', Rates, 'Compounding', Compounding)

%
% Build the tree with a volatility of 10%.

MatDates = {'1-Jan-2013'; '1-Jan-2014';'1-Jan-2015';'1-Jan-2016';'1-Jan-2017';'1-Jan-2018'};
BDTTimeSpec = bdttimespec(ValuationDate, MatDates);
Volatility = 0.10;  
BDTVolSpec = bdtvolspec(ValuationDate, MatDates, Volatility*ones(1,length(MatDates))');
BDTT = bdttree(BDTVolSpec, RateSpec, BDTTimeSpec);

%
% Compute the price of a forward swap that starts in two years (Jan 1, 2014) and matures in three years with a forward swap rate of 3.85%.

Settle ='1-Jan-2012';
Maturity = '1-Jan-2017';
StartDate = '1-Jan-2014';
LegRate = [0.0385 10];

Price = swapbybdt(BDTT, LegRate, Settle, Maturity, 'StartDate', StartDate)

%
% Using the previous data, compute the forward swap rate, the coupon rate for the fixed leg, such that the forward swap price at time = 0 is zero.

LegRate = [NaN 10];
[Price, ~,~, SwapRate] = swapbybdt(BDTT, LegRate, Settle, Maturity, 'StartDate', StartDate)

% Copyright 2015 The MathWorks, Inc.