%% Price a Vanilla Bond Using the Optional Input Argument AdjustCashFlowsBasis
% To adjust the cash flows according to the accrual amount, use the optional input argument AdjustCashFlowsBasis when calling bondbyzero.
% Use the following data to define the interest-rate term structure and to create a RateSpec.

Rates = 0.065;
ValuationDate = '1-Jan-2011';
StartDates = ValuationDate;
EndDates=  '1-Jan-2017';
Compounding = 1;
RateSpec = intenvset('ValuationDate',ValuationDate,'StartDates',StartDates,...
'EndDates', EndDates,'Rates',Rates,'Compounding',Compounding);
CouponRate = 0.07;
Settle ='1-Jan-2011';
Maturity = '1-Jan-2017';
Period = 1;
Face = {{'1-Jan-2015' 100;'1-Jan-2016' 90;'1-Jan-2017' 80}};

%
% Use cfamounts and cycle through the Basis of 0 to 13, using the optional argument AdjustCashFlowsBasis to determine the cash flow amounts for accrued interest due at settlement.

AdjustCashFlowsBasis = true;
CFlowAmounts =  cfamounts(CouponRate,Settle,Maturity,'Period',Period,'Basis',0:13,'AdjustCashFlowsBasis',AdjustCashFlowsBasis)

% Notice that the cash flow amounts have been adjusted according to Basis.
%
% Price a vanilla bond using the input argument AdjustCashFlowsBasis.

PriceVanilla = bondbyzero(RateSpec,CouponRate,Settle,Maturity,'Period',Period,'Basis',0:13,'AdjustCashFlowsBasis',AdjustCashFlowsBasis)

% Copyright 2012 The MathWorks, Inc.