BondFixedTransactionDefinition extends BondTransactionDefinition<PaymentFixedDefinition, CouponFixedDefinition> { @Override public BondFixedTransaction toDerivative(final ZonedDateTime date) { ArgumentChecker.notNull(date, "date"); final ZonedDateTime spot = ScheduleCalculator.getAdjustedDate(date, getUnderlyingBond().getSettlementDays(), getUnderlyingBond().getCalendar()); final BondFixedSecurity bondPurchase = getUnderlyingBond().toDerivative(date, getSettlementDate()); final BondFixedSecurity bondStandard = getUnderlyingBond().toDerivative(date); final int nbCoupon = getUnderlyingBond().getCoupons().getNumberOfPayments(); int couponIndex = 0; for (int loopcpn = 0; loopcpn < nbCoupon; loopcpn++) { if (getUnderlyingBond().getCoupons().getNthPayment(loopcpn).getAccrualEndDate().isAfter(spot)) { couponIndex = loopcpn; break; } } final double notionalStandard = getUnderlyingBond().getCoupons().getNthPayment(couponIndex).getNotional(); double price; if (getSettlementDate().toLocalDate().isBefore(date.toLocalDate())) { price = 0.0; } else { price = getPrice(); } final BondFixedTransaction result = new BondFixedTransaction(bondPurchase, getQuantity(), price, bondStandard, notionalStandard); return result; } BondFixedTransactionDefinition(final BondFixedSecurityDefinition underlyingBond, final double quantity, 
      final ZonedDateTime settlementDate, final double cleanPrice); static BondFixedTransactionDefinition fromYield(final BondFixedSecurityDefinition underlyingBond, 
      final double quantity, final ZonedDateTime settlementDate, final double yield); double getAccruedInterestAtSettlement(); @Override BondFixedSecurityDefinition getUnderlyingBond(); @Override BondFixedTransaction 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 toDerivatives() { final BondFixedSecurity bondSecurityStandard = BOND_SECURITY_DEFINITION.toDerivative(REFERENCE_DATE_1); final BondFixedTransaction bondTransaction = BOND_TRANSACTION_DEFINITION.toDerivative(REFERENCE_DATE_1); assertEquals("Bond transaction: toDerivative", bondSecurityStandard, bondTransaction.getBondStandard()); final BondFixedSecurity bondSecurityPurchase = BOND_SECURITY_DEFINITION.toDerivative(REFERENCE_DATE_1, SETTLEMENT_DATE); assertEquals("Bond transaction: toDerivative", bondSecurityPurchase.getAccruedInterest(), bondTransaction.getBondTransaction().getAccruedInterest()); assertEquals("Bond transaction: toDerivative", bondSecurityPurchase.getCouponPerYear(), bondTransaction.getBondTransaction().getCouponPerYear()); assertEquals("Bond transaction: toDerivative", bondSecurityPurchase.getYieldConvention(), bondTransaction.getBondTransaction().getYieldConvention()); }
@Test public void longFirstCouponMon() { final double notional = 1000000; final ZonedDateTime settle090410 = DateUtils.getUTCDate(2009, 04, 10); final double accrual090410 = 4429.95; BondFixedSecurity bond090410 = BOND_MON_SECURITY_DEFINITION.toDerivative(settle090410, settle090410); assertEquals("Bond transaction: accrued", accrual090410, bond090410.getAccruedInterest() * notional, TOLERANCE_ACCRUED); final ZonedDateTime settle091010 = DateUtils.getUTCDate(2009, 10, 10); final double accrual091010 = 31354.97; BondFixedSecurity bond091010 = BOND_MON_SECURITY_DEFINITION.toDerivative(settle091010, settle091010); assertEquals("Bond transaction: accrued", accrual091010, bond091010.getAccruedInterest() * notional, TOLERANCE_ACCRUED); final ZonedDateTime settle101010 = DateUtils.getUTCDate(2010, 10, 10); final double accrual101010 = 17769.81; BondFixedSecurity bond101010 = BOND_MON_SECURITY_DEFINITION.toDerivative(settle101010, settle101010); assertEquals("Bond transaction: accrued", accrual101010, bond101010.getAccruedInterest() * notional, TOLERANCE_ACCRUED); }