Repository navigation
Credit coupons in Bond.forward_price the way the dirty prices and calc_ror do - #487
Merged
domokane merged 1 commit intoNov 30, 2026
Conversation
…c_ror do forward_price subtracted the coupons whose payment date falls after the settlement date and on or before the forward date. The dirty prices and calc_ror decide who gets a coupon by its coupon date, its ex-dividend date and, on the maturity date, the final coupon period. So the forward clean price jumped by a whole coupon when the forward date was a coupon date whose payment is business-day adjusted, inside an ex-dividend period, or the maturity date, where accrued_interest already includes the final coupon. Move calc_ror's rule into _cpns_held, which returns the coupons a holder from one date to another receives, and use it in both. forward_price carries each of those coupons from its payment date to the forward date as before. One kept in an ex-dividend period is paid after the forward date, so its time is negative.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The other item from #484.
forward_pricesubtracts the coupons paid between the settlement and forward dates, picked by payment date. The dirty prices andcalc_rordecide who gets a coupon by its coupon date and ex-dividend date. They also treat the maturity date as part of the final coupon period. Because the rules differ, the forward clean price jumps by a whole coupon in three places. For the bond from #484's tests, settled on 1 Mar 2027 at a clean price of 100 with a 3% repo rate:The cause of each jump:
accrued_interestincludes the final coupon since Fix Bond settlement on the maturity date and coupon attribution in calc_ror #484, and the coupon was also subtracted as paid.Change
_cpns_held(begin_dt, end_dt)returns the coupons that a holder frombegin_dttoend_dtreceives. It uses the rulecalc_roralready had, moved out ofcalc_ror, which now calls it.forward_pricesubtracts those coupons, each carried from its payment date to the forward date, as before. A coupon kept in an ex-dividend period is paid after the forward date, so its carry time is negative.BondFuture.implied_repo_ratepicks coupons with the same kind of window.test_implied_repo_inverts_forward_pricestill passes, because its dates avoid these cases. I can align it in a follow-up if you like.Tests
test_forward_price_moves_smoothlywalks the forward date a day at a time:It checks that no day moves the price by 0.01 or more. On master all 4 cases fail, each with a move of 2.003. The 16 tests from #484 still pass, including the
calc_rorones.I also walked the forward date through the whole life of this bond, and of a quarterly bond with weekend coupon dates, with and without ex-dividend days. The largest one-day move is now 0.0075, against 2.004 and 1.257 on master.
pytest tests/unitgives 2073 passed, including the new cases.scripts/run_all_regression_tests.pygives the same error counts as master in all 129 modules. The warning counts differ by one only in the equity barrier, FX barrier and FX lookback Monte Carlo modules, which vary from run to run and don't use bonds. The branch merges cleanly with #486, and the bond tests pass on the merge.