%% Price a 1-Year Call Swaption with Receiving and Paying Legs Using an HJM Interest-Rate Tree
% This example shows how to price a 1-year call swaption with receiving and paying legs using an HJM interest-rate tree. Assume that interest rate is fixed at 5% annually between the valuation date of the tree until its maturity. Build a tree with the following data.

Rates = [ 0.05;0.05;0.05;0.05];  
StartDates = 'jan-1-2007';  
EndDates =['jan-1-2008';'jan-1-2009';'jan-1-2010';'jan-1-2011'];
ValuationDate = StartDates;  
Compounding = 1;

%
% Define the RateSpec.

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

%
% Use VolSpec to compute the interest-rate volatility.

VolSpec=hjmvolspec('Constant',0.01);

%
% Use TimeSpec to specify the structure of the time layout for the HJM interest-rate tree.

TimeSpec = hjmtimespec(ValuationDate,EndDates,Compounding);

%
% Build the HJM tree.

HJMTree = hjmtree(VolSpec,RateSpec,TimeSpec);

%
% Use the following swaption arguments

ExerciseDates = '01-Jan-2008';
SwapSettlement = ExerciseDates;
SwapMaturity   = 'jan-1-2010';
Spread = [0];  
SwapReset = [1 1];  % 1st column represents receiving leg, 2nd column represents paying leg  
Basis  = [1 3];     % 1st column represents receiving leg, 2nd column represents paying leg 
Principal = 100;  
OptSpec = 'call';    
Strike=0.05;

%
% Price the swaption.

[Price, PriceTree] = swaptionbyhjm(HJMTree,OptSpec,Strike,ExerciseDates, ...
Spread,SwapSettlement,SwapMaturity,'SwapReset',SwapReset, ...
'Basis',Basis,'Principal',Principal)

% Copyright 2012 The MathWorks, Inc.