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

    %% Price an Interest-Rate Swap  
% Price an interest-rate swap with a fixed receiving leg and a floating
% paying leg. Payments are made once a year, and the notional principal
% amount is $100. The values for the remaining arguments are: 
%  
% * Coupon rate for fixed leg: 0.06 (6%)   
% * Spread for floating leg: 20 basis points   
% * Swap settlement date: Jan. 01, 2005  
% * Swap maturity date: Jan. 01, 2008      

% Copyright 2015 The MathWorks, Inc.


%% 
% Based on the information above, set the required arguments and build the
% |LegRate|, |LegType|, and |LegReset| matrices: 
Settle = '01-Jan-2005';
Maturity = '01-Jan-2008';
Basis = 0; 
Principal = 100;
LegRate = [0.06 20]; % [CouponRate Spread] 
LegType = [1 0]; % [Fixed Float] 
LegReset = [1 1]; % Payments once per year   

%% 
% Price the swap using the |HWTree| included in the MAT-file |deriv.mat|.
% The |HWTree| structure contains the time and forward-rate information
% needed to price the instrument.  
load deriv.mat;   

%% 
% Use |swapbyhw| to compute the price of the swap. 
[Price, PriceTree, SwapRate] = swapbyhw(HWTree, LegRate, ... 
Settle, Maturity, LegReset, Basis, Principal, LegType)   

%% 
% Using the previous data, calculate the swap rate, which is the coupon
% rate for the fixed leg, such that the swap price at time = 0 is zero. 
LegRate = [NaN 20]; 

[Price, PriceTree, SwapRate] = swapbyhw(HWTree, LegRate, ... 
Settle, Maturity, LegReset, Basis, Principal, LegType)