-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Long existing bug causing error in first period interest/cashflow calculation for FixedRateBond #1910
Comments
Thanks for posting! It might take a while before we look at your issue, so don't worry if there seems to be no feedback. We'll get to it. |
I see, thanks. I think that to be consistent with what happens during the generation of the coupon dates, |
Thanks for your prompt reply @lballabio ! Your proposal sounds good to me maybe except for one case: I'm not 100% sure if this is a valid example and appreciate more input from expert like you. Generally I agree that we should fill the gap between |
I also just noticed a long-existing thread about the same issue #405. This feels like a great opportunity to settle on a solution for this sought-after fix. |
I'm not sure if it would make sense to have Unadjusted and end-of-month in this case? |
@lballabio I see, yeah, agreed. I can go ahead and make a PR to fix then. Basically modify |
Sure, go ahead—thanks! |
Hi QL developers, I found a bug in the latest version of QL which caused inaccurate cashflow and accrued interest calculation for the first coupon period in a FixedRateBond.
Consider this US treasury note with the following properties:
https://www.investing.com/rates-bonds/usgovt-1.875-30-sep-2022
Construct it and calculate its cashflow in QL 1.9 and 1.32:
Note that QL 1.9 cashflow outputs matches a best-in-class data vendor.
Upon investigation, this turns out to be caused by the ref date of the first coupon period being moved to the last business day of the month.
https://github.com/lballabio/QuantLib/blob/master/ql/cashflows/fixedratecoupon.cpp#L198-L203
Searching in history, this bug/feature was first introduced in https://github.com/lballabio/QuantLib/pull/214/files where it moved ref date of the first coupon to the last business day of the month. Here's the related PR #210 which introduced this bug.
Here's my proposed way to fix this:
https://github.com/lballabio/QuantLib/blob/master/ql/time/calendar.cpp#L162
In Calendar::advance(), the return date will be moved to end of business day if endOfMonth && isEndOfMonth(d) is True. However, isEndOfMonth(d) is True when d is or after the end of business day, which introduces a discrepancy between d and the return date. I suggest implementing an
isEndOfBusinessDay()
and use that to replace theisEndOfMonth(d)
inCalendar::advance()
Since I'm not a bond/QuantLib expert, I'm not sure the possible side effects of this fix and would love to hear from ppl that's more familiar with this lib and make a better fix. Thanks!
The text was updated successfully, but these errors were encountered: