AgricultureFutureOptionDefinition extends CommodityFutureOptionDefinition<AgricultureFutureDefinition, AgricultureFutureOption> { @Override public AgricultureFutureOption toDerivative(final ZonedDateTime date) { ArgumentChecker.inOrderOrEqual(date, this.getExpiryDate(), "date", "expiry date"); final double timeToFixing = TimeCalculator.getTimeBetween(date, this.getExpiryDate()); final AgricultureFuture underlyingDeriv = getUnderlying().toDerivative(date); return new AgricultureFutureOption(timeToFixing, underlyingDeriv, getStrike(), getExerciseType(), isCall()); } AgricultureFutureOptionDefinition(final ZonedDateTime expiryDate, final AgricultureFutureDefinition underlying, final double strike,
      final ExerciseDecisionType exerciseType, final boolean isCall); @Override AgricultureFutureOption 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() { AgricultureFutureOptionDefinition first = new AgricultureFutureOptionDefinition(EXPIRY_DATE, AN_UNDERLYING, 100, ExerciseDecisionType.EUROPEAN, true); AgricultureFutureOptionDefinition second = new AgricultureFutureOptionDefinition(EXPIRY_DATE, AN_UNDERLYING, 100, ExerciseDecisionType.AMERICAN, false); AgricultureFutureOption firstDerivative = first.toDerivative(A_DATE); AgricultureFutureOption 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()); AgricultureFutureOption firstDerivative2 = new AgricultureFutureOption(0.0027397260273972603, AN_UNDERLYING.toDerivative(A_DATE), 100, ExerciseDecisionType.EUROPEAN, true); assertEquals(firstDerivative.hashCode(), firstDerivative2.hashCode()); assertEquals(firstDerivative, firstDerivative2); }