Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions financepy/products/equity/equity_vanilla_option.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
26 changes: 26 additions & 0 deletions tests/unit/test_FinEquityVanillaOption.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Loading