%% Price a Collar with a Floating-Rate Note
% Price a collar with a floating-rate note using the CapRate and FloorRate input argument to define the collar pricing.
% Create the RateSpec.

Rates = [0.0287; 0.03024; 0.03345; 0.03861; 0.04033];
ValuationDate = '1-April-2012';
StartDates = ValuationDate;
EndDates = {'1-April-2013';'1-April-2014';'1-April-2015' ;...
'1-April-2016';'1-April-2017'};
Compounding = 1;

%
% Create the RateSpec.

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

%
% Build the BDT tree and assume volatility is 5%.

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

%
% Create the floating rate note instrument.

Settle ='1-April-2012';
Maturity = '1-April-2016';
Spread = 10;
Principal = 100;

%
% Compute the price of a collared floating-rate note.

CapStrike = {{'1-April-2013' 0.03; '1-April-2015' 0.055}};
FloorStrike = {{'1-April-2013' 0.025; '1-April-2015' 0.04}};

Price = floatbybdt(BDTT, Spread, Settle, Maturity, 'CapRate',...
CapStrike, 'FloorRate', FloorStrike)

% Copyright 2015 The MathWorks, Inc.