clear all; clc; close all;
% 1) Building a bootstrapped spot curve from downloaded CNNFN data on Treasury Notes and Bonds.
[A, B] = xlsread('bonddata.xls');
Bonds = [datenum(A(:,4))+693960 A(:,3)/100 100*ones(length(A(:,3)),1) 2*ones(length(A(:,3)),1) 2*ones(length(A(:,3)),1) 0*ones(length(A(:,3)),1)];
Prices = A(:,6);
Settle = datenum('04-Sep-2002');
OutputCompoundingZERO = 2;
OutputCompoundingFWD = 2;
warning off MATLAB:break_outside_of_loop
[ZeroRates, CurveDates, FWDRates, DISCRates] = zbtprice(Bonds, Prices, Settle, OutputCompoundingZERO, OutputCompoundingFWD);
pause;
% 2) A use of spline to get a "smooth" forward curve
Smoothing = 0.95;
BreakDates = round(linspace(datenum(Settle), max(datenum(A(:,4))+693960), 30));
[ZeroRates, CurveDates, BootZeros, BootDates, BreakDates] = ...
termfit(Smoothing, Bonds, Prices, Settle, OutputCompoundingZERO, 1, CurveDates, BreakDates');
figure;
fwdratesplined = zero2fwd(ZeroRates,CurveDates,Settle);
plot(CurveDates, FWDRates, 'ro-', CurveDates, fwdratesplined, 'b-'); grid;
title('Calculated Forward Curve')
ylabel('Rate');
xlabel('Maturity in Serial date')
legend('Bootstrapped', 'Fitted')
% 3) Further illustration, using MOVIE to visualize effects of smoothing parameters.
pause;
% for i = 1:20
% Smoothing = 0.05*(i-1);
% [ZeroRates, CurveDates, BootZeros, BootDates, BreakDates] = ...
% termfit(Smoothing, Bonds, Prices, Settle, OutputCompoundingZERO, 1, CurveDates, BreakDates');
% fwdratesplined = zero2fwd(ZeroRates,CurveDates,Settle);
% plot(CurveDates, fwdratesplined*100);
% xlim([7.31e5 7.42e5]);
% ylim([-2 8]);
% legend(['Smoothing Factor = ', num2str(Smoothing)]);
% xlabel('Serial Date Beginning on Settle');
% ylabel('Forward Rate [%]');
% grid on;
% F(i) = getframe;
% %close gcf - XP related bug needs this line;
% end
load splinemovie
movie(F,-1)
pause;
% 4) A further use of the bootstrapped spot curve to obtain term structure of spread, for...
% WALT DISNEY's bonds! The benchmark was the non-smoothed spotcurve.
[C D] = XLSREAD('disneybond.xls');
BondsWD = [datenum(C(:,2))+693960 C(:,1)/100 100*ones(length(C(:,3)),1) 2*ones(length(C(:,3)),1) 2*ones(length(C(:,3)),1) 0*ones(length(C(:,3)),1)];
Prices = C(:,3);
Settle = datenum('09-Sep-2002');
% Snuff out some of data less than 3 months, seem like noise to me ...
idx = find(BootZeros > 0.015);
BootZeros = BootZeros(idx);
ZeroRates = ZeroRates(idx);
CurveDates = CurveDates(idx);
ZeroMatrix = [CurveDates, BootZeros, 2*ones(length(CurveDates),1)];
CouponRate = BondsWD(:,2);
Maturity = BondsWD(:,1);
Period = BondsWD(:,4);
Basis = BondsWD(:,5);
EndMonthRule = BondsWD(:,6);
staticspread_nsmooth = bondprice2spread(ZeroMatrix, Prices, CouponRate, Settle, Maturity, ...
Period, Basis, EndMonthRule);
ZeroMatrix = [CurveDates, ZeroRates, 2*ones(length(CurveDates),1)];
staticspread_smooth = bondprice2spread(ZeroMatrix, Prices, CouponRate, Settle, Maturity, ...
Period, Basis, EndMonthRule);
figure;
plot(Maturity, staticspread_nsmooth,'ob-', Maturity, staticspread_smooth, 'dr-');
title('Calculated static spread of Disney noncallable bonds to treasury on 09/09/2002')
ylabel('bp');
xlabel('Maturity in Serial date')
legend('to bootstrapped', 'to fitted')
grid;