Skip to content

AD: use type-generic identities in present-value and derivative-pricing reductions #288

Open

Description

@alecloudenback

Problem

Several pricing reductions initialize accumulators with literal 0.0, including generic present_value methods and cap, floor, and swaption pricing.

Nonempty computations usually promote after the first operation, but empty projections always return Float64 regardless of the model/cashflow scalar type. Fixed literals also make generic AD and arbitrary-precision behavior less predictable.

Proposed direction

Use an identity derived from the relevant model, cashflow amount, or computed contribution type. Where inference makes that difficult, structure the reduction so the first contribution establishes the accumulator type while still handling empty projections explicitly.

Review nearby 1.0 identities where they participate in typed accumulators as well.

Acceptance criteria

  • Empty and nonempty present-value paths preserve an appropriate scalar type for AD and BigFloat inputs.
  • Cap, floor, and swaption accumulation does not force Float64.
  • Existing numerical results remain unchanged.
  • Tests include empty/past-maturity projections and at least one non-Float64 scalar type.

Activity

  1. alecloudenback commented on Oct 11, 2026

    @alecloudenback
    MemberAuthor

    Review update against FinanceModels v7.0.0 (6cb71714), 2026-10-11.

    Mostly resolved; remaining priority: medium, overlapping #107. Generic present-value reductions and empty cap/floor values now preserve BigFloat and ForwardDiff values appropriately. The corresponding regression checks pass.

    The broader Float32 criterion is not yet met. An entirely Float32 Vasicek model still returns Float64 for a Float32 cap, floor, or swaption, including a one-period cap with no caplets. The strip and swaption code use Float64 period/weight literals; this is wider than the accumulator identity alone.

    m = ShortRate.Vasicek(0.1f0, 0.04f0, 0.01f0, 0.03f0)
    typeof(present_value(m, Option.Cap(0.04f0, 2, 0.5f0))) # Float64

    See cap/floor strip and swaption schedule. Suggested scope: track the remaining Float32 widening with #107, then close this issue once that overlap is explicitly accounted for.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions