From 970f5ec7b37d0443a9904423a769cf8ff57ccebf Mon Sep 17 00:00:00 2001 From: hereiszepedro <78000000+hereiszepedro@users.noreply.github.com> Date: Tue, 1 Dec 2026 15:02:46 +0000 Subject: [PATCH 1/2] Test FX digital Monte Carlo against the analytic value with a spot lag --- tests/unit/test_fx_double_digital_option.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tests/unit/test_fx_double_digital_option.py b/tests/unit/test_fx_double_digital_option.py index 0c1a3abc..49cfb678 100644 --- a/tests/unit/test_fx_double_digital_option.py +++ b/tests/unit/test_fx_double_digital_option.py @@ -114,3 +114,23 @@ def test_digitals_with_spot_lag_decompose_the_vanilla_call(): expected = _lag_value(vanilla)["v"] assert np.isclose(_lag_value(asset) - k * _lag_value(cash), expected, rtol=1e-6) + + +def test_digital_monte_carlo_with_spot_lag_uses_the_delivery_forward_and_discount(): + """A digital call plus a digital put at the same strike pays one unit for sure, so + in Monte Carlo the pair is worth the value of that unit paid on the delivery date, + the same as in the analytic value.""" + for prem_currency in ("USD", "EUR"): + options = [ + FXDigitalOption(lag_expiry_dt, 1.10, "EURUSD", opt_type, 1.0, prem_currency, 2) + for opt_type in (OptionTypes.DIGITAL_CALL, OptionTypes.DIGITAL_PUT) + ] + mc = sum( + option.value_mc( + lag_value_dt, spot_fx_rate, lag_domestic_curve, lag_foreign_curve, model, + num_paths=200000, + ) + for option in options + ) + analytic = sum(_lag_value(option) for option in options) + assert np.isclose(mc, analytic, rtol=1e-4) From 1e30d115f7a1b97c4aec9c610b659ed9faaf01a1 Mon Sep 17 00:00:00 2001 From: hereiszepedro <78000000+hereiszepedro@users.noreply.github.com> Date: Tue, 1 Dec 2026 15:05:43 +0000 Subject: [PATCH 2/2] Grow the FX digital Monte Carlo forward from the spot date to delivery FXDigitalOption.value builds the forward from the spot date to the delivery date and discounts the payment from delivery (#475). value_mc still measured time from the spot date to expiry, discounted over that shorter period as if it started today, and drifted the rate with the zero rates to expiry. With a spot lag the Monte Carlo price therefore did not converge to the analytic one: a digital call plus a digital put paying USD was worth 0.970685 instead of the 0.970366 discount factor to delivery. Use the same forward, discount factor and expiry time as value(). With spot_days=0, the default, the discounting is unchanged and prices on flat curves are identical. --- financepy/products/fx/fx_digital_option.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/financepy/products/fx/fx_digital_option.py b/financepy/products/fx/fx_digital_option.py index 0271c9ff..54527a47 100644 --- a/financepy/products/fx/fx_digital_option.py +++ b/financepy/products/fx/fx_digital_option.py @@ -218,8 +218,9 @@ def value_mc( spot_dt = value_dt.add_weekdays(self.spot_days) - t_del = option_years(spot_dt, self.delivery_dt) - t_exp = option_years(spot_dt, self.expiry_dt) + t_spot = option_years(value_dt, spot_dt) + t_del = option_years(value_dt, self.delivery_dt) + t_exp = option_years(value_dt, self.expiry_dt) # ------------------------------------------------------------------ # Market parameters @@ -227,12 +228,16 @@ def value_mc( t = max(t_exp, 1.0e-10) - dom_df = domestic_curve.df_t(t) - - r_d = domestic_curve.zero_rate_cc(self.expiry_dt) - r_f = foreign_curve.zero_rate_cc(self.expiry_dt) + # As in value(): the forward grows from the spot date to delivery and + # the payment is discounted from delivery. + dom_df = domestic_curve.df_t(t_del) + dom_fwd_df = dom_df / domestic_curve.df_t(t_spot) + for_fwd_df = foreign_curve.df_t(t_del) / foreign_curve.df_t(t_spot) - mu = r_d - r_f + if t_exp == 0.0: + f = spot_fx_rate + else: + f = spot_fx_rate * for_fwd_df / dom_fwd_df v = model.volatility @@ -245,7 +250,7 @@ def value_mc( rng = np.random.default_rng(seed) g = rng.standard_normal(num_paths) - s = spot_fx_rate * np.exp((mu - v * v / 2.0) * t) + s = f * np.exp(-v * v / 2.0 * t) m = np.exp(g * np.sqrt(t) * v) s_1 = s * m