# Problem with bond.bondYield Quantlib

I'm having issues with a simple FixedRateBond bond yield calculation using QuantLib:

import QuantLib as ql

start = ql.Date(9,9,2020)
end = ql.Date(23,7,2021)
period = ql.Period(int(2))
coupon = 2.75
face = 100
ql.Settings.instance().evaluationDate = ql.Date(31,5,2021)
given = 102.23

schedule = ql.Schedule(start, end,
period, ql.UnitedStates(),
ql.DateGeneration.Backward, True)

day_counter = ql.Thirty360()

bond = ql.FixedRateBond(1, face, schedule, [coupon/100], day_counter)

bond_price = bond.bondYield(given, day_counter, ql.Compounded, 2)


The code above returns -0.12041547246813772 as the yield of the bond. I know the yield to be around 0.00190424005054490 since i'm replicating an excercise previously done on matlab.

The program seems to be failing since, when i call  bond.cashflows() i get three cashflows that add to about 102.391304, which is higher that the given price and therefore discount factors should be less than 1, and the yield should not be negative.

First, I don't think the coupon is correct. You have coupon = 0.0275 but then you input the parameter as [coupon/100]. That would be 2.75 bps.
Also, could 102.23 be the dirty price? QuantLib expects the clean price in the .bondYield method...
(100 + 2.75 * 53/360) / (1+ (-0.12)*53/360) = 102.21
• Yes, i edited the post to correct the coupon payment, thank you. As for the yield calculation, 102.23 is the bond's clean price, what i don't understand is why would a bond's cashflows add up to a higher amount than its clean price and end up with a negative discount rate. for validation, in matlab i just calculate them as: bndyield(102.23, 0.0275, '2020-09-09', '2021-07-23', 2, 1, 'Face', 100) , and it returns 0.0019., and i obtain a similar result with excel's  yield  function– Jun 15 at 13:52
My mistake was with the ql.Settings.instance().evaluationDate = ql.Date(31,5,2021) line, it should be set as ql.Settings.instance().evaluationDate = start to obtain a yield calculation similar to other engines.