Code covered by the BSD License

Hazard Rate Bootstrapping

Vilen Abramov (view profile)

This file bootstraps hazard rates from a series of 1/3/5/7/10-year par spreads.

hazard
function[hazard] = hazard
%% Intro
% This file bootstraps hazard rates from a series of
% Par spreads and Libor rates are defined in the input file input.xls.
% The recovery rate is assumed to be 40% and can be changed in Step 5
%% Step 1 - Import the libor data from the spreadsheet input.xls
% The Libor data is as of 06-29-2012
% Import the libor data
[~, ~, raw] = xlsread('C:\Documents and Settings\abramvi\Desktop\CDS\MatLab\input.xls','libor');
raw = raw(2:end,:);

% Create output variable
data = cell2mat(raw);

% Allocate imported array to column variable names
libornodes = data(:,1)./365;
libor = data(:,2);

% Clear temporary variables
clearvars data raw columnIndices;
%% Step 2 - Interpolate libor data linearly
t=[90/360:90/360:10];
liborinterp=interp1(libornodes, libor, t, 'linear', 'extrap');
%% Step 3 - Calculate discount factors corresponding to each date
% We use annual compounding
n=length(t);
for j=1:n
DF(j)=(1+liborinterp(j))^(-t(j));
end
%% Step 4 - Import par spread data from the spreadsheet input.xls
% Import the par data
[~, ~, raw] = xlsread('C:\Documents and Settings\abramvi\Desktop\CDS\MatLab\input.xls','par');
raw = raw(2:end,:);

% Create output variable
data = cell2mat(raw);

% Allocate imported array to column variable names
parnodes = data(:,1)./360;
par = data(:,2);

% Clear temporary variables
clearvars data raw columnIndices;
%% Step 5 - Define recovery rate
R=.40;
%% Step 6 - Solve for the 1-year lambda
% Define X(j)=\exp^{-t_{j}} and Y(j)=\exp^{-t(j-1)}
for j=1:40
X(j)=exp(-j/4);
Y(j)=exp(-(j-1)/4);
end
% Find 1Y hazard rate
DF1=DF(1:4);
X1=X(1:4);
Y1=Y(1:4);
gf = @(l)(abs(...
((1-R)*DF1*transpose(-X1.^l+Y1.^l))...
-par(1)*...
(DF1*transpose((1/4)*(X1.^l)))...
));
% One can use various numerical procedures to solve for \lambda
% We will be searching for the \lambda on the interval [0,5*par(3)]
% using fminbnd function
bnd=5*par(3);
lambda(1) = fminbnd(gf,0,bnd);
%% Step 7 - Solve for the 3-year lambda
DF3=DF(5:12);
X3=X(5:12);
Y3=Y(5:12);
Numer1=(1-R)*DF1*transpose(-X1.^lambda(1)+Y1.^lambda(1));
Denom1=DF1*transpose((1/4)*(X1.^lambda(1)));
gf = @(l)(abs(...
(Numer1+(1-R)*DF3*transpose(-X3.^l+Y3.^l))...
-par(2)*...
(Denom1+DF3*transpose((1/4)*(X3.^l)))...
));
lambda(2) = fminbnd(gf,0,bnd);
%% Step 8 - Solve for the 5-year lambda
DF5=DF(13:20);
X5=X(13:20);
Y5=Y(13:20);
Numer3=Numer1+(1-R)*DF3*transpose(-X3.^lambda(2)+Y3.^lambda(2));
Denom3=Denom1+DF3*transpose((1/4)*(X3.^lambda(2)));
gf = @(l)(abs(...
(Numer3+(1-R)*DF5*transpose(-X5.^l+Y5.^l))...
-par(3)*...
(Denom3+DF5*transpose((1/4)*(X5.^l)))...
));
lambda(3) = fminbnd(gf,0,bnd);
%% Step 9 - Solve for the 7-year lambda
DF7=DF(21:28);
X7=X(21:28);
Y7=Y(21:28);
Numer5=Numer3+(1-R)*DF5*transpose(-X5.^lambda(3)+Y5.^lambda(3));
Denom5=Denom3+DF5*transpose((1/4)*(X5.^lambda(3)));
gf = @(l)(abs(...
(Numer5+(1-R)*DF7*transpose(-X7.^l+Y7.^l))...
-par(4)*...
(Denom5+DF7*transpose((1/4)*(X7.^l)))...
));
lambda(4) = fminbnd(gf,0,bnd);
%% Step 10 - Solve for the 10-year lambda
DF10=DF(29:40);
X10=X(29:40);
Y10=Y(29:40);
Numer7=Numer5+(1-R)*DF7*transpose(-X7.^lambda(4)+Y7.^lambda(4));
Denom7=Denom5+DF7*transpose((1/4)*(X7.^lambda(4)));
gf = @(l)(abs(...
(Numer7+(1-R)*DF10*transpose(-X10.^(abs(l))+Y10.^(abs(l))))...
-par(5)*...
(Denom7+DF10*transpose((1/4)*(X10.^(abs(l)))))...
));
lambda(5) = fminbnd(gf,0,bnd);
%% Step 11 - Send hazard rates to Excel
format long
hazard=lambda';
xlswrite('output.xls',hazard);