%% Compute OAS and OAD Using the Hull-White (HW) Model
% This example shows how to compute OAS and OAD using the Hull-White (HW) model using the following data.

ValuationDate = 'October-25-2010';
Rates = [0.0355; 0.0382; 0.0427; 0.0489];
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 VolsSpec and TimeSpec
Sigma = 0.05;
Alpha = 0.01;
VS = hwvolspec(ValuationDate, EndDates, Sigma*ones(size(EndDates)),...
EndDates, Alpha*ones(size(EndDates)));
TS = hwtimespec(ValuationDate, EndDates, Compounding);

% build the HW tree
HWTree = hwtree(VS, RateSpec, TS);

% instrument information
CouponRate = 0.045;
Settle = ValuationDate;
Maturity = '25-October-2014';
OptSpec = 'call';
Strike = 100;
ExerciseDates = {'25-October-2010','25-October-2013'};
Period = 1;
AmericanOpt = 0;
Price = 97;

% compute the OAS
[OAS, OAD] = oasbyhw(HWTree, Price, CouponRate, Settle, Maturity,...
OptSpec, Strike, ExerciseDates, 'Period', Period, 'AmericanOpt', AmericanOpt)

% Copyright 2012 The MathWorks, Inc.