EquityIndexOptionDefinition implements InstrumentDefinition<EquityIndexOption> { @Override public EquityIndexOption toDerivative(final ZonedDateTime date) { ArgumentChecker.notNull(date, "date"); ArgumentChecker.inOrderOrEqual(date.toLocalDate(), getExpiryDate().toLocalDate(), "valuation date", "expiry"); double timeToExpiry = TimeCalculator.getTimeBetween(date, getExpiryDate()); if (timeToExpiry == 0) { timeToExpiry = 0.0015; } double timeToSettlement = TimeCalculator.getTimeBetween(date, _settlementDate); if (timeToSettlement == 0) { timeToSettlement = 0.0015; } return new EquityIndexOption(timeToExpiry, timeToSettlement, _strike, _isCall, _currency, _pointValue, _exerciseType, _settlementType); } EquityIndexOptionDefinition(final boolean isCall, final double strike, final Currency currency, final ExerciseDecisionType exerciseType,
      final ZonedDateTime expiryDT, final LocalDate settlementDate, final double pointValue, final SettlementType settlementType); boolean isCall(); double getStrike(); Currency getCurrency(); ExerciseDecisionType getExerciseType(); ZonedDateTime getExpiryDate(); LocalDate getSettlementDate(); double getPointValue(); SettlementType getSettlementType(); @Override EquityIndexOption 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(expectedExceptions = IllegalArgumentException.class) public void testNullValuationDate() { AMERICAN_PUT.toDerivative(null); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testValuationAfterExpiry() { AMERICAN_PUT.toDerivative(EXPIRY.plusDays(1)); }
@Test public void testToDerivative() { final ZonedDateTime valuationDate = EXPIRY.minusDays(10); final EquityIndexOption derivative = AMERICAN_PUT.toDerivative(valuationDate); assertEquals(STRIKE, derivative.getStrike()); assertEquals(10. / 365, derivative.getTimeToExpiry()); assertEquals(13. / 365, derivative.getTimeToSettlement()); assertEquals(POINT_VALUE, derivative.getUnitAmount()); assertEquals(IS_CALL, derivative.isCall()); assertEquals(CCY, derivative.getCurrency()); assertEquals(SETTLEMENT_TYPE, derivative.getSettlementType()); assertEquals(EXERCISE, derivative.getExerciseType()); }