Hello Everyone, I've got quite a fix calibrating alpha and sigma for swaptions using matlab and I was wondering if anyone could give me a hand. I've actually finished my coding, but I'm still getting negative results for alpha.....Not sure if my constraints were optimal enough....Would appreciate your inputs. Please find my matlab code below. Thanks
Code:
% hull-white calibration with swaption following equation (24) in Fabien's
% short rate interest rate models in the HJM framework: models, calibration
% and MC simulations
clear all
clc
yield_time=[1,3,6,12,24,36,48,60,84,120,180,240,360]/12;
yield=[0.2953,0.5810,0.8085,1.1280,0.7460,0.8275,1.010133,1.2270,1.6501,2.0340,2.4132,2.5326,2.6290]/100;
swaption_maturity=[6,12,24,36,48]/12;
swaption_vol1=[50.05,53.95,70.95,89.40,101.50]/100;
swaption_vol2=[49.65,54.35,74.80,94.50,103.85]/100;
swaption_vol3=[54.10,60.50,82.45,97.65,103.95]/100;
swaption_vol4=[61.40,70.60,88.40,99.60,104.50]/100;
swaption_matrix=[swaption_maturity',swaption_vol1',swaption_vol2',swaption_vol3',swaption_vol4'];
swap_maturity=[1,2,3,4];
[alpha,sigma]=hw_calibration(yield_time,yield,swaption_matrix,...
swap_maturity)
y=0;
for ni=2:size(swaption_matrix,2)
figure
for nj=1:size(swaption_matrix,1)
sigma_black(nj)=get_sigma_black(alpha,sigma,...
swaption_matrix(nj,1),swap_maturity(ni-1),...
yield_time,yield);
y=y+(sigma_black(nj)-swaption_matrix(nj,ni))*...
(sigma_black(nj)-swaption_matrix(nj,ni));
end % end of nj
plot(swaption_maturity,sigma_black)
hold on
plot(swaption_maturity,swaption_matrix(:,ni),'*')
xlabel('Swaption maturity')
ylabel('Swaption volatility')
legend('Calibrated volatility','Market volatility')
axis([0,10,0.1,1])
end % end of ni
function [alpha,sigma]=hw_calibration(yield_time,yield,swaption_matrix,...
swap_maturity)
% 1 jun 2010
% called by main.m to calibrate hull-white model
x0(1)=0.0218;
x0(2)=0.01;
[xmin,ymin]=fmincon(@sigma_diff,x0,[],[],[],[],[-1,0],[1,1]);
alpha=xmin(1);
sigma=xmin(2);
function y=sigma_diff(x)
y=0;
for ni=2:size(swaption_matrix,2)
for nj=1:size(swaption_matrix,1)
sigma_black=get_sigma_black(x(1),x(2),...
swaption_matrix(nj,1),swap_maturity(ni-1),...
yield_time,yield);
y=y+(sigma_black-swaption_matrix(nj,ni))*...
(sigma_black-swaption_matrix(nj,ni));
end % end of nj
end % end of ni
end % end of function sigma_diff
end % end of function hw_calibration
function sigma_black=get_sigma_black(alpha,sigma,swaption_maturity,...
swap_maturity,yield_time,yield)
% called by hw_calibration.m to calcualte A and B
% A is a number and B is a vector of size n
theta=0.5;
n=swap_maturity*2;
paytime=(1:n)*theta+swaption_maturity;
yield_i=spline(yield_time,yield,paytime);
B=exp(-yield_i.*paytime);
A=sum(B);
omega=B/A;
omega=omega.*(1-exp(-alpha*theta*(1:n)));
sum_term=sum(omega);
B0=exp(-spline(yield_time,yield,swaption_maturity)*swaption_maturity);
omega_p=B(n)/(B0-B(n));
omega_p=omega_p*(1-exp(-alpha*n*theta));
sigma_black2=sigma*sigma/alpha/alpha*(sum_term+omega_p)*...
(sum_term+omega_p)*(1-exp(-2*alpha*swaption_maturity))...
/2/alpha/swaption_maturity;
sigma_black=sqrt(sigma_black2);