%% Compute the Zero Discount Margin Using a Yield Curve
% Use floatdiscmargin to compute the discount margin and zero discount margin for a floating-rate note.
% Define data for the floating-rate note.

Price = 99.99;
Spread = 50;
Settle = '20-Jan-2011';
Maturity = '15-Jan-2012';
LatestFloatingRate = 0.05;
StubRate = 0.049;
SpotRate = 0.05;
Reset = 4;
Basis = 2;

%
% Compute the discount margin.

dMargin = floatdiscmargin(Price, Spread, Settle, Maturity, ...
[StubRate, SpotRate], LatestFloatingRate,'Reset', Reset, 'Basis', Basis, ...
'AdjustCashFlowsBasis', true)

% Usually you want to set AdjustCashFlowsBasis to true, so cash flows are calculated with adjustments on accrual amounts.
%
% Create an annualized zero-rate term structure to calculate the zero discount margin.

Rates = [0.0500;
         0.0505;
         0.0510;
         0.0520];
StartDates = ['20-Jan-2011';
              '15-Apr-2011';
              '15-Jul-2011';
              '15-Oct-2011'];
EndDates =   ['15-Apr-2011';
              '15-Jul-2011';
              '15-Oct-2011';
              '15-Jan-2012'];
ValuationDate = '20-Jan-2011';
RateSpec = intenvset('Compounding', Reset, 'Rates', Rates,...
'StartDates', StartDates, 'EndDates', EndDates,...
'ValuationDate', ValuationDate, 'Basis', Basis);

%
% Calculate the zero discount margin using the previous yield curve.

dMargin = floatdiscmargin(Price, Spread, Settle, Maturity, ...
RateSpec, LatestFloatingRate,'Reset', Reset, 'Basis', Basis, ...
'AdjustCashFlowsBasis', true)

% Copyright 2015 The MathWorks, Inc.