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
21 changes: 13 additions & 8 deletions financepy/products/fx/fx_digital_option.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,21 +218,26 @@ 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
# ------------------------------------------------------------------

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

Expand All @@ -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
Expand Down
20 changes: 20 additions & 0 deletions tests/unit/test_fx_double_digital_option.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Loading