%% Price a Callable Bond Using an HJM Interest-Rate Tree Model
% Create a HJMTree with the following data:

Rates = [0.05;0.06;0.07];
Compounding = 1;
StartDates = ['jan-1-2007';'jan-1-2008';'jan-1-2009'];
EndDates   = ['jan-1-2008';'jan-1-2009';'jan-1-2010'];
ValuationDate = 'jan-1-2007';

%
% Create a RateSpec.

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

%
% Create a VolSpec.

VolSpec = hjmvolspec('Constant', 0.01)

%
% Create a TimeSpec.

TimeSpec = hjmtimespec(ValuationDate, EndDates, Compounding)

%
% Build the HJMTree.

HJMTree = hjmtree(VolSpec, RateSpec, TimeSpec)

%
% To compute the price of an American callable bond that pays a 6% annual coupon and matures and is callable on January 1, 2010.

BondSettlement = 'jan-1-2007';
BondMaturity   = 'jan-1-2010'; 
CouponRate = 0.06;
Period = 1;
OptSpec = 'call'; 
Strike = [98];  
ExerciseDates = '01-Jan-2010'; 
AmericanOpt = 1;

[PriceCallBond,PT] = optembndbyhjm(HJMTree, CouponRate, BondSettlement, BondMaturity,...
OptSpec, Strike, ExerciseDates, 'Period', 1,'AmericanOp',1)

% Copyright 2015 The MathWorks, Inc.