%% Compute the Price of an Amortizing and Vanilla Caps Using the HW Model
% Define the RateSpec.

Rates = [0.035; 0.042; 0.047; 0.052; 0.054];
ValuationDate = '01-April-2014';
StartDates = ValuationDate;
EndDates = {'01-April-2019'};
Compounding = 1;
RateSpec = intenvset('ValuationDate', ValuationDate,'StartDates', StartDates,...
'EndDates', EndDates,'Rates', Rates, 'Compounding', Compounding)

%
% Define the cap instruments.

Settle ='01-April-2014';
Maturity = '01-April-2018';
Strike = 0.055;
CapReset = 1;
Principal ={{'01-April-2015' 100;'01-April-2016' 60;'01-April-2017' 40;'01-April-2018' 20};
            100};

%
% Build the HW Tree.

VolDates = ['01-April-2015';'01-April-2016';'01-April-2017';'01-April-2018'];
VolCurve = 0.05;
AlphaDates = '01-April-2018';
AlphaCurve = 0.10;

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

%
% Price the amortizing and vanilla caps.

Basis = 0;
Price  = capbyhw(HWTree, Strike, Settle, Maturity, CapReset, Basis, Principal)

% Copyright 2015 The MathWorks, Inc.