EnergyFutureDefinition extends CommodityFutureDefinition<EnergyFuture> { @Override public EnergyFuture toDerivative(final ZonedDateTime date) { ArgumentChecker.inOrderOrEqual(date, this.getExpiryDate(), "date", "expiry date"); final double timeToFixing = TimeCalculator.getTimeBetween(date, this.getExpiryDate()); final double timeToSettlement = TimeCalculator.getTimeBetween(date, this.getSettlementDate()); return new EnergyFuture(timeToFixing, getUnderlying(), getUnitAmount(), getFirstDeliveryDate(), getLastDeliveryDate(), getAmount(), getUnitName(), getSettlementType(), timeToSettlement, getReferencePrice(), getCurrency()); } EnergyFutureDefinition(final ZonedDateTime expiryDate, final ExternalId underlying, final double unitAmount, final ZonedDateTime firstDeliveryDate,
      final ZonedDateTime lastDeliveryDate, final double amount, final String unitName,
      final SettlementType settlementType, final double referencePrice, final Currency currency, final ZonedDateTime settlementDate);  EnergyFutureDefinition(final ZonedDateTime expiryDate, final ExternalId underlying, final double unitAmount, final double amount, final String unitName, final double referencePrice,
      final Currency currency, final ZonedDateTime settlementDate); static EnergyFutureDefinition withCashSettlement(final ZonedDateTime expiryDate, final ExternalId underlying, final double unitAmount, final double amount, final String unitName,
      final double referencePrice, final Currency currency, final ZonedDateTime settlementDate); static EnergyFutureDefinition withPhysicalSettlement(final ZonedDateTime expiryDate, final ExternalId underlying, final double unitAmount,
      final ZonedDateTime firstDeliveryDate, final ZonedDateTime lastDeliveryDate, final double amount, final String unitName, final double referencePrice,
      final Currency currency, final ZonedDateTime settlementDate); @Override EnergyFuture toDerivative(final ZonedDateTime date); @Override EnergyFuture toDerivative(final ZonedDateTime date, final Double referencePrice); @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() { EnergyFutureDefinition first = new EnergyFutureDefinition(EXPIRY_DATE, AN_UNDERLYING, 100., null, null, 1000., "tonnes", SettlementType.CASH, 0, Currency.GBP, SETTLEMENT_DATE); EnergyFutureDefinition second = new EnergyFutureDefinition(EXPIRY_DATE, AN_UNDERLYING, 100., FIRST_DELIVERY_DATE, LAST_DELIVERY_DATE, 1000., "tonnes", SettlementType.PHYSICAL, 0, Currency.GBP, SETTLEMENT_DATE); EnergyFuture firstDerivative = first.toDerivative(A_DATE); EnergyFuture secondDerivative = second.toDerivative(A_DATE); assertEquals(firstDerivative.getAmount(), 1000.); assertEquals(firstDerivative.getUnitAmount(), 100.); assertEquals(firstDerivative.getUnitName(), "tonnes"); assertEquals(firstDerivative.getExpiry(), 0.0027397260273972603); assertNull(firstDerivative.getFirstDeliveryDate()); assertNull(firstDerivative.getLastDeliveryDate()); assertEquals(firstDerivative.getSettlementType(), SettlementType.CASH); assertEquals(firstDerivative.getUnderlying(), AN_UNDERLYING); assertEquals(secondDerivative.getFirstDeliveryDate(), FIRST_DELIVERY_DATE); assertEquals(secondDerivative.getLastDeliveryDate(), LAST_DELIVERY_DATE); assertEquals(secondDerivative.getSettlementType(), SettlementType.PHYSICAL); EnergyFuture firstDerivative2 = new EnergyFuture(0.0027397260273972603, AN_UNDERLYING, 100, null, null, 1000, "tonnes", SettlementType.CASH, 1.0035032562317538, 0, Currency.GBP); assertEquals(firstDerivative.hashCode(), firstDerivative2.hashCode()); assertEquals(firstDerivative, firstDerivative2); }