%% Price a Swap Using a Different Curve to Generate the Cash Flows of the Floating Leg
% 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 swap.

Maturity = datenum('15-Mar-2018'); % Five year swap
FloatSpread = 0;
FixedRate = .025;
LegRate = [FixedRate FloatSpread];

%
% Compute the price of the swap instrument. The LiborCurve term structure will be used to generate the cash flows of the floating leg. The OISCurve term structure will be used for discounting the cash flows.

Price = swapbyzero(OISCurve, LegRate, Settle,...
Maturity,'ProjectionCurve',LiborCurve)

%
% Compare results when the term structure OISCurve is used both for discounting and also generating the cash flows of the floating leg.

PriceSwap = swapbyzero(OISCurve, LegRate, Settle, Maturity)

% Copyright 2015 The MathWorks, Inc.