%% Price an Amortizing Floating-Rate Note
% Price an amortizing floating-rate note using the Principal input argument to define the amortization schedule.
% Create the RateSpec.

Rates = [0.03583; 0.042147; 0.047345; 0.052707; 0.054302];
ValuationDate = '15-Nov-2011';
StartDates = ValuationDate;
EndDates = {'15-Nov-2012';'15-Nov-2013';'15-Nov-2014' ;'15-Nov-2015';'15-Nov-2016'};
Compounding = 1;
RateSpec = intenvset('ValuationDate', ValuationDate,'StartDates', StartDates,...
'EndDates', EndDates,'Rates', Rates, 'Compounding', Compounding)

%
% Create the floating-rate instrument using the following data:

Settle ='15-Nov-2011';
Maturity = '15-Nov-2015';
Spread = 15;

%
% Define the floating-rate note amortizing schedule.

Principal ={{'15-Nov-2012' 100;'15-Nov-2013' 70;'15-Nov-2014' 40;'15-Nov-2015' 10}};

%
% Build the HJM tree using the following data:

MatDates = {'15-Nov-2012'; '15-Nov-2013';'15-Nov-2014';'15-Nov-2015';'15-Nov-2016';'15-Nov-2017'};
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);

%
% Compute the price of the amortizing floating-rate note.

Price = floatbyhjm(HJMT, Spread, Settle, Maturity, 'Principal', Principal)

% Copyright 2015 The MathWorks, Inc.