%% 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.0374;
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 a BK tree.

VolDates = {'1-Jan-2013'; '1-Jan-2014';'1-Jan-2015';'1-Jan-2016';'1-Jan-2017';'1-Jan-2018'};
VolCurve = 0.1;
AlphaDates = '01-01-2018';
AlphaCurve = 0.1;

BKVolSpec = bkvolspec(RateSpec.ValuationDate, VolDates, VolCurve,... 
AlphaDates, AlphaCurve);
BKTimeSpec = bktimespec(RateSpec.ValuationDate, VolDates, Compounding);
BKT = bktree(BKVolSpec, RateSpec, BKTimeSpec);

%
% Compute the price of a forward swap that starts in a year (Jan 1, 2013) and matures in four years with a forward swap rate of 4.25%.

Settle ='1-Jan-2012';
Maturity = '1-Jan-2017';
StartDate = '1-Jan-2013';
LegRate = [0.0425 10];

Price = swapbybk(BKT, 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] = swapbybk(BKT, LegRate, Settle, Maturity, 'StartDate', StartDate)

% Copyright 2015 The MathWorks, Inc.