%% Price an Amortizing Callable Bond Using a BK Interest-Rate Tree Model
% This example shows how to price an amortizing callable bond and a vanilla callable bond using a BK lattice model.
% Create a RateSpec.

Rates = [0.035; 0.042147; 0.047345; 0.052707];
ValuationDate = 'Jan-1-2012';
StartDates = ValuationDate;
EndDates = {'Jan-1-2013'; 'Jan-1-2014'; 'Jan-1-2015'; 'Jan-1-2016'};
Compounding = 1;
RS = intenvset('ValuationDate', ValuationDate, 'StartDates', StartDates,...
'EndDates', EndDates,'Rates', Rates, 'Compounding', Compounding);

% Build a BK tree.

VolDates = ['1-Jan-2013'; '1-Jan-2014'; '1-Jan-2015'; '1-Jan-2016'];
VolCurve = 0.01;
AlphaDates = '01-01-2016';
AlphaCurve = 0.1;

BKVolSpec = bkvolspec(RS.ValuationDate, VolDates, VolCurve,... 
AlphaDates, AlphaCurve);
BKTimeSpec = bktimespec(RS.ValuationDate, VolDates, Compounding);
BKT = bktree(BKVolSpec, RS, BKTimeSpec);

% Define the callable bond.

CouponRate = 0.05;
Settle = 'Jan-1-2012';
Maturity =  'Jan-1-2016';
Period = 1;
    
    Face = { 
                 {'Jan-1-2014'  100; 
                  'Jan-1-2015'   70;
                  'Jan-1-2016'   50};
                 };
 
OptSpec = 'call'; 
Strike = [97 95 93];
ExerciseDates ={'Jan-1-2014' 'Jan-1-2015' 'Jan-1-2016'};

% Price a callable amortizing bond using the BDT tree.

BondType = 'amortizing';
Pcallbonds = optembndbybk(BKT, CouponRate,  Settle, Maturity ,OptSpec, Strike,...
ExerciseDates, 'Period', 1,'Face',Face,'BondType', BondType)

% Copyright 2019 The MathWorks, Inc.