%% Create a RateSpec to Price Multi-Stepped Coupon Bonds
% Price the following multi-stepped coupon bonds using the following data:

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

% Create RateSpec using intenvset
RS = intenvset('ValuationDate', ValuationDate, 'StartDates', StartDates,...
'EndDates', EndDates,'Rates', Rates, 'Compounding', Compounding);

% Create a portfolio of stepped coupon bonds with different maturities
Settle = '01-Jan-2010';
Maturity = {'01-Jan-2011';'01-Jan-2012';'01-Jan-2013';'01-Jan-2014'};
CouponRate = {{'01-Jan-2011' .042;'01-Jan-2012' .05; '01-Jan-2013' .06; '01-Jan-2014' .07}};

% Display the instrument portfolio 
ISet = instbond(CouponRate, Settle, Maturity, 1);
instdisp(ISet)

%
% Build a BDTTree to price the stepped coupon bonds. Assume the volatility to be 10%

Sigma = 0.1; 
BDTTimeSpec = bdttimespec(ValuationDate, EndDates, Compounding);
BDTVolSpec = bdtvolspec(ValuationDate, EndDates, Sigma*ones(1, length(EndDates))');
BDTT = bdttree(BDTVolSpec, RS, BDTTimeSpec);

% Compute the price of the stepped coupon bonds
PBDT = bdtprice(BDTT, ISet)

% Copyright 2015 The MathWorks, Inc.