@Test public void testExerciseFunction() { StandardOptionDataBundle data = DATA.withSpot(STRIKE + DELTA); assertFalse(CALL.getExerciseFunction().shouldExercise(data, null)); assertFalse(PUT.getExerciseFunction().shouldExercise(data, null)); data = DATA.withSpot(STRIKE - DELTA); assertFalse(CALL.getExerciseFunction().shouldExercise(data, null)); assertFalse(PUT.getExerciseFunction().shouldExercise(data, null)); }
@Test public void testPayoffFunction() { assertEquals(CALL.getPayoffFunction().getPayoff(DATA, null), 0, 0); assertEquals(PUT.getPayoffFunction().getPayoff(DATA, null), 0, 0); double spot = STRIKE + DELTA; StandardOptionDataBundle data = DATA.withSpot(spot); assertEquals(CALL.getPayoffFunction().getPayoff(data, null), spot - PAYOFF_STRIKE, 0); assertEquals(PUT.getPayoffFunction().getPayoff(data, null), 0, 0); spot = STRIKE - DELTA; data = DATA.withSpot(spot); assertEquals(CALL.getPayoffFunction().getPayoff(data, null), 0, 0); assertEquals(PUT.getPayoffFunction().getPayoff(data, null), PAYOFF_STRIKE - spot, 0); }
@Override public double getPayoff(final StandardOptionDataBundle data, final Double optionPrice) { Validate.notNull(data); final double spot = data.getSpot(); return isCall() ? Math.pow(Math.max(0, spot - getStrike()), getPower()) : Math.pow(Math.max(0, getStrike() - spot), getPower()); }