Conversation
The fixed- and floating-strike lookback formulas divide by lambda = 2(r - q)/sigma^2, and with r equal to q both engines returned NaN. The ratio they divide is itself zero there, and its limit is stdDev times a combination of N(d1) and n(d1), which the engines now use for |lambda| < 1e-7. Near zero the old division also lost digits: at a carry of 1e-12 it was 2e-5 off. Over 792 options with carries between -3% and 3%, including 0 and values down to 1e-12, the prices are within 4e-9 of the same formulas evaluated in 50-digit arithmetic.
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.
AnalyticContinuousFloatingLookbackEngineandAnalyticContinuousFixedLookbackEnginereturn NaN whenever the risk-free rate equals the dividend yield, at any volatility. Both formulas divide by lambda = 2(r - q)/sigma^2, and the ratio being divided is zero there too.The limit of that ratio is simple: stdDev * (eta n(d1) - d1 N(-eta d1)) in the floating case and -stdDev * (d1 N(eta d1) + eta n(d1)) in the fixed one, which gives the usual zero-carry lookback formulas. The engines use it for |lambda| < 1e-7. The threshold is where the error of the limit and the cancellation in the division cross: near zero the division alone was 2e-5 off at a carry of 1e-12.
Over 792 options, with carries between -3% and 3% including 0 and values down to 1e-12, master gives 72 NaN, all at zero carry. With this change there are none, and every price is within 4e-9 of the same formulas evaluated in 50-digit arithmetic.
testAnalyticContinuousLookbackZeroCarrychecks two floating and four fixed lookbacks at r = q = 5%, and all six are NaN on master.LookbackOptionTestsand the full suite pass.The partial-time lookback engines divide by the carry as well and are left as they are.