Repository navigation
Keep finite power-times-CDF products in AnalyticBarrierEngine at low volatility - #2992
Open
anveshachuri wants to merge 1 commit into
Open
anveshachuri wants to merge 1 commit into
anveshachuri wants to merge 1 commit into
Conversation
|
Thanks for opening this pull request! It might take a while before we look at it, so don't worry if there seems to be no feedback. We'll get to it. |
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.
fixes #2969.
C(),D(),E()andF()each form products likepow(H/S, 2 mu) * N(y), and returned 0 wheneverN(y)underflowed. at low volatility and large carrypowoverflows at the same time, and the product is finite and not small (0.076 forDin the issue's example), so the engine was off by that amount.this adds a helper that computes
power * N(y)as before when both factors are in range, so results don't change anywhere else (bit for bit), and otherwise forms it asexp(log(power) + log N(y)). forN(y)below the smallest normal double,log N(y)uses the log of the same asymptotic expansion (A&S 26.2.12) thatCumulativeNormalDistributionalready uses for very negativey, with the log of the gaussian density in closed form.the issue only checked the down-and-out put without rebate, but the down-and-in put is off by the same amount (e.g. 65.5304 vs 65.6064), and with a rebate
E()andF()hit the same problem (down-and-out put with rebate 2.0 was 3.6% too high at 1.6% vol). the new testtestLowVolatilityLargeCarrycovers down-and-out and down-and-in puts, with and without rebate, at 0.5% to 2% volatility (20 cases), against the same closed-form formulas evaluated with 60-digit arithmetic in mpmath (script below). before the change 16 of the 20 cases fail (every vol below 2%), after it all pass.the tolerance is 1e-10 relative to
max(price, 1): for the 0.5% down-and-out the price is 7.6e-6 but it's a difference of terms of the order of the spot, so 1e-14 absolute is the best a double can do there.BarrierOptionTests(including the existingtestLowVolatilityat 1e-7 vol),SoftBarrierOptionTests,QuantoOptionTests,PartialTimeBarrierOptionTests,DoubleBarrierOptionTests,BinaryOptionTestsandFdHestonTests/testFdmHestonBarrierVsBlackScholespass (gcc 14.3, cmake + ninja, release).ai use: I used Claude (Anthropic) to help write the fix, the test and the reference script; I checked the math and ran the tests before and after the change myself.
reference values (mpmath, 60 digits)