Fill a matrix with a loop Finance application (Bootstrapping)
8 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hello everyone!
I'm struggling with an issue concerning the for cycle. I am not able to use it in a way such that I keep filling up an empty matrix of values that comes from the previous cycle.
I show you the data that I am modelling:
The contest of this code is the computation of Zero Rates (finance application). I should find out a way to compute the zero rates for the longest maturities (given in the %data) using the information on the zero rates.
All bonds have Par Value =100
Maturities only occur every 0.5 (6 months)
%data
Maturity=[1.5,2]; % maturity in years for long maturity bonds (2 bonds)
Coupon=[4,6]; %respectively 4 every 0.5 for the first bond and 6 every 0.5 for the second bond
Price=[96, 100]; %for the long bonds
zerorates=[0.1047,0.1054]'; % which are respectively for Maturity 0,5 and 1 of zero coupon bond
% zerorates vector is also reffered to short rates
rateslong=zeros(length(Maturity),1); % this is the matrix for the long rates that must be updated with the for cycle
RZ=vertcat(zerorates,rateslong);
Matfin=0.5:0.5:Maturity(end); %note that RZ and Matfin should have the same length
%forcyle
for j=1:length(Coupon)
for i=1:(Maturity(j)/0.5)-1
NPVC=Coupon(j)*exp(-RZ(i)*Matfin(i));
% NPCV must compute the sum of the coupons disocunted for the first bond
% in this case for the first Bond would be
% NPVC=Coupon(1,1)*exp(-RZ(1,1)*Matfin(1,1))+Coupon(1,1)*exp(-RZ(2,1)*Matfin(2,1))
sumNPVC = sum(NPVC);
rateslong=-log((Price(j)-sumNPVC/(100+Coupon(j))*1/Maturity(j)));
% in this case for the first bond would be
% rateslong=-log((Price(1,1)-NPVC/100+Coupon(1,1))*1/Maturity(1,1))
% this formula should compute the zero rate that should be added into RZ
% so RZ now has [0.1047, 0.1054, "newzerorate", 0]
% newzerorate analitically computed is 0.1068
% and this new matrix should be the new input for the second bond with coupon 6
% so at NPVC for the second bond would be :
% NPVC=Coupon(1,2)*exp(-RZ(1,1)*Matfin(1,1))+Coupon(1,2)*exp(-RZ(2,1)*Matfin(2,1))+Coupon(1,2)*exp(-RZ(3,1)*Matfin(3,1))
end
end
disp(RZ) %at the end what I care is the complete vector for zero rates RZ
I leave you this command (even though it is wrong) because I think it easily explains what I should find out.
Thanks for any help you are able to provide, I really appreciate it.
1 commentaire
Roofus Milton
le 4 Nov 2019
I believe the concept you are trying to figure out is "bootstrapping" an interest rate curve. You should be able to compute the spot curve from the prices, coupons, and maturities you provided. I would look for examples of converting a spot curve to a zero curve.
rateslong= -log.... is probably missing a reference to j.
Réponses (0)
Voir également
Catégories
En savoir plus sur Financial Toolbox dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!