%% Price a Floating-Rate Note Using a Different Curve to Generate Floating Cash Flows
% Define the OIS and Libor rates.

Settle = datenum('15-Mar-2013');
CurveDates = daysadd(Settle,360*[1/12 2/12 3/12 6/12 1 2 3 4 5 7 10],1);
OISRates = [.0018 .0019 .0021 .0023 .0031 .006  .011 .017 .021 .026 .03]';
LiborRates = [.0045 .0047 .005 .0055 .0075 .011 .016 .022 .026 .030 .0348]';

%
% Plot the dual curves.

figure,plot(CurveDates,OISRates,'r');hold on;plot(CurveDates,LiborRates,'b')
datetick
legend({'OIS Curve', 'Libor Curve'})

%
% Create an associated RateSpec for the OIS and Libor curves.

OISCurve = intenvset('Rates',OISRates,'StartDate',Settle,'EndDates',CurveDates);
LiborCurve = intenvset('Rates',LiborRates,'StartDate',Settle,'EndDates',CurveDates);

%
% Define the floating-rate note.

Maturity = datenum('15-Mar-2018');

%
% Compute the price for the floating-rate note. The LiborCurve term structure will be used to generate the floating cash flows of the floater instrument. The OISCurve term structure will be used for discounting the cash flows.

Price = floatbyzero(OISCurve,0,Settle,Maturity,'ProjectionCurve',LiborCurve)

% Some instruments require using different interest-rate curves for generating the floating cash flows and discounting. This is when the ProjectionCurve parameter is useful. When you provide both RateSpec and ProjectionCurve, floatbyzero uses the RateSpec for the purpose of discounting and it uses the ProjectionCurve for generating the floating cash flows.
% Copyright 2012 The MathWorks, Inc.