def test_UP_AND_IN_CASH_AT_EXPIRY(): stock_price = 95.0 downType = TouchOptionTypes.UP_AND_IN_CASH_AT_EXPIRY option = EquityOneTouchOption(expiry_date, downType, barrier_level, payment_size) v = option.value(valuation_date, stock_price, discount_curve, dividend_curve, model) v_mc = option.value_mc(valuation_date, stock_price, discount_curve, dividend_curve, model, num_steps_per_year, num_paths) assert round(v, 5) == 10.86668 assert round(v_mc, 5) == 10.67302
def test_DOWN_AND_OUT_CASH_OR_NOTHING(): stock_price = 105.0 downType = TouchOptionTypes.DOWN_AND_OUT_CASH_OR_NOTHING option = EquityOneTouchOption(expiry_date, downType, barrier_level, payment_size) v = option.value(valuation_date, stock_price, discount_curve, dividend_curve, model) v_mc = option.value_mc(valuation_date, stock_price, discount_curve, dividend_curve, model, num_steps_per_year, num_paths) assert round(v, 5) == 4.49627 assert round(v_mc, 5) == 4.44473
def test_DOWN_AND_IN_CASH_AT_HIT(): stock_price = 105.0 downType = TouchOptionTypes.DOWN_AND_IN_CASH_AT_HIT option = EquityOneTouchOption(expiry_date, downType, barrier_level, payment_size) v = option.value(valuation_date, stock_price, discount_curve, dividend_curve, model) v_mc = option.value_mc(valuation_date, stock_price, discount_curve, dividend_curve, model, num_steps_per_year, num_paths) assert round(v, 5) == 10.15381 assert round(v_mc, 5) == 10.20050
def test_UP_AND_OUT_ASSET_OR_NOTHING(): stock_price = 95.0 downType = TouchOptionTypes.UP_AND_OUT_ASSET_OR_NOTHING option = EquityOneTouchOption(expiry_date, downType, barrier_level, payment_size) v = option.value(valuation_date, stock_price, discount_curve, dividend_curve, model) v_mc = option.value_mc(valuation_date, stock_price, discount_curve, dividend_curve, model, num_steps_per_year, num_paths) assert round(v, 5) == 19.19968 assert round(v_mc, 5) == 20.16362
def test_UP_AND_IN_ASSET_AT_HIT(): stock_price = 95.0 downType = TouchOptionTypes.UP_AND_IN_ASSET_AT_HIT option = EquityOneTouchOption(expiry_date, downType, barrier_level, payment_size) v = option.value(valuation_date, stock_price, discount_curve, dividend_curve, model) v_mc = option.value_mc(valuation_date, stock_price, discount_curve, dividend_curve, model, num_steps_per_year, num_paths) assert round(v, 5) == 75.23538 assert round(v_mc, 5) == 73.84206
def test_DOWN_AND_IN_ASSET_AT_EXPIRY(): stock_price = 105.0 downType = TouchOptionTypes.DOWN_AND_IN_ASSET_AT_EXPIRY option = EquityOneTouchOption(expiry_date, downType, barrier_level, payment_size) v = option.value(valuation_date, stock_price, discount_curve, dividend_curve, model) v_mc = option.value_mc(valuation_date, stock_price, discount_curve, dividend_curve, model, num_steps_per_year, num_paths) assert round(v, 5) == 66.91760 assert round(v_mc, 5) == 68.84921
def test_EquityOneTouchOption(): # Examples Haug Page 180 Table 4-22 # Agreement not exact at t is not exactly 0.50 valuation_date = Date(1, 1, 2016) expiry_date = Date(2, 7, 2016) interest_rate = 0.10 volatility = 0.20 barrier_level = 100.0 # H model = BlackScholes(volatility) dividend_yield = 0.03 num_paths = 10000 num_steps_per_year = 252 discount_curve = DiscountCurveFlat(valuation_date, interest_rate) dividend_curve = DiscountCurveFlat(valuation_date, dividend_yield) stock_price = 105.0 payment_size = 15.0 testCases.header("================================= CASH ONLY") downTypes = [ FinTouchOptionPayoffTypes.DOWN_AND_IN_CASH_AT_HIT, FinTouchOptionPayoffTypes.DOWN_AND_IN_CASH_AT_EXPIRY, FinTouchOptionPayoffTypes.DOWN_AND_OUT_CASH_OR_NOTHING ] testCases.header("TYPE", "VALUE", "VALUE_MC") for downType in downTypes: option = EquityOneTouchOption(expiry_date, downType, barrier_level, payment_size) v = option.value(valuation_date, stock_price, discount_curve, dividend_curve, model) v_mc = option.value_mc(valuation_date, stock_price, discount_curve, dividend_curve, model, num_steps_per_year, num_paths) testCases.print("%60s " % downType, "%9.5f" % v, "%9.5f" % v_mc) stock_price = 95.0 payment_size = 15.0 upTypes = [ FinTouchOptionPayoffTypes.UP_AND_IN_CASH_AT_HIT, FinTouchOptionPayoffTypes.UP_AND_IN_CASH_AT_EXPIRY, FinTouchOptionPayoffTypes.UP_AND_OUT_CASH_OR_NOTHING ] testCases.header("TYPE", "VALUE", "VALUE_MC") for upType in upTypes: option = EquityOneTouchOption(expiry_date, upType, barrier_level, payment_size) v = option.value(valuation_date, stock_price, discount_curve, dividend_curve, model) v_mc = option.value_mc(valuation_date, stock_price, discount_curve, dividend_curve, model, num_steps_per_year, num_paths) testCases.print("%60s " % upType, "%9.5f" % v, "%9.5f" % v_mc) ########################################################################### stock_price = 105.0 testCases.banner("================= ASSET ONLY") downTypes = [ FinTouchOptionPayoffTypes.DOWN_AND_IN_ASSET_AT_HIT, FinTouchOptionPayoffTypes.DOWN_AND_IN_ASSET_AT_EXPIRY, FinTouchOptionPayoffTypes.DOWN_AND_OUT_ASSET_OR_NOTHING ] testCases.header("TYPE", "VALUE", "VALUE_MC") for downType in downTypes: option = EquityOneTouchOption(expiry_date, downType, barrier_level) v = option.value(valuation_date, stock_price, discount_curve, dividend_curve, model) v_mc = option.value_mc(valuation_date, stock_price, discount_curve, dividend_curve, model, num_steps_per_year, num_paths) testCases.print("%60s " % downType, "%9.5f" % v, "%9.5f" % v_mc) stock_price = 95.0 upTypes = [ FinTouchOptionPayoffTypes.UP_AND_IN_ASSET_AT_HIT, FinTouchOptionPayoffTypes.UP_AND_IN_ASSET_AT_EXPIRY, FinTouchOptionPayoffTypes.UP_AND_OUT_ASSET_OR_NOTHING ] for upType in upTypes: option = EquityOneTouchOption(expiry_date, upType, barrier_level) v = option.value(valuation_date, stock_price, discount_curve, dividend_curve, model) v_mc = option.value_mc(valuation_date, stock_price, discount_curve, dividend_curve, model, num_steps_per_year, num_paths) testCases.print("%60s " % upType, "%9.5f" % v, "%9.5f" % v_mc)
def test_FinFXOneTouchOption(): # Examples Haug Page 180 Table 4-22 # Agreement not exact at t is not exactly 0.50 valuation_date = Date(1, 1, 2016) expiry_date = Date(2, 7, 2016) volatility = 0.20 barrier_level = 1.0 # H model = BlackScholes(volatility) domesticRate = 0.10 foreignRate = 0.03 num_paths = 20000 num_steps_per_year = 252 domCurve = DiscountCurveFlat(valuation_date, domesticRate) forCurve = DiscountCurveFlat(valuation_date, foreignRate) spot_fx_rate = 1.050 payment_size = 1.5 testCases.header("================================= CASH ONLY") downTypes = [ FinTouchOptionPayoffTypes.DOWN_AND_IN_CASH_AT_HIT, FinTouchOptionPayoffTypes.DOWN_AND_IN_CASH_AT_EXPIRY, FinTouchOptionPayoffTypes.DOWN_AND_OUT_CASH_OR_NOTHING ] testCases.header("TYPE", "VALUE", "VALUE_MC") for downType in downTypes: option = EquityOneTouchOption(expiry_date, downType, barrier_level, payment_size) v = option.value(valuation_date, spot_fx_rate, domCurve, forCurve, model) v_mc = option.value_mc(valuation_date, spot_fx_rate, domCurve, forCurve, model, num_steps_per_year, num_paths) testCases.print("%60s " % downType, "%9.5f" % v, "%9.5f" % v_mc) spot_fx_rate = 0.950 payment_size = 1.5 upTypes = [ FinTouchOptionPayoffTypes.UP_AND_IN_CASH_AT_HIT, FinTouchOptionPayoffTypes.UP_AND_IN_CASH_AT_EXPIRY, FinTouchOptionPayoffTypes.UP_AND_OUT_CASH_OR_NOTHING ] testCases.header("TYPE", "VALUE", "VALUE_MC") for upType in upTypes: option = EquityOneTouchOption(expiry_date, upType, barrier_level, payment_size) v = option.value(valuation_date, spot_fx_rate, domCurve, forCurve, model) v_mc = option.value_mc(valuation_date, spot_fx_rate, domCurve, forCurve, model, num_steps_per_year, num_paths) testCases.print("%60s " % upType, "%9.5f" % v, "%9.5f" % v_mc) ########################################################################### spot_fx_rate = 1.050 testCases.banner("================= ASSET ONLY") downTypes = [ FinTouchOptionPayoffTypes.DOWN_AND_IN_ASSET_AT_HIT, FinTouchOptionPayoffTypes.DOWN_AND_IN_ASSET_AT_EXPIRY, FinTouchOptionPayoffTypes.DOWN_AND_OUT_ASSET_OR_NOTHING ] testCases.header("TYPE", "VALUE", "VALUE_MC") for downType in downTypes: option = EquityOneTouchOption(expiry_date, downType, barrier_level) v = option.value(valuation_date, spot_fx_rate, domCurve, forCurve, model) v_mc = option.value_mc(valuation_date, spot_fx_rate, domCurve, forCurve, model, num_steps_per_year, num_paths) testCases.print("%60s " % downType, "%9.5f" % v, "%9.5f" % v_mc) spot_fx_rate = 0.950 upTypes = [ FinTouchOptionPayoffTypes.UP_AND_IN_ASSET_AT_HIT, FinTouchOptionPayoffTypes.UP_AND_IN_ASSET_AT_EXPIRY, FinTouchOptionPayoffTypes.UP_AND_OUT_ASSET_OR_NOTHING ] for upType in upTypes: option = EquityOneTouchOption(expiry_date, upType, barrier_level) v = option.value(valuation_date, spot_fx_rate, domCurve, forCurve, model) v_mc = option.value_mc(valuation_date, spot_fx_rate, domCurve, forCurve, model, num_steps_per_year, num_paths) testCases.print("%60s " % upType, "%9.5f" % v, "%9.5f" % v_mc)