Skip to content

Price bonds from discount and survival curves on the maturity date, and raise for yields and spreads there - #486

Merged
domokane merged 1 commit into
FinancePy-Org:masterfrom
QuantIntellect:fix/bond-curve-prices-on-maturity
Nov 30, 2026
Merged

domokane merged 1 commit into
FinancePy-Org:masterfrom
QuantIntellect:fix/bond-curve-prices-on-maturity

Conversation

@QuantIntellect

Copy link
Copy Markdown
Contributor

Follow-up to #484, as you suggested there. On the maturity date, dirty_price_from_ytm returns the final coupon plus principal (102 for this bond, or 100 when it is ex-dividend), and since #484 accrued_interest uses 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:

master this PR
dirty_price_from_discount_curve, dirty_price_from_oas, dirty_price_from_survival_curve 0 102 (100 ex-dividend)
clean_price_from_discount_curve, clean_price_from_survival_curve -2.0 (0 ex-dividend) 100
option_adjusted_spread prints a warning, returns nan raises FinError
yield_to_maturity -0.2, the solver's lower bound, for a clean price of 100, and scipy's ValueError for any other price raises FinError
z_spread raises RuntimeError raises FinError

The day before maturity, these prices are already close to the YTM-based ones, and the solvers work.

Change

  • Curve prices: the three loops selected flows with cpn_dt > settle_dt. They now use a small _is_owed check, which also keeps the final flows on the maturity date, as dirty_price_from_ytm does. 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.
  • Yields and spreads: on the maturity date every price is the same whatever the yield or spread, so there is nothing to solve for. With the prices above, the OAS solver still fails for every target price. So yield_to_maturity, option_adjusted_spread and z_spread now raise FinError("Cannot calculate the ... on the maturity date") before solving.

asset_swap_spread already raises on that date, from the swap schedule. I didn't touch forward_price to 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_maturity checks 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/unit gives 2076 passed, including the new cases. scripts/run_all_regression_tests.py gives 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.

…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.
@domokane
domokane merged commit f92b759 into FinancePy-Org:master Nov 30, 2026
2 checks passed
@domokane

Copy link
Copy Markdown
Collaborator

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants