Skip to content

Integrate TransformedYield and add Cashflow support for ZRC methods#121

Open
alecloudenback wants to merge 8 commits intomasterfrom
integrate-transformed-yield
Open

Integrate TransformedYield and add Cashflow support for ZRC methods#121
alecloudenback wants to merge 8 commits intomasterfrom
integrate-transformed-yield

Conversation

@alecloudenback
Copy link
Member

Summary

This PR upgrades ActuaryUtilities to work with FinanceModels v5, integrating TransformedYield for key-rate bump-and-reprice, adding Cashflow object support across all ZeroRateCurve methods, and expanding documentation with live @example blocks.

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 lazy TransformedYield that 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-based duration, convexity, and sensitivities methods now accept AbstractVector{<:Cashflow} directly (amounts and timepoints extracted automatically), eliminating the need to manually split cashflows.

  • Do-block forwarding for AbstractYieldModelduration(fn, yield_model) and convexity(fn, yield_model) now forward correctly to the existing duration(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:

    • CompositeYield now operates in continuous zero-rate space, so duration(Yield.Constant(r), ...) returns the continuous modified duration (= Macaulay duration) rather than periodic modified duration
    • ForwardYields renamed to ForwardYield (singular)

Files changed

File Change
Project.toml FM compat ^4.175
docs/Project.toml Add FinanceModels dep for @example blocks
README.md Update snippet to use Cashflow objects
src/financial_math.jl _tent_bump + _ensure_yield_model helpers, TransformedYield-based _krd_new_curve(::KeyRateZero), _extract_cfs_times helper, Cashflow overloads for all ZRC methods, do-block forwarding for AbstractYieldModel
test/runtests.jl Fix 3 tests for FM v5 API changes, add KeyRateZero TransformedYield testset (tent bump shape, type checks, KRD sum ≈ total duration), add Cashflow support testset (27 tests across single/two-curve variants), add do-block + dispatch priority tests
docs/src/financial_math.md New "Curve Transformations" section with 6 live @example blocks (parallel shift, periodic rate arithmetic, tenor-dependent twist, PV comparison, bootstrapped curve + stress, negative rates)
docs/src/sensitivities.md New "Using Cashflow Objects" and "Constructing a ZeroRateCurve from Other Models" sections, new "Validating AD with TransformedYield" live @example block

Test plan

  • All existing tests pass (72/72 duration and convexity, including the 3 fixed FM v5 tests)
  • New KeyRateZero TransformedYield tests pass (14 tests — tent bump shape for interior/first/last points, type checks, KRD sum ≈ total modified duration)
  • New ZeroRateCurve Cashflow support tests pass (27 tests — all duration/convexity/sensitivities variants with single and two-curve, including semi-annual cashflows on annual-tenor curves)
  • New do-block with AbstractYieldModel tests pass (2 tests)
  • New ZRC dispatch priority tests pass (2 tests — ZRC AD path preferred over AbstractYieldModel forwarding)
  • Docs build with live @example blocks (requires FM dev with TransformedYield)

🤖 Generated with Claude Code

alecloudenback and others added 8 commits February 18, 2026 09:04
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>
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