Skip to content

Fix argument order in the numpy, numba and parallel Monte Carlo wrappers - #281

Merged
domokane merged 1 commit into
domokane:masterfrom
Cashubski:fix/vanilla-mc-argument-order
Sep 27, 2026
Merged

domokane merged 1 commit into
domokane:masterfrom
Cashubski:fix/vanilla-mc-argument-order

Conversation

@Cashubski

Copy link
Copy Markdown
Contributor

Summary

Four of the six Monte Carlo methods of EquityVanillaOption return NaN for every input:

call = EquityVanillaOption(Date(1, 1, 2027), 105.0, OptionTypes.EUROPEAN_CALL)
call.value_mc(value_dt, 100.0, discount_curve, dividend_curve, BlackScholes(0.3), 20000, 42)             # 10.9112
call.value_mc_numpy_only(value_dt, 100.0, discount_curve, dividend_curve, BlackScholes(0.3), 20000, 42)  # nan
call.value_mc_numba_only(...)      # nan
call.value_mc_numba_parallel(...)  # nan
call.value_mc_numpy_numba(...)     # nan

Cause. Every model function in black_scholes_mc.py has 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 receives r=opt_type, q=r, v=q, opt_type=vol; the volatility is a float that matches no option type and the result is NaN. value_mc and value_mc_nonumba_nonumpy pass 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_analytic prices 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).

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
domokane merged commit 322b3b6 into domokane:master Sep 27, 2026
2 checks passed
@domokane

Copy link
Copy Markdown
Owner

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants