Skip to content

AD/numerics: reduce hard threshold branches in stochastic formulas #291

Closed

Description

@alecloudenback

Problem

Stochastic pricing uses hard transitions such as abs(a) < 1e-12, abs(σ) < 1e-15, and σ_P < 1e-15 to select limiting formulas.

The limits are needed for numerical stability, but fixed branches introduce derivative discontinuities at their cutoffs. This can create noisy gradients when fitting parameters near zero.

Proposed direction

  • Rewrite expressions with stable primitives such as expm1 where that removes a branch.
  • Use well-conditioned helper functions for removable singularities and their series expansions.
  • Where a true nonsmooth limit remains, document it and test one-sided behavior.
  • Keep intrinsic-value max behavior explicit because payoff nonsmoothness is mathematical rather than merely numerical.

Acceptance criteria

  • Values and first derivatives remain finite as a -> 0 and σ -> 0.
  • Derivatives do not jump solely because of an implementation cutoff where the underlying formula is smooth.
  • Stable and general formulas agree over an overlap region.
  • Tests cover values immediately on both sides of any remaining threshold.

Activity

  1. alecloudenback commented on Oct 11, 2026

    @alecloudenback
    MemberAuthor

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

    Priority: high for the remaining zero-volatility simulation derivative bug. Much of the original bond-price stability work is complete, but this issue is not fully resolved.

    The Gaussian simulation transition still computes sqrt(σ^2 * factor). At σ = 0 this can turn zero partials into NaN, even when differentiating mean reversion rather than volatility:

    using FinanceModels, ForwardDiff, Random
    function path_discount(a)
        m = ShortRate.Vasicek(a, 0.04, 0.0, 0.03)
        p = only(simulate(m; n_scenarios=1, timestep=0.1,
                         horizon=1.0, rng=Random.Xoshiro(11)))
        discount(p, 1.0)
    end
    ForwardDiff.derivative(path_discount, 0.1) # NaN
    (path_discount(0.100001) - path_discount(0.099999)) / 2e-6
    # -0.004536863384974055

    Differentiating a fixed-draw Vasicek or Hull–White path in σ at zero also gives NaN; one-sided finite differences are finite. See OU transition. A candidate fix is to express the nonnegative-volatility standard deviation as σ * sqrt(factor), with regression checks at zero volatility and zero mean reversion.

    A separate remainder is the bond-option cutoff, σ_P < 1e-15. For HullWhite(0.1, σ, Yield.Constant(Continuous(0.0))) and Option.ZCBCall(1.0, 2.0, 1.0), positive σ = 1e-16 gives vega 0, while the positive-volatility limiting value is about 0.3614293. The absolute price error is tiny, but the sensitivity is suppressed. Narrow this issue to the remaining simulation boundary and option-cutoff behavior; the earlier general mean-reversion/CIR bond-price problems have been addressed.

  2. added a commit that references this issue on Oct 12, 2026
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