ForexOptionVanillaDefinition implements InstrumentDefinition<InstrumentDerivative> { @Override public ForexOptionVanilla toDerivative(final ZonedDateTime date) { ArgumentChecker.notNull(date, "date"); final Forex fx = _underlyingForex.toDerivative(date); final double expirationTime = TimeCalculator.getTimeBetween(date, _expirationDate); return new ForexOptionVanilla(fx, expirationTime, _isCall, _isLong); } ForexOptionVanillaDefinition(final ForexDefinition forex, final ZonedDateTime expirationDate, final boolean isCall, final boolean isLong); ForexDefinition getUnderlyingForex(); ZonedDateTime getExpirationDate(); boolean isCall(); boolean isLong(); @Override ForexOptionVanilla 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 testNullConversionDate() { final ForexOptionVanillaDefinition option = new ForexOptionVanillaDefinition(FX_DEFINITION, EXPIRATION_DATE, IS_CALL, IS_LONG); option.toDerivative(EXPIRATION_DATE.plusDays(10)); }
@Test public void toDerivative() { final ZonedDateTime referenceDate = DateUtils.getUTCDate(2011, 5, 20); final InstrumentDerivative optionConverted = FX_OPTION_DEFINITION.toDerivative(referenceDate); final Forex fx = FX_DEFINITION.toDerivative(referenceDate); final DayCount actAct = DayCounts.ACT_ACT_ISDA; final double expirationTime = actAct.getDayCountFraction(referenceDate, EXPIRATION_DATE); final ForexOptionVanilla optionConstructed = new ForexOptionVanilla(fx, expirationTime, IS_CALL, IS_LONG); assertEquals("Convertion to derivative", optionConstructed, optionConverted); }