%% Price a 5-Year Call Swaption Using a BDT Interest-Rate Tree
% This example shows how to price a 5-year call swaption using a BDT interest-rate tree. Assume that interest rate and volatility are fixed at 6% and 20% annually between the valuation date of the tree until its maturity. Build a tree with the following data.

Rates = 0.06 * ones (10,1);      
StartDates = ['jan-1-2007';'jan-1-2008';'jan-1-2009';'jan-1-2010';'jan-1-2011';...
'jan-1-2012';'jan-1-2013';'jan-1-2014';'jan-1-2015';'jan-1-2016'];    

EndDates =['jan-1-2008';'jan-1-2009';'jan-1-2010';'jan-1-2011';'jan-1-2012';...
'jan-1-2013';'jan-1-2014';'jan-1-2015';'jan-1-2016';'jan-1-2017'];
ValuationDate = 'jan-1-2007'; 
Compounding = 1; 

% define the RateSpec
RateSpec = intenvset('Rates', Rates, 'StartDates', StartDates, 'EndDates', EndDates, ...
'Compounding', Compounding);

% use VolSpec to compute interest-rate volatility
Volatility = 0.20 * ones (10,1);  VolSpec = bdtvolspec(ValuationDate,...
EndDates, Volatility);

% use TimeSpec to specify the structure of the time layout for a BDT tree
TimeSpec = bdttimespec(ValuationDate, EndDates, Compounding);

% build the BDT tree
BDTTree = bdttree(VolSpec, RateSpec, TimeSpec); 

% use the following swaption arguments
ExerciseDates = 'jan-1-2012';
SwapSettlement = ExerciseDates;
SwapMaturity   = 'jan-1-2015'; 
Spread = 0;
SwapReset = 1; 
Principal = 100;
OptSpec = 'call';
Strike=.062;
Basis=1;

% price the swaption
[Price, PriceTree] = swaptionbybdt(BDTTree, OptSpec, Strike, ExerciseDates, ...
Spread, SwapSettlement, SwapMaturity, 'SwapReset', SwapReset, ...
'Basis', Basis, 'Principal', Principal)

% Copyright 2015 The MathWorks, Inc.