%% 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.
% Price two collared floating-rate notes using the following data:

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 HW tree and assume the volatility to be 5%.

VolDates = ['1-April-2013';'1-April-2014';'1-April-2015';...
'1-April-2016';'1-April-2017';'1-April-2018'];
VolCurve = 0.05;
AlphaDates = '15-Nov-2018';
AlphaCurve = 0.1;

HWVolSpec = hwvolspec(RateSpec.ValuationDate, VolDates, VolCurve,... 
AlphaDates, AlphaCurve);
HWTimeSpec = hwtimespec(RateSpec.ValuationDate, VolDates, Compounding);
HWT = hwtree(HWVolSpec, RateSpec, HWTimeSpec);

%
% Create the floating-rate note instrument.

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

%
% Compute the price of a vanilla floater.

Price = floatbyhw(HWT, Spread, Settle, Maturity)

%
% Compute the price of the collared floating-rate notes.

CapStrike = {{'1-April-2014' 0.045; '1-April-2015' 0.05;...
 '1-April-2016' 0.06}; 0.06};
         
FloorStrike = {{'1-April-2014' 0.035; '1-April-2015' 0.04;...
 '1-April-2016' 0.05}; 0.03};
PriceCollared = floatbyhw(HWT, Spread, Settle, Maturity,....
'CapRate', CapStrike,'FloorRate', FloorStrike)

% Copyright 2015 The MathWorks, Inc.