I'm trying to calculate the ytm of bonds amortized in quantlib. The maturity of this bond is five years, starting from the second year to repay 25% of the face value until the last year.
The cash flow of bonds is correct. I want to calculate ytm based on the current net price, but I don't know why it is wrong.
I have the following bond:
Maturity Date:
24.07.2024
Coupon Frequency:
25 at 24.07.2021
25 at 24.07.2022
25 at 24.07.2023
25 at 24.07.2024
Day Count
Convention: ACT/365
Coupon rate: 6.5
Here is the python code
start_d = ql.Date(24, ql.July, 2019)
mat_d = ql.Date(24, ql.July, 2024)
calc_date = ql.Date(8, ql.December, 2022)
frequency = ql.Period(ql.Annual)
freq = ql.Annual
dayCounter = ql.Actual365Fixed()
cleanprice = 45.83
ql.Settings.instance().evaluationDate = calc_date
schedule = ql.MakeSchedule(start_d, mat_d, frequency)
bond = ql.AmortizingFixedRateBond(0, [100, 100, 75, 50, 25, 0], schedule, [0.065], dayCounter)
for c in bond.cashflows():
print(f"{str(c.date()):20} => {c.amount():.4}")
ytm = bond.bondYield(float(cleanprice), dayCounter, ql.Compounded, freq)
print(f"{'YTM':20} => {round(ytm * 100, 8):.6}")
print(f"{'Accrued days':20} => {str(ql.BondFunctions.accruedDays(bond)):.4}")
print(f"{'Accrued amount':20} => {round(bond.accruedAmount(), 8):.4}")
The following is the printing of cash flow and ytm
July 24th, 2020 => 6.518
July 24th, 2021 => 6.5
July 24th, 2021 => 25.0
July 24th, 2022 => 4.875
July 24th, 2022 => 25.0
July 24th, 2023 => 3.25
July 24th, 2023 => 25.0
July 24th, 2024 => 1.629
July 24th, 2024 => 25.0
YTM => 125.49
Accrued days => 138
Accrued amount => 2.458