EnergyFutureOptionDefinition extends CommodityFutureOptionDefinition<EnergyFutureDefinition, EnergyFutureOption> { @Override public EnergyFutureOption toDerivative(final ZonedDateTime date) { ArgumentChecker.inOrderOrEqual(date, this.getExpiryDate(), "date", "expiry date"); final double timeToFixing = TimeCalculator.getTimeBetween(date, this.getExpiryDate()); return new EnergyFutureOption(timeToFixing, getUnderlying().toDerivative(date), getStrike(), getExerciseType(), isCall()); } EnergyFutureOptionDefinition(final ZonedDateTime expiryDate, final EnergyFutureDefinition underlying, final double strike, final ExerciseDecisionType exerciseType,
      final boolean isCall); @Override EnergyFutureOption toDerivative(final ZonedDateTime date); @Override V accept(final InstrumentDefinitionVisitor<U, V> visitor, final U data); @Override V accept(final InstrumentDefinitionVisitor<?, V> visitor); @Override int hashCode(); @Override boolean equals(final Object obj);  }
@Test public void testToDerivative() { EnergyFutureOptionDefinition first = new EnergyFutureOptionDefinition(EXPIRY_DATE, AN_UNDERLYING, 100, ExerciseDecisionType.EUROPEAN, true); EnergyFutureOptionDefinition second = new EnergyFutureOptionDefinition(EXPIRY_DATE, AN_UNDERLYING, 100, ExerciseDecisionType.AMERICAN, false); EnergyFutureOption firstDerivative = first.toDerivative(A_DATE); EnergyFutureOption secondDerivative = second.toDerivative(A_DATE); assertEquals(firstDerivative.getStrike(), 100.); assertEquals(firstDerivative.getExerciseType(), ExerciseDecisionType.EUROPEAN); assertEquals(firstDerivative.getUnderlying(), AN_UNDERLYING.toDerivative(A_DATE)); assertTrue(firstDerivative.isCall()); assertEquals(secondDerivative.getExerciseType(), ExerciseDecisionType.AMERICAN); assertFalse(secondDerivative.isCall()); EnergyFutureOption firstDerivative2 = new EnergyFutureOption(0.0027397260273972603, AN_UNDERLYING.toDerivative(A_DATE), 100, ExerciseDecisionType.EUROPEAN, true); assertEquals(firstDerivative.hashCode(), firstDerivative2.hashCode()); assertEquals(firstDerivative, firstDerivative2); }