Fix argument order in the numpy, numba and parallel Monte Carlo wrappers - #281
Merged
domokane merged 1 commit intoSep 27, 2026
Merged
Conversation
EquityVanillaOption.value_mc_numpy_only, value_mc_numba_only, value_mc_numba_parallel and value_mc_numpy_numba passed the option type in the position of the interest rate, so the model functions received (r=opt_type, q=r, v=q, opt_type=vol) and returned NaN. value_mc and value_mc_nonumba_nonumpy were already correct. Add a test that every variant agrees with the closed form.
domokane
approved these changes
Sep 27, 2026
Owner
|
Thanks. |
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.
Summary
Four of the six Monte Carlo methods of
EquityVanillaOptionreturnNaNfor every input:Cause. Every model function in
black_scholes_mc.pyhas the signature(s, t, k, r, q, v, opt_type, num_paths, seed, use_sobol). The four broken wrappers call them with(s, t, k, opt_type, r, q, v, ...), so the model receivesr=opt_type,q=r,v=q,opt_type=vol; the volatility is a float that matches no option type and the result isNaN.value_mcandvalue_mc_nonumba_nonumpypass the arguments in the right order and work.Fix. Pass the arguments in the model functions' order in all four wrappers.
Test.
test_monte_carlo_variants_agree_with_analyticprices the same call with all six variants and a fixed seed and checks each is finite and within sampling error of the closed form. Full unit suite passes (1,059 tests).