%% Compute OAS Using the Heath-Jarrow-Morton (HJM) Model
% This example shows how to compute OAS using the Heath-Jarrow-Morton (HJM) model using the following data.

ValuationDate = 'Nov-1-2010';
Rates = [0.0356; 0.0427; 0.0478; 0.0529];
StartDates = ValuationDate;
EndDates = datemnth(ValuationDate, 12:12:48)';
Compounding = 1;
 
% define RateSpec
RateSpec = intenvset('ValuationDate', ValuationDate,...
'StartDates', StartDates,'EndDates', EndDates, ...
'Rates', Rates,'Compounding', Compounding); 
 
% specify VolSpec and TimeSpec
Sigma = 0.02;
VS = hjmvolspec('Constant', Sigma);
TS = hjmtimespec(ValuationDate, EndDates, Compounding);
 
% build the HJM tree
HJMTree = hjmtree(VS, RateSpec, TS);
HJMTreenew = cvtree(HJMTree);
 
% instrument information
CouponRate = 0.05;
Settle = ValuationDate;
Maturity = '01-Nov-2014';
OptSpec = 'call';
Strike = 100;
ExerciseDates ='01-Nov-2011';
Period = 1;
Price = 97.5;

% compute the OAS
OAS = oasbyhjm(HJMTree, Price, CouponRate, Settle, Maturity, OptSpec, Strike,...
ExerciseDates, 'Period', Period)

% Copyright 2012 The MathWorks, Inc.