Repository navigation
Price bonds from discount and survival curves on the maturity date, and raise for yields and spreads there - #486
Merged
domokane merged 1 commit intoNov 30, 2026
Conversation
…nd raise for yields and spreads there On the maturity date, dirty_price_from_ytm returns the final coupon and principal (only the principal when the bond is ex-dividend), and since FinancePy-Org#484 accrued_interest uses the final coupon period. The discount-curve, OAS and survival-curve prices only counted flows whose coupon date is after settlement, so they gave a dirty price of 0 and a clean price of minus the accrued coupon. Count the flows paid on the maturity date in those prices, with the same ex-dividend rule. On that date the price no longer depends on a yield or spread, so yield_to_maturity, option_adjusted_spread and z_spread raise FinError instead of returning the solver's lower bound (-0.2), printing a warning and returning nan, or raising RuntimeError.
Collaborator
|
Thanks |
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.
Follow-up to #484, as you suggested there. On the maturity date,
dirty_price_from_ytmreturns the final coupon plus principal (102 for this bond, or 100 when it is ex-dividend), and since #484accrued_interestuses the final coupon period (2 or 0). The curve-based methods didn't agree. For the 4% semi-annual bond from #484's tests, maturing on 15 Jan 2030, settled on that date:dirty_price_from_discount_curve,dirty_price_from_oas,dirty_price_from_survival_curveclean_price_from_discount_curve,clean_price_from_survival_curveoption_adjusted_spreadnanFinErroryield_to_maturityValueErrorfor any other priceFinErrorz_spreadRuntimeErrorFinErrorThe day before maturity, these prices are already close to the YTM-based ones, and the solvers work.
Change
cpn_dt > settle_dt. They now use a small_is_owedcheck, which also keeps the final flows on the maturity date, asdirty_price_from_ytmdoes. The existing ex-dividend rule then drops the final coupon inside the ex-dividend period. The flows are still discounted from their payment dates to the settlement date, so a final payment date that is business-day adjusted past the maturity date is discounted for those days.yield_to_maturity,option_adjusted_spreadandz_spreadnow raiseFinError("Cannot calculate the ... on the maturity date")before solving.asset_swap_spreadalready raises on that date, from the swap schedule. I didn't touchforward_priceto the maturity date, the other item from #484, since it's a separate fix.Tests
In
tests/unit/test_bond_maturity_settlement.py:test_curve_prices_on_maturitychecks the three dirty prices and two clean prices, with and without ex-dividend days, for a new bond and after earlier calls. The curves are anchored at the issue date, so the prices are re-based to the settlement date.test_yields_and_spreads_on_maturity_raise.All 7 new cases fail on master, and the 16 tests from #484 still pass.
pytest tests/unitgives 2076 passed, including the new cases.scripts/run_all_regression_tests.pygives the same error counts as master in all 129 modules (852 in total). The warning counts differ only in the equity barrier and FX lookback modules, by one each. Those are Monte Carlo modules that vary from run to run and don't use bonds.