MATLAB: Do “bndyield” and “cfyield” give different results

Financial Toolbox

I have some code to calculate bond yield ("bndyield"), and I set up very similar code to calculate the same yield using the cash flow yield, "cfyield" function. For some reason, I am getting different results. What might be causing this?

Best Answer

The primary issue here is the treatment of accrued interest. Specifically, "bndyield" accepts a clean price as an input, internally computes the accrued interest and adds that to the clean price to compute a full price before computing the yield to maturity. Therefore, to compare the outputs from the two approaches, the input cash flows to "cfyield" should include the accrued interest as well.