%% Compute the Price of American and European Call Options on a Floating-Rate Note
% Define the interest-rate term structure.

Rates = [0.03;0.035;0.040;0.045];
ValuationDate = 'Jan-1-2012';
StartDates = {'Jan-1-2012'; 'Jan-1-2013'; 'Jan-1-2014'; 'Jan-1-2015'};
EndDates = {'Jan-1-2013'; 'Jan-1-2014'; 'Jan-1-2015'; 'Jan-1-2016'};
Compounding = 1;

%
% Create the RateSpec.

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

%
% Build the HJM tree.

VolSpec = hjmvolspec('Constant', 0.01);
TimeSpec = hjmtimespec(RateSpec.ValuationDate, EndDates, Compounding);
HJMTree = hjmtree(VolSpec, RateSpec, TimeSpec)

%
% The floater instrument has a spread of 10, a period of one year, and matures on Jan-1-2015.

Spread = 10;
Settle = 'Jan-1-2012';
Maturity =  'Jan-1-2015';
Period = 1;

%
% Define the option for the floating-rate note.

OptSpec = {'call'};
Strike = 95;
ExerciseDates = 'Jan-1-2015';
AmericanOpt = [0;1];

%
% Compute the price of the call options.

Price= optfloatbyhjm(HJMTree,  OptSpec, Strike, ExerciseDates,AmericanOpt,...
Spread, Settle, Maturity)

% Copyright 2015 The MathWorks, Inc.