%% Compute the OAS to Measure Cost of an Embedded Option Relative to a Risk-Free Curve
% This example shows how to compute the price of a callable bond using a Hull-White tree.
% Use the following bond data:

Settle = datenum('20-Aug-2014');

% Bond Properties
Maturity = datenum('01-Apr-2034');
CouponRate = .0625;
CallDates = datemnth('01-Oct-2014',6*(0:19));
CallStrikes = [102.85 102.7 102.55 102.4 102.25 102.1 101.95 101.8 ...
    101.65 101.5 101.35 101.2 101.05 100.9 100.75 100.6 100.45 100.3 ...
    100.15 100];

%
% Use the following zero-curve data:

CurveDates = datemnth(Settle,12*[1 2 3 5 7 10 20 30]');
ZeroRates = [.11 0.30 0.64 1.44 2.07 2.61 3.29 3.55]'/100;

%
% Define the RateSpec and build the HW tree.

RateSpec = intenvset('StartDate',Settle,'EndDates',CurveDates,'Rates',ZeroRates);

% HW Model Properties
alpha = .1;
sigma = .01;

TimeSpec = hwtimespec(Settle,cfdates(Settle,Maturity,12),2);
VolSpec = hwvolspec(Settle,Maturity,sigma,Maturity,alpha);

HWTree = hwtree(VolSpec,RateSpec,TimeSpec,'method','HW2000')

%
% Compute the OAS for the bond.

Price = 103.25;
OAS = oasbyhw(HWTree, Price, CouponRate, Settle, Maturity, 'call', CallStrikes, CallDates)

% If you want to compute an OAS that only measures the option cost, you can pass in an issuer-specific curve instead of a risk-free curve (this would be done in the RateSpec argument).
% Copyright 2012 The MathWorks, Inc.