Skip to content

Give the short rate trees discount factors on their ACT/365F clock - #502

Open
hereiszepedro wants to merge 2 commits into
FinancePy-Org:masterfrom
hereiszepedro:tree-dfs-act365f-clock
Open

hereiszepedro wants to merge 2 commits into
FinancePy-Org:masterfrom
hereiszepedro:tree-dfs-act365f-clock

Conversation

@hereiszepedro

Copy link
Copy Markdown
Contributor

IborSwaption (BK and BDT), IborBermudanSwaption, BondOption and BondEmbeddedOption pass discount_curve._times and discount_curve._dfs straight to build_tree. Those times are measured on the curve's own day count clock (curve_dc_type), but the trees and the coupon times use days / G_DAYS_IN_YEAR. When the curve is not on ACT/365F, the tree reads every discount factor at the wrong time, so the price depends on the curve's day count even when the discount factors on every date are the same.

Two DiscountCurves with the same discount factors on the same dates, one with curve_dc_type=ACT_365F and one with ACT_360 (the curve in the new test):

Product Model ACT/365F curve ACT/360 curve, master ACT/360 curve, this PR
2Y x 10Y payer swaption BK 32,879.43 30,193.24 32,879.43
2Y x 10Y payer swaption BDT 39,169.07 36,410.53 39,169.07
2Y x 10Y Bermudan payer HW 51,246.06 49,122.92 51,246.06
2Y x 10Y Bermudan payer BK 47,351.79 44,969.72 47,351.79
2Y x 10Y Bermudan payer BDT 54,268.59 51,904.47 54,268.59
2Y call on a 2034 bond HW 3.6690 3.2704 3.6690
2Y call on a 2034 bond BK 3.5090 3.7836 3.5090
2Y call on a 2034 bond BDT 4.1612 4.4114 4.1612

The same happens with IborSingleCurve(..., curve_dc_type=DayCountTypes.ACT_360).

This PR adds DiscountCurve.tree_dfs(t_max) and uses it in the four products. For an ACT/365F curve it returns the knots unchanged, so prices with the default curves are unchanged. For any other clock it samples the curve daily out to t_max and returns the times as days / G_DAYS_IN_YEAR. Because the knots fall on dates, the samples reproduce a flat-forward curve exactly. The analytic Hull-White branch of IborSwaption already handles this (#465) and is not touched. IborCapFloor is left alone because #501 is open on that file.

The first commit adds tests/unit/test_tree_curve_day_count.py, which prices each product with both curves and expects the same value. Its 11 cases fail on master and pass with the fix. The unit suite passes (2153 tests). I also ran the golden regression scripts for the swaption, Bermudan swaption, bond option and embedded option (HW, BK, BDT). Only the timing columns change.

AI-assisted (Claude Code). I checked the numbers above and ran the tests locally.

IborSwaption (BK and BDT), IborBermudanSwaption, BondOption and
BondEmbeddedOption passed the curve's knot times straight to the trees.
Those times are on the curve's day count clock, while the trees and the
coupon times use days / 365. With a curve on ACT/360, for example, the
trees discounted every flow with the wrong discount factor.

DiscountCurve.tree_dfs returns the knots unchanged for an ACT/365F curve
and otherwise samples the curve daily on the trees' clock.

This branch has not been deployed

No deployments
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.

1 participant