%% Compute OAS for an Amortizing Callable Bond Using a BDT Interest-Rate Tree Model
% This example shows how to compte the OAS for an amortizing callable bond using a BDT lattice model.
% Create a RateSpec.

Rates = [0.025;0.028;0.030;0.031];
ValuationDate = 'Jan-1-2018';
StartDates = ValuationDate;
EndDates = {'Jan-1-2019'; 'Jan-1-2020'; 'Jan-1-2021'; 'Jan-1-2022'};
Compounding = 1;
RateSpec = intenvset('ValuationDate', ValuationDate, 'StartDates',...
StartDates, 'EndDates', EndDates, 'Rates', Rates, 'Compounding', Compounding);

% Build a BDT tree and assume a volatility of 5%.

Sigma = 0.05;  
BDTTimeSpec = bdttimespec(ValuationDate, EndDates);
BDTVolSpec = bdtvolspec(ValuationDate, EndDates, Sigma*ones(1, length(EndDates))');
BDTT = bdttree(BDTVolSpec, RateSpec, BDTTimeSpec);

% Define the callable bond.

CouponRate = 0.05;
Settle = 'Jan-1-2018';
Maturity =  'Jan-1-2021';
Period = 1;
    
    Face = { 
                 {'Jan-1-2019'  100; 
                  'Jan-1-2020'   70; ...
                   'Jan-1-2021'   50};
                 };
 
OptSpec = 'call'; 
Strike = [97 95 93];
ExerciseDates ={'Jan-1-2019' 'Jan-1-2020' 'Jan-1-2021'};

% Compute the OAS for a callable amortizing bond using the BDT tree.

Price = 99;
BondType = 'amortizing';
OAS = oasbybdt(BDTT, Price, CouponRate, Settle, Maturity,...
OptSpec, Strike, ExerciseDates, 'Period', Period, 'Face', Face,'BondType', BondType)

% Copyright 2019 The MathWorks, Inc.