%% 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 a portfolio of 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 HJM tree with the following data:

MatDates = {'1-April-2013'; '1-April-2014';'1-April-2015';...
'1-April-2016';'1-April-2017';'1-April-2018'};
HJMTimeSpec = hjmtimespec(RateSpec.ValuationDate, MatDates);
Volatility = [.10; .08; .06; .04];
CurveTerm = [ 1; 2; 3; 4];
HJMVolSpec = hjmvolspec('Proportional', Volatility, CurveTerm, 1e6);
HJMT = hjmtree(HJMVolSpec,RateSpec,HJMTimeSpec);

%
% Create the floating-rate note instrument.

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

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

CapStrike = [0.04;0.055];
PriceCapped = floatbyhjm(HJMT, Spread, Settle, Maturity,...
'CapRate', CapStrike)

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

FloorStrike = [0.035;0.040];
PriceCollared = floatbyhjm(HJMT, Spread, Settle, Maturity,...
'CapRate', CapStrike, 'FloorRate', FloorStrike)

% Copyright 2015 The MathWorks, Inc.