EuropeanStandardBarrierOptionDefinition extends OptionDefinition { @Override public OptionPayoffFunction<StandardOptionDataBundle> getPayoffFunction() { return _payoffFunction; } EuropeanStandardBarrierOptionDefinition(final double strike, final Expiry expiry, final boolean isCall, final Barrier barrier);  EuropeanStandardBarrierOptionDefinition(final double strike, final Expiry expiry, final boolean isCall, final Barrier barrier, final double rebate); Barrier getBarrier(); double getRebate(); @Override OptionExerciseFunction<StandardOptionDataBundle> getExerciseFunction(); @Override OptionPayoffFunction<StandardOptionDataBundle> getPayoffFunction(); @Override String toString(); @Override int hashCode(); @Override boolean equals(final Object obj);  }
@Test public void testPayoffNoRebate() { final double barrierDelta = 10; final double delta = 20; EuropeanStandardBarrierOptionDefinition call = new EuropeanStandardBarrierOptionDefinition(STRIKE, EXPIRY, true, new Barrier(KnockType.IN, BarrierType.DOWN, ObservationType.CONTINUOUS, STRIKE - barrierDelta)); EuropeanStandardBarrierOptionDefinition put = new EuropeanStandardBarrierOptionDefinition(STRIKE, EXPIRY, false, new Barrier(KnockType.IN, BarrierType.DOWN, ObservationType.CONTINUOUS, STRIKE - barrierDelta)); StandardOptionDataBundle data = DATA.withSpot(STRIKE + delta); assertEquals(call.getPayoffFunction().getPayoff(data, null), 0, 0); assertEquals(put.getPayoffFunction().getPayoff(data, null), 0, 0); data = DATA.withSpot(STRIKE - delta); assertEquals(call.getPayoffFunction().getPayoff(data, null), 0, 0); assertEquals(put.getPayoffFunction().getPayoff(data, null), delta, 0); call = new EuropeanStandardBarrierOptionDefinition(STRIKE, EXPIRY, true, new Barrier(KnockType.IN, BarrierType.DOWN, ObservationType.CONTINUOUS, STRIKE + barrierDelta)); put = new EuropeanStandardBarrierOptionDefinition(STRIKE, EXPIRY, false, new Barrier(KnockType.IN, BarrierType.DOWN, ObservationType.CONTINUOUS, STRIKE + barrierDelta)); data = data.withSpot(STRIKE - delta); assertEquals(call.getPayoffFunction().getPayoff(data, null), 0, 0); assertEquals(put.getPayoffFunction().getPayoff(data, null), delta, 0); data = DATA.withSpot(STRIKE + delta); assertEquals(call.getPayoffFunction().getPayoff(data, null), delta, 0); assertEquals(put.getPayoffFunction().getPayoff(data, null), 0, 0); call = new EuropeanStandardBarrierOptionDefinition(STRIKE, EXPIRY, true, new Barrier(KnockType.IN, BarrierType.UP, ObservationType.CONTINUOUS, STRIKE - barrierDelta)); put = new EuropeanStandardBarrierOptionDefinition(STRIKE, EXPIRY, false, new Barrier(KnockType.IN, BarrierType.UP, ObservationType.CONTINUOUS, STRIKE - barrierDelta)); data = data.withSpot(STRIKE - delta); assertEquals(call.getPayoffFunction().getPayoff(data, null), 0, 0); assertEquals(put.getPayoffFunction().getPayoff(data, null), 0, 0); data = DATA.withSpot(STRIKE + delta); assertEquals(call.getPayoffFunction().getPayoff(data, null), delta, 0); assertEquals(put.getPayoffFunction().getPayoff(data, null), 0, 0); call = new EuropeanStandardBarrierOptionDefinition(STRIKE, EXPIRY, true, new Barrier(KnockType.IN, BarrierType.UP, ObservationType.CONTINUOUS, STRIKE + barrierDelta)); put = new EuropeanStandardBarrierOptionDefinition(STRIKE, EXPIRY, false, new Barrier(KnockType.IN, BarrierType.UP, ObservationType.CONTINUOUS, STRIKE + barrierDelta)); data = data.withSpot(STRIKE - delta); assertEquals(call.getPayoffFunction().getPayoff(data, null), 0, 0); assertEquals(put.getPayoffFunction().getPayoff(data, null), 0, 0); data = DATA.withSpot(STRIKE + delta); assertEquals(call.getPayoffFunction().getPayoff(data, null), delta, 0); assertEquals(put.getPayoffFunction().getPayoff(data, null), 0, 0); call = new EuropeanStandardBarrierOptionDefinition(STRIKE, EXPIRY, true, new Barrier(KnockType.OUT, BarrierType.DOWN, ObservationType.CONTINUOUS, STRIKE - barrierDelta)); put = new EuropeanStandardBarrierOptionDefinition(STRIKE, EXPIRY, false, new Barrier(KnockType.OUT, BarrierType.DOWN, ObservationType.CONTINUOUS, STRIKE - barrierDelta)); data = DATA.withSpot(STRIKE + delta); assertEquals(call.getPayoffFunction().getPayoff(data, null), delta, 0); assertEquals(put.getPayoffFunction().getPayoff(data, null), 0, 0); data = DATA.withSpot(STRIKE - delta); assertEquals(call.getPayoffFunction().getPayoff(data, null), 0, 0); assertEquals(put.getPayoffFunction().getPayoff(data, null), 0, 0); call = new EuropeanStandardBarrierOptionDefinition(STRIKE, EXPIRY, true, new Barrier(KnockType.OUT, BarrierType.DOWN, ObservationType.CONTINUOUS, STRIKE + barrierDelta)); put = new EuropeanStandardBarrierOptionDefinition(STRIKE, EXPIRY, false, new Barrier(KnockType.OUT, BarrierType.DOWN, ObservationType.CONTINUOUS, STRIKE + barrierDelta)); data = data.withSpot(STRIKE - delta); assertEquals(call.getPayoffFunction().getPayoff(data, null), 0, 0); assertEquals(put.getPayoffFunction().getPayoff(data, null), 0, 0); data = DATA.withSpot(STRIKE + delta); assertEquals(call.getPayoffFunction().getPayoff(data, null), 0, 0); assertEquals(put.getPayoffFunction().getPayoff(data, null), 0, 0); call = new EuropeanStandardBarrierOptionDefinition(STRIKE, EXPIRY, true, new Barrier(KnockType.OUT, BarrierType.UP, ObservationType.CONTINUOUS, STRIKE - barrierDelta)); put = new EuropeanStandardBarrierOptionDefinition(STRIKE, EXPIRY, false, new Barrier(KnockType.OUT, BarrierType.UP, ObservationType.CONTINUOUS, STRIKE - barrierDelta)); data = data.withSpot(STRIKE - delta); assertEquals(call.getPayoffFunction().getPayoff(data, null), 0, 0); assertEquals(put.getPayoffFunction().getPayoff(data, null), delta, 0); data = DATA.withSpot(STRIKE + delta); assertEquals(call.getPayoffFunction().getPayoff(data, null), 0, 0); assertEquals(put.getPayoffFunction().getPayoff(data, null), 0, 0); call = new EuropeanStandardBarrierOptionDefinition(STRIKE, EXPIRY, true, new Barrier(KnockType.OUT, BarrierType.UP, ObservationType.CONTINUOUS, STRIKE + barrierDelta)); put = new EuropeanStandardBarrierOptionDefinition(STRIKE, EXPIRY, false, new Barrier(KnockType.OUT, BarrierType.UP, ObservationType.CONTINUOUS, STRIKE + barrierDelta)); data = data.withSpot(STRIKE - delta); assertEquals(call.getPayoffFunction().getPayoff(data, null), 0, 0); assertEquals(put.getPayoffFunction().getPayoff(data, null), delta, 0); data = DATA.withSpot(STRIKE + delta); assertEquals(call.getPayoffFunction().getPayoff(data, null), 0, 0); assertEquals(put.getPayoffFunction().getPayoff(data, null), 0, 0); }
@Test public void testPayoffWithRebate() { final double barrierDelta = 10; final double delta = 20; EuropeanStandardBarrierOptionDefinition call = new EuropeanStandardBarrierOptionDefinition(STRIKE, EXPIRY, true, new Barrier(KnockType.IN, BarrierType.DOWN, ObservationType.CONTINUOUS, STRIKE - barrierDelta), REBATE); EuropeanStandardBarrierOptionDefinition put = new EuropeanStandardBarrierOptionDefinition(STRIKE, EXPIRY, false, new Barrier(KnockType.IN, BarrierType.DOWN, ObservationType.CONTINUOUS, STRIKE - barrierDelta), REBATE); StandardOptionDataBundle data = DATA.withSpot(STRIKE + delta); assertEquals(call.getPayoffFunction().getPayoff(data, null), REBATE, 0); assertEquals(put.getPayoffFunction().getPayoff(data, null), REBATE, 0); data = DATA.withSpot(STRIKE - delta); assertEquals(call.getPayoffFunction().getPayoff(data, null), 0, 0); assertEquals(put.getPayoffFunction().getPayoff(data, null), delta, 0); call = new EuropeanStandardBarrierOptionDefinition(STRIKE, EXPIRY, true, new Barrier(KnockType.IN, BarrierType.DOWN, ObservationType.CONTINUOUS, STRIKE + barrierDelta), REBATE); put = new EuropeanStandardBarrierOptionDefinition(STRIKE, EXPIRY, false, new Barrier(KnockType.IN, BarrierType.DOWN, ObservationType.CONTINUOUS, STRIKE + barrierDelta), REBATE); data = data.withSpot(STRIKE - delta); assertEquals(call.getPayoffFunction().getPayoff(data, null), 0, 0); assertEquals(put.getPayoffFunction().getPayoff(data, null), delta, 0); data = DATA.withSpot(STRIKE + delta); assertEquals(call.getPayoffFunction().getPayoff(data, null), delta, 0); assertEquals(put.getPayoffFunction().getPayoff(data, null), 0, 0); call = new EuropeanStandardBarrierOptionDefinition(STRIKE, EXPIRY, true, new Barrier(KnockType.IN, BarrierType.UP, ObservationType.CONTINUOUS, STRIKE - barrierDelta), REBATE); put = new EuropeanStandardBarrierOptionDefinition(STRIKE, EXPIRY, false, new Barrier(KnockType.IN, BarrierType.UP, ObservationType.CONTINUOUS, STRIKE - barrierDelta), REBATE); data = data.withSpot(STRIKE - delta); assertEquals(call.getPayoffFunction().getPayoff(data, null), REBATE, 0); assertEquals(put.getPayoffFunction().getPayoff(data, null), REBATE, 0); data = DATA.withSpot(STRIKE + delta); assertEquals(call.getPayoffFunction().getPayoff(data, null), delta, 0); assertEquals(put.getPayoffFunction().getPayoff(data, null), 0, 0); call = new EuropeanStandardBarrierOptionDefinition(STRIKE, EXPIRY, true, new Barrier(KnockType.IN, BarrierType.UP, ObservationType.CONTINUOUS, STRIKE + barrierDelta), REBATE); put = new EuropeanStandardBarrierOptionDefinition(STRIKE, EXPIRY, false, new Barrier(KnockType.IN, BarrierType.UP, ObservationType.CONTINUOUS, STRIKE + barrierDelta), REBATE); data = data.withSpot(STRIKE - delta); assertEquals(call.getPayoffFunction().getPayoff(data, null), REBATE, 0); assertEquals(put.getPayoffFunction().getPayoff(data, null), REBATE, 0); data = DATA.withSpot(STRIKE + delta); assertEquals(call.getPayoffFunction().getPayoff(data, null), delta, 0); assertEquals(put.getPayoffFunction().getPayoff(data, null), 0, 0); call = new EuropeanStandardBarrierOptionDefinition(STRIKE, EXPIRY, true, new Barrier(KnockType.OUT, BarrierType.DOWN, ObservationType.CONTINUOUS, STRIKE - barrierDelta), REBATE); put = new EuropeanStandardBarrierOptionDefinition(STRIKE, EXPIRY, false, new Barrier(KnockType.OUT, BarrierType.DOWN, ObservationType.CONTINUOUS, STRIKE - barrierDelta), REBATE); data = DATA.withSpot(STRIKE + delta); assertEquals(call.getPayoffFunction().getPayoff(data, null), delta, 0); assertEquals(put.getPayoffFunction().getPayoff(data, null), 0, 0); data = DATA.withSpot(STRIKE - delta); assertEquals(call.getPayoffFunction().getPayoff(data, null), REBATE, 0); assertEquals(put.getPayoffFunction().getPayoff(data, null), REBATE, 0); call = new EuropeanStandardBarrierOptionDefinition(STRIKE, EXPIRY, true, new Barrier(KnockType.OUT, BarrierType.DOWN, ObservationType.CONTINUOUS, STRIKE + barrierDelta), REBATE); put = new EuropeanStandardBarrierOptionDefinition(STRIKE, EXPIRY, false, new Barrier(KnockType.OUT, BarrierType.DOWN, ObservationType.CONTINUOUS, STRIKE + barrierDelta), REBATE); data = data.withSpot(STRIKE - delta); assertEquals(call.getPayoffFunction().getPayoff(data, null), REBATE, 0); assertEquals(put.getPayoffFunction().getPayoff(data, null), REBATE, 0); data = DATA.withSpot(STRIKE + delta); assertEquals(call.getPayoffFunction().getPayoff(data, null), REBATE, 0); assertEquals(put.getPayoffFunction().getPayoff(data, null), REBATE, 0); call = new EuropeanStandardBarrierOptionDefinition(STRIKE, EXPIRY, true, new Barrier(KnockType.OUT, BarrierType.UP, ObservationType.CONTINUOUS, STRIKE - barrierDelta), REBATE); put = new EuropeanStandardBarrierOptionDefinition(STRIKE, EXPIRY, false, new Barrier(KnockType.OUT, BarrierType.UP, ObservationType.CONTINUOUS, STRIKE - barrierDelta), REBATE); data = data.withSpot(STRIKE - delta); assertEquals(call.getPayoffFunction().getPayoff(data, null), 0, 0); assertEquals(put.getPayoffFunction().getPayoff(data, null), delta, 0); data = DATA.withSpot(STRIKE + delta); assertEquals(call.getPayoffFunction().getPayoff(data, null), REBATE, 0); assertEquals(put.getPayoffFunction().getPayoff(data, null), REBATE, 0); call = new EuropeanStandardBarrierOptionDefinition(STRIKE, EXPIRY, true, new Barrier(KnockType.OUT, BarrierType.UP, ObservationType.CONTINUOUS, STRIKE + barrierDelta), REBATE); put = new EuropeanStandardBarrierOptionDefinition(STRIKE, EXPIRY, false, new Barrier(KnockType.OUT, BarrierType.UP, ObservationType.CONTINUOUS, STRIKE + barrierDelta), REBATE); data = data.withSpot(STRIKE - delta); assertEquals(call.getPayoffFunction().getPayoff(data, null), 0, 0); assertEquals(put.getPayoffFunction().getPayoff(data, null), delta, 0); data = DATA.withSpot(STRIKE + delta); assertEquals(call.getPayoffFunction().getPayoff(data, null), REBATE, 0); assertEquals(put.getPayoffFunction().getPayoff(data, null), REBATE, 0); }