%% Create a BKTree
% Using the data provided, create a BK volatility specification (using bkvolspec), rate specification (using intenvset), and tree time layout specification (using bktimespec). Then use these specifications to create a BK tree using bktree.

Compounding = -1;
ValuationDate = '01-01-2004';
StartDate = ValuationDate;
VolDates = ['12-31-2004'; '12-31-2005'; '12-31-2006'; 
'12-31-2007'];
VolCurve = 0.01;
AlphaDates = '01-01-2008';
AlphaCurve = 0.1;
Rates = [0.0275; 0.0312; 0.0363; 0.0415];

BKVolSpec = bkvolspec(ValuationDate, VolDates, VolCurve,...  
AlphaDates, AlphaCurve);

RateSpec = intenvset('Compounding', Compounding,...
		     'ValuationDate', ValuationDate,...
		     'StartDates', ValuationDate,...
		     'EndDates', VolDates,...
		     'Rates', Rates);
 
BKTimeSpec = bktimespec(ValuationDate, VolDates, Compounding);

BKTree = bktree(BKVolSpec, RateSpec, BKTimeSpec)

% Use treeviewer to observe the tree you have created.

treeviewer(BKTree)

% Copyright 2018 The MathWorks, Inc.