diff --git a/financepy/products/equity/equity_vanilla_option.py b/financepy/products/equity/equity_vanilla_option.py index 17861c3d..0325b238 100644 --- a/financepy/products/equity/equity_vanilla_option.py +++ b/financepy/products/equity/equity_vanilla_option.py @@ -399,10 +399,10 @@ def value_mc_numpy_only( s0, t_exp, self.strike_price, - self.opt_type_value, r, q, vol, + self.opt_type_value, num_paths, seed, use_sobol, @@ -441,10 +441,10 @@ def value_mc_numba_only( s0, t_exp, self.strike_price, - self.opt_type_value, r, q, vol, + self.opt_type_value, num_paths, seed, use_sobol, @@ -483,10 +483,10 @@ def value_mc_numba_parallel( s0, t_exp, self.strike_price, - self.opt_type_value, r, q, vol, + self.opt_type_value, num_paths, seed, use_sobol, @@ -527,10 +527,10 @@ def value_mc_numpy_numba( s0, t_exp, self.strike_price, - self.opt_type_value, r, q, vol, + self.opt_type_value, num_paths, seed, use_sobol, diff --git a/tests/unit/test_FinEquityVanillaOption.py b/tests/unit/test_FinEquityVanillaOption.py index dae62047..702b10d4 100644 --- a/tests/unit/test_FinEquityVanillaOption.py +++ b/tests/unit/test_FinEquityVanillaOption.py @@ -126,3 +126,29 @@ def test_vanna(): test_call_option() + + +######################################################################################## + + +def test_monte_carlo_variants_agree_with_analytic(): + """Every Monte Carlo implementation prices the same call within sampling error + of the closed form. The numpy, numba and parallel wrappers used to pass the + option type in the position of the interest rate and returned NaN.""" + analytic = call_option.value( + value_date, stock_price, discount_curve, dividend_curve, model + ) + variants = { + "value_mc": 200_000, + "value_mc_numpy_only": 200_000, + "value_mc_numba_only": 200_000, + "value_mc_numpy_numba": 200_000, + "value_mc_numba_parallel": 200_000, + "value_mc_nonumba_nonumpy": 20_000, + } + for name, num_paths in variants.items(): + value = getattr(call_option, name)( + value_date, stock_price, discount_curve, dividend_curve, model, num_paths, 4242 + ) + assert math.isfinite(value), name + assert abs(value - analytic) < 0.20, (name, value, analytic)