www.gusucode.com > fininst 案例源码程序 matlab代码 > fininst/PriceanAmortizingSwapExample.m

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

% Copyright 2015 The MathWorks, Inc.


%% 
% 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';
Period = 1;
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}};  

%% 
% Build the BK tree and assume volatility is 10%. 
MatDates = {'1-Jan-2012'; '1-Jan-2013';'1-Jan-2014';'1-Jan-2015';'1-Jan-2016';'1-Jan-2017'};
BKTimeSpec = bktimespec(ValuationDate, MatDates);
Volatility = 0.10;  
AlphaDates = '01-01-2017';
AlphaCurve = 0.1;
BKVolSpec = bkvolspec(ValuationDate, MatDates, Volatility*ones(1,length(MatDates))',...
AlphaDates, AlphaCurve);
BKT = bktree(BKVolSpec, RateSpec, BKTimeSpec);  

%% 
% Compute the price of the amortizing swap. 
Price = swapbybk(BKT, LegRate, Settle, Maturity, 'Principal' , Principal)