[R] Yield to maturity calculation - bndyield equivalent of MATLAB in R
Tunga Kantarcı
tungakantarci at gmail.com
Wed Apr 5 15:00:20 CEST 2017
I have the MATLAB code pasted below that calculates yields to maturity.
IRR = zeros(length(c),length(M))
The ith row and jth column is the price of the bond with coupon c(i)
and maturity M(j).
for i = 1:3
for j = 1:3
if j == 1
IRR(i,j) =
bndyield(mPricecon(i,j),c_org(i),'07-Apr-2016','07-Apr-2026');
elseif j == 2
IRR(i,j) =
bndyield(mPricecon(i,j),c_org(i),'07-Apr-2016','07-Apr-2036');
elseif j == 3
IRR(i,j) =
bndyield(mPricecon(i,j),c_org(i),'07-Apr-2016','07-Apr-2046');
end
end
end;
mPricecon represents the prices calculated from zero coupon bond
prices, and c_org represents the coupon payments. This then gives IRR.
I need to convert this MATLAB code to R code, and ideally one to one.
The problem is that bndyield is a MATLAB function and there does not
seem be an exact equivalent in R. What is the best way to go?
More information about the R-help
mailing list