Posted by
Toyin Akin on
URL: http://quantlib.414.s1.nabble.com/Problem-within-the-Bond-YieldSolver-class-tp4278.html
Hi,
Okay, after playing around a bit within the Bond classes, there can be
situations where the implied Yield will not reprice the bond exactly
(yield() function of the Bond class). This is because there is a minor
difference between the implementation between the computation of the dirty
price within the YieldSolver (dirtyPriceFromYield() function) and the
performCalculation class of the Bond class.
Basically it's the way accrual periods are computed when the datedDate is
before the SettleDate
for the first cashflow.
Within the dirtyPriceFromYield() function, for the first cashflow period,
the call eventually ends up calling yearFraction, passing all four date
parameters (ie - does not default the last 2 date parameters).
However within the performCalculation() function of the Bond class, within
the call to discount(), the yearfraction is computed in a similar way to the
yearFraction function, but without the use of the last 2 date parameters.
Thus the coverage computed, especially in the presence of accrual periods
are different.
In my local copy, I thought about changing the code within the
performCalculation() function so that for the first accrual period, I
compute a 'Time' variable instead of using the 'Date' variable and then
passing this to the discount() function. The Time variable would have been
produced using all four date parameters of the yearFraction() function,
however this does not work as this accrual period is priced correctly, but
the next period is not as the 'Time' parameter implied within the discount()
function is really the sum of the first 'incorrect' (for the lack of a
better word) accrual period + the the following periods.
The dirtyPriceFromYield() function is a little smarter in that basically it
computes the accrual period for the first coshflow and then works out the
accural period for the next period and adds this to the first period
(indirectly that is via the multiplication of the discount factors...).
I've included a little graphic of the inputs that I have used within the
FixedCouponBond function.
I've also included my own solution within a text file which is consistent
with the code within the YieldSolver class ( more specifically the
dirtyPriceFromYield() function ).
Sorry about the waffle...
Toy out.