%% Price an Amortizing Swap
% Price an amortizing swap using the Principal input argument to define the amortization schedule.
% Create the RateSpec.

Rates = 0.035;
ValuationDate = '1-Jan-2011';
StartDates = ValuationDate;
EndDates = '1-Jan-2017';
Compounding = 1;

RateSpec = intenvset('ValuationDate', ValuationDate,'StartDates', StartDates,...
'EndDates', EndDates,'Rates', Rates, 'Compounding', Compounding);

%
% Create the swap instrument using the following data:

Settle ='1-Jan-2011';
Maturity = '1-Jan-2017';
LegRate = [0.04 10];

%
% Define the swap amortizing schedule.

Principal ={{'1-Jan-2013' 100;'1-Jan-2014' 80;'1-Jan-2015' 60;'1-Jan-2016' 40; '1-Jan-2017' 20}};

%
% Compute the price of the amortizing swap.

Price = swapbyzero(RateSpec, LegRate, Settle, Maturity, 'Principal' , Principal)

% Copyright 2015 The MathWorks, Inc.