You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
AD/numerics: reduce hard threshold branches in stochastic formulas #291
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.
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
functionpath_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.
Activity
alecloudenback commentedon Oct 11, 2026
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: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. ForHullWhite(0.1, σ, Yield.Constant(Continuous(0.0)))andOption.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.Merge pull request #348 from JuliaActuary/fix/zero-volatility-derivat…