%% Price a Callable Bond Using a BDT Interest-Rate Tree Model
% Create a BDTTree with the following data:

ZeroRates = [ 0.035;0.04;0.045];
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', ZeroRates, 'StartDates', ValuationDate, 'EndDates', ...
EndDates, 'Compounding', Compounding, 'ValuationDate', ValuationDate)

%
% Create a VolSpec.

Volatility = 0.10 * ones (3,1);
VolSpec = bdtvolspec(ValuationDate, EndDates, Volatility)

%
% Create a TimeSpec.

TimeSpec = bdttimespec(ValuationDate, EndDates, Compounding);

%
% Build the BDTTree.

BDTTree = bdttree(VolSpec, RateSpec, TimeSpec)

%
% To compute the price of an American callable bond that pays a 5.25% annual coupon, matures in Jan-1-2010, and is callable on Jan-1-2008 and 01-Jan-2010.

BondSettlement = 'jan-1-2007';
BondMaturity   = 'jan-1-2010'; 
CouponRate = 0.0525;
Period = 1;
OptSpec = 'call'; 
Strike = [100];  
ExerciseDates = {'jan-1-2008' '01-Jan-2010'}; 
AmericanOpt = 1;

PriceCallBond = optembndbybdt(BDTTree, CouponRate, BondSettlement, BondMaturity,...
OptSpec, Strike, ExerciseDates, 'Period', 1,'AmericanOp', 1)

% Copyright 2015 The MathWorks, Inc.