BillTransactionDefinition implements InstrumentDefinition<BillTransaction> { public static BillTransactionDefinition fromYield(final BillSecurityDefinition underlying, final double quantity, final ZonedDateTime settlementDate, final double yield, final Calendar calendar) { ArgumentChecker.notNull(underlying, "Underlying"); ArgumentChecker.notNull(settlementDate, "Settlement date"); final double accrualFactor = underlying.getDayCount().getDayCountFraction(settlementDate, underlying.getEndDate(), calendar); final double settlementAmount = -quantity * underlying.getNotional() * PriceFromYieldCalculator.priceFromYield(underlying.getYieldConvention(), yield, accrualFactor); return new BillTransactionDefinition(underlying, quantity, settlementDate, settlementAmount); } 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 fromYield() { final double yield = 0.0020; final double accrualFactor = ACT360.getDayCountFraction(SETTLE_DATE, END_DATE); final double price = METHOD_BILL_SECURITY.priceFromYield(YIELD_CONVENTION, yield, accrualFactor); final double settlementAmount = -QUANTITY * price * NOTIONAL; final BillTransactionDefinition from = BillTransactionDefinition.fromYield(BILL_SEC_DEFINITION, QUANTITY, SETTLE_DATE, yield, CALENDAR); final BillTransactionDefinition constructed = new BillTransactionDefinition(BILL_SEC_DEFINITION, QUANTITY, SETTLE_DATE, settlementAmount); assertEquals("Bill Transaction Definition: fromYield", constructed, from); }