Integrate TransformedYield and add Cashflow support for ZRC methods#121
Open
alecloudenback wants to merge 8 commits intomasterfrom
Open
Integrate TransformedYield and add Cashflow support for ZRC methods#121alecloudenback wants to merge 8 commits intomasterfrom
alecloudenback wants to merge 8 commits intomasterfrom
Conversation
Eliminate friction when using Vector{Cashflow} with ZeroRateCurve-based
sensitivity functions, and enable do-block syntax with AbstractYieldModel.
Cashflow support:
- Add _extract_cfs_times helper to split Vector{Cashflow} into amounts/times
- Add 16 Cashflow-accepting overloads for all ZRC-based duration, convexity,
and sensitivities methods (single-curve and two-curve variants)
Do-block forwarding:
- Add duration(fn, yield::AbstractYieldModel) and convexity(fn, yield::AbstractYieldModel)
so that `duration(Constant(0.05)) do i ... end` works naturally
- No dispatch ambiguity: ZRC <: AbstractYieldModel is more specific
Documentation:
- Updated docstrings for duration, KeyRates duration, sensitivities (single
and two-curve) to document Cashflow signatures
- Added "Using Cashflow Objects" and "Constructing a ZeroRateCurve from
Other Models" sections to sensitivities.md
- Updated README quickstart to show Cashflow usage
Tests:
- 18 new tests verifying Cashflow variants match amounts+times for all
dispatch combinations
- 2 new tests for do-block with AbstractYieldModel
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Replace Vector{Cashflow} with AbstractVector{<:Cashflow} in 9
docstrings to match actual method signatures
- Add missing .cross, .credit checks in two-curve convexity and
sensitivities tests
- Add test for Cashflow objects with non-tenor times (semi-annual
cashflows on annual-tenor ZRC) to exercise interpolation path
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Verify duration/convexity do-block with ZRC routes through the AD key-rate path, and test the convexities field of sensitivities NamedTuple. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Requires FinanceModels v4.18+ for ZeroRateCurve constructor and spline types used by the Cashflow and do-block support. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Replace the sample-bump-refit approach in `_krd_new_curve(::KeyRateZero)` with a lazy `TransformedYield` wrapper from FinanceModels. The new `_tent_bump` helper implements the Ho (1992) tent function as a closure, and `_ensure_yield_model` wraps bare Rate/Real inputs so they satisfy the `AbstractYieldModel` constraint. This avoids refitting a linear spline on every KRD evaluation and preserves the original curve shape between KRD points. - Bump FinanceModels compat to v5 (for TransformedYield support) - Add FinanceModels to docs/Project.toml for @example blocks - Add 14 new tests for tent bump shape and TransformedYield integration - Add "Curve Transformations" docs section with 6 live @example blocks - Add "Validating AD with TransformedYield" docs section Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Update expected duration values: FM v5 CompositeYield operates in continuous zero-rate space, so bump-and-reprice now gives continuous modified duration (= Macaulay duration) instead of periodic modified - Rename ForwardYields → ForwardYield (singular) per FM v5 naming Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Resolve FinanceModels compat conflict: keep "5" (TransformedYield requires v5). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.
Summary
This PR upgrades ActuaryUtilities to work with FinanceModels v5, integrating
TransformedYieldfor key-rate bump-and-reprice, addingCashflowobject support across allZeroRateCurvemethods, and expanding documentation with live@exampleblocks.Key changes
TransformedYield for KeyRateZero — Replace the old
_krd_new_curve(::KeyRateZero)(which extracted zero rates, mutated a vector, and refitted a spline) with a lazyTransformedYieldthat applies a Ho (1992) tent-function bump closure directly. This avoids unnecessary curve refitting and preserves the original curve's interpolation method.Cashflow object support — All
ZeroRateCurve-basedduration,convexity, andsensitivitiesmethods now acceptAbstractVector{<:Cashflow}directly (amounts and timepoints extracted automatically), eliminating the need to manually split cashflows.Do-block forwarding for AbstractYieldModel —
duration(fn, yield_model)andconvexity(fn, yield_model)now forward correctly to the existingduration(yield, fn)dispatch, enabling do-block syntax with any yield model (not just ZRC).FinanceModels v5 compat — Bumped compat to
"5", updated tests for two FM v5 breaking changes:CompositeYieldnow operates in continuous zero-rate space, soduration(Yield.Constant(r), ...)returns the continuous modified duration (= Macaulay duration) rather than periodic modified durationForwardYieldsrenamed toForwardYield(singular)Files changed
Project.toml^4.17→5docs/Project.toml@exampleblocksREADME.mdCashflowobjectssrc/financial_math.jl_tent_bump+_ensure_yield_modelhelpers,TransformedYield-based_krd_new_curve(::KeyRateZero),_extract_cfs_timeshelper,Cashflowoverloads for all ZRC methods, do-block forwarding forAbstractYieldModeltest/runtests.jlKeyRateZero TransformedYieldtestset (tent bump shape, type checks, KRD sum ≈ total duration), addCashflowsupport testset (27 tests across single/two-curve variants), add do-block + dispatch priority testsdocs/src/financial_math.md@exampleblocks (parallel shift, periodic rate arithmetic, tenor-dependent twist, PV comparison, bootstrapped curve + stress, negative rates)docs/src/sensitivities.md@exampleblockTest plan
KeyRateZero TransformedYieldtests pass (14 tests — tent bump shape for interior/first/last points, type checks, KRD sum ≈ total modified duration)ZeroRateCurve Cashflow supporttests pass (27 tests — allduration/convexity/sensitivitiesvariants with single and two-curve, including semi-annual cashflows on annual-tenor curves)do-block with AbstractYieldModeltests pass (2 tests)ZRC dispatch prioritytests pass (2 tests — ZRC AD path preferred over AbstractYieldModel forwarding)@exampleblocks (requires FM dev with TransformedYield)🤖 Generated with Claude Code