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: 6 additions & 2 deletions financepy/products/fx/fx_one_touch_option.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
from ...utils.helpers import option_years
from ...models.model import Model
from ...models.gbm_process_simulator import get_paths_times
from ...models.bs_equity_one_touch import barrier_pay_asset_at_expiry_down
from ...models.bs_equity_one_touch import barrier_pay_asset_at_expiry_up
from ...products.fx.fx_option import FXOption
from ...utils.math import normcdf_vect
from ...market.curves.discount_curve import DiscountCurve
Expand Down Expand Up @@ -517,7 +519,8 @@ def value_mc(
if s0 <= h:
raise FinError("Stock price is currently below barrier.")

v = _barrier_pay_one_at_hit_pv_down(s, h, 0.0, dt) * h
v = barrier_pay_asset_at_expiry_down(s, h)
v = v * np.exp(-r_d * t_exp)
return v

elif self.opt_type == TouchOptionTypes.UP_AND_IN_ASSET_AT_EXPIRY:
Expand All @@ -526,7 +529,8 @@ def value_mc(
if s0 >= h:
raise FinError("Stock price is currently below barrier.")

v = _barrier_pay_one_at_hit_pv_up(s, h, 0.0, dt) * h
v = barrier_pay_asset_at_expiry_up(s, h)
v = v * np.exp(-r_d * t_exp)
return v

elif self.opt_type == TouchOptionTypes.DOWN_AND_OUT_CASH_OR_NOTHING:
Expand Down
28 changes: 28 additions & 0 deletions tests/unit/test_fx_one_touch_option.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,31 @@ def test_low_volatility():
option = FXOneTouchOption(expiry_dt, opt_type, barrier, payment_size)
v = option.value(value_dt, 1.0, curves[0], curves[1], BlackScholes(0.0005))
assert np.isclose(v, expected, rtol=1e-10, atol=1e-10), (opt_type, v, expected)


########################################################################################


def test_mc_asset_in_plus_out_is_discounted_forward():

# On the same paths, knock-in plus knock-out asset-at-expiry pays S(T) on every path
for in_type, out_type, spot_fx_rate in [
(
TouchOptionTypes.DOWN_AND_IN_ASSET_AT_EXPIRY,
TouchOptionTypes.DOWN_AND_OUT_ASSET_OR_NOTHING,
1.05,
),
(
TouchOptionTypes.UP_AND_IN_ASSET_AT_EXPIRY,
TouchOptionTypes.UP_AND_OUT_ASSET_OR_NOTHING,
0.95,
),
]:
v_in = FXOneTouchOption(expiry_dt, in_type, barrier_rate, payment_size).value_mc(
value_dt, spot_fx_rate, domestic_curve, foreign_curve, model
)
v_out = FXOneTouchOption(expiry_dt, out_type, barrier_rate, payment_size).value_mc(
value_dt, spot_fx_rate, domestic_curve, foreign_curve, model
)
expected = spot_fx_rate * foreign_curve.df(expiry_dt)
assert np.isclose(v_in + v_out, expected, rtol=5e-3), (in_type, v_in + v_out, expected)