%% Price a Callable Bond Using a BK Interest-Rate Tree Model
% Create a BKTree 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.

VolDates = ['jan-1-2008';'jan-1-2009';'jan-1-2010'];
VolCurve = 0.01;
AlphaDates = 'jan-1-2010';
AlphaCurve = 0.1;
BKVolSpec = bkvolspec(ValuationDate, VolDates, VolCurve, AlphaDates, AlphaCurve)

%
% Create a TimeSpec.

BKTimeSpec = bktimespec(ValuationDate, EndDates, Compounding);

%
% Build the BKTree.

BKTree = bktree(BKVolSpec, RateSpec, BKTimeSpec)

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

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

PricePutBondBK = optembndbybk(BKTree, CouponRate, BondSettlement, BondMaturity,...
OptSpec, Strike, ExerciseDates,'Period', 1, 'AmericanOpt', 1)

% Copyright 2015 The MathWorks, Inc.