BillTransactionDefinition implements InstrumentDefinition<BillTransaction> { @Override public BillTransaction toDerivative(final ZonedDateTime date) { ArgumentChecker.notNull(date, "Reference date"); final BillSecurity purchased = _underlying.toDerivative(date, _settlementDate); final BillSecurity standard = _underlying.toDerivative(date); final double amount = (_settlementDate.isBefore(date)) ? 0.0 : _settlementAmount; return new BillTransaction(purchased, _quantity, amount, standard); } BillTransactionDefinition(final BillSecurityDefinition underlying, final double quantity, final ZonedDateTime settlementDate, final double settlementAmount); static BillTransactionDefinition fromYield(final BillSecurityDefinition underlying, final double quantity, final ZonedDateTime settlementDate, final double yield,
      final Calendar calendar); BillSecurityDefinition getUnderlying(); double getQuantity(); ZonedDateTime getSettlementDate(); double getSettlementAmount(); @Override String toString(); @Override BillTransaction 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 toDerivativeStandard() { final ZonedDateTime referenceDateStandard = ScheduleCalculator.getAdjustedDate(SETTLE_DATE, -SETTLEMENT_DAYS, CALENDAR); final BillTransaction transactionConverted1 = BILL_TRA_DEFINITION.toDerivative(referenceDateStandard); final BillSecurity purchased1 = BILL_SEC_DEFINITION.toDerivative(referenceDateStandard, SETTLE_DATE); final BillSecurity standard1 = BILL_SEC_DEFINITION.toDerivative(referenceDateStandard); final BillTransaction transactionExpected1 = new BillTransaction(purchased1, QUANTITY, SETTLE_AMOUNT, standard1); assertEquals("Bill Transaction: toDerivatives", transactionExpected1, transactionConverted1); }
@Test public void toDerivativeEarly() { final ZonedDateTime referenceDateEarly = ScheduleCalculator.getAdjustedDate(SETTLE_DATE, -(SETTLEMENT_DAYS + 1), CALENDAR); final BillTransaction transactionConverted2 = BILL_TRA_DEFINITION.toDerivative(referenceDateEarly); final BillSecurity purchased2 = BILL_SEC_DEFINITION.toDerivative(referenceDateEarly, SETTLE_DATE); final BillSecurity standard2 = BILL_SEC_DEFINITION.toDerivative(referenceDateEarly); final BillTransaction transactionExpected2 = new BillTransaction(purchased2, QUANTITY, SETTLE_AMOUNT, standard2); assertEquals("Bill Transaction: toDerivatives", transactionExpected2, transactionConverted2); }
@Test public void toDerivativeAtSettle() { final ZonedDateTime referenceDate = SETTLE_DATE; final BillTransaction transactionConverted = BILL_TRA_DEFINITION.toDerivative(referenceDate); final BillSecurity purchased = BILL_SEC_DEFINITION.toDerivative(referenceDate, SETTLE_DATE); final BillSecurity standard = BILL_SEC_DEFINITION.toDerivative(referenceDate); final BillTransaction transactionExpected = new BillTransaction(purchased, QUANTITY, SETTLE_AMOUNT, standard); assertEquals("Bill Transaction: toDerivatives", transactionExpected, transactionConverted); }
@Test public void toDerivativeBetweenSettleAndMaturity() { final ZonedDateTime referenceDate = ScheduleCalculator.getAdjustedDate(SETTLE_DATE, SETTLEMENT_DAYS, CALENDAR); final BillTransaction transactionConverted = BILL_TRA_DEFINITION.toDerivative(referenceDate); final BillSecurity purchased = BILL_SEC_DEFINITION.toDerivative(referenceDate, SETTLE_DATE); final BillSecurity standard = BILL_SEC_DEFINITION.toDerivative(referenceDate); final BillTransaction transactionExpected = new BillTransaction(purchased, QUANTITY, 0.0, standard); assertEquals("Bill Transaction: toDerivatives", transactionExpected, transactionConverted); }
@Test public void toDerivativeBetweenJustBeforeMaturity() { final ZonedDateTime referenceDate = ScheduleCalculator.getAdjustedDate(END_DATE, -1, CALENDAR); final BillTransaction transactionConverted = BILL_TRA_DEFINITION.toDerivative(referenceDate); final BillSecurity purchased = BILL_SEC_DEFINITION.toDerivative(referenceDate, SETTLE_DATE); final BillSecurity standard = BILL_SEC_DEFINITION.toDerivative(referenceDate); final BillTransaction transactionExpected = new BillTransaction(purchased, QUANTITY, 0.0, standard); assertEquals("Bill Transaction: toDerivatives", transactionExpected, transactionConverted); }
@Test public void toDerivativeBetweenAtMaturity() { final ZonedDateTime referenceDate = END_DATE; final BillTransaction transactionConverted = BILL_TRA_DEFINITION.toDerivative(referenceDate); final BillSecurity purchased = BILL_SEC_DEFINITION.toDerivative(referenceDate, SETTLE_DATE); final BillSecurity standard = BILL_SEC_DEFINITION.toDerivative(referenceDate); final BillTransaction transactionExpected = new BillTransaction(purchased, QUANTITY, 0.0, standard); assertEquals("Bill Transaction: toDerivatives", transactionExpected, transactionConverted); }