%% Compute the Price of a Range Note Using a Black-Karasinski Tree
% This example shows how to compute the price of a range note using a Black-Karasinski tree with the following interest-rate term structure data.

Rates = [0.035; 0.042147; 0.047345; 0.052707];
ValuationDate = 'Jan-1-2011';
StartDates = ValuationDate;
EndDates = {'Jan-1-2012'; 'Jan-1-2013'; 'Jan-1-2014'; 'Jan-1-2015'};
Compounding = 1;

% define RateSpec
RS = intenvset('ValuationDate', ValuationDate, 'StartDates', StartDates,...
'EndDates', EndDates, 'Rates', Rates, 'Compounding', Compounding);
                       
% range note instrument matures in Jan-1-2014 and has the following RateSchedule:
Spread = 100;
Settle = 'Jan-1-2011';
Maturity = 'Jan-1-2014';
RateSched(1).Dates = {'Jan-1-2012'; 'Jan-1-2013'  ; 'Jan-1-2014'};
RateSched(1).Rates = [0.045 0.055 ; 0.0525  0.0675; 0.06 0.08];

% data to build the tree is as follows:
VolDates = ['1-Jan-2012'; '1-Jan-2013'; '1-Jan-2014';'1-Jan-2015'];
VolCurve = 0.01;
AlphaDates = '01-01-2015';
AlphaCurve = 0.1;

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

% price the instrument 
Price = rangefloatbybk(BKT, Spread, Settle, Maturity, RateSched)

% Copyright 2015 The MathWorks, Inc.