%% Price a Range Floating-Rate Note Using a CIR Interest-Rate Tree
% Create a RateSpec using the intenvset function.

Rates = [0.035; 0.042147; 0.047345; 0.052707]; 
Dates = {'Jan-1-2017'; 'Jan-1-2018'; 'Jan-1-2019'; 'Jan-1-2020'; 'Jan-1-2021'}; 
ValuationDate = 'Jan-1-2017'; 
EndDates = Dates(2:end)'; 
Compounding = 1; 
RateSpec = intenvset('ValuationDate', ValuationDate, 'StartDates', ValuationDate, 'EndDates',EndDates,'Rates', Rates, 'Compounding', Compounding); 

% Create a CIR tree.

NumPeriods = length(EndDates); 
Alpha = 0.03; 
Theta = 0.02;  
Sigma = 0.1;   
Settle = '01-Jan-2017'; 
Maturity = '01-Jan-2020'; 
CIRTimeSpec = cirtimespec(Settle, Maturity, 3); 
CIRVolSpec = cirvolspec(Sigma, Alpha, Theta); 

CIRT = cirtree(CIRVolSpec, RateSpec, CIRTimeSpec)

% Define the range note instrument that matures in Jan-1-2014 and has the following RateSchedule:

Spread = 100;
Settle = 'Jan-1-2017';
Maturity = 'Jan-1-2020';
RateSched(1).Dates = {'Jan-1-2018'; 'Jan-1-2019'  ; 'Jan-1-2020'};
RateSched(1).Rates = [0.045 0.055 ; 0.0525  0.0675; 0.06 0.08];

% Compute the price of the range floating note.

[Price,PriceTree] = rangefloatbycir(CIRT,Spread,Settle,Maturity,RateSched)

% Copyright 2012 The MathWorks, Inc.