/**
  * Return the relative (not multiplied by the notional) accrued interest rate at a given date.
  *
  * @param date The date.
  * @return The accrued interest.
  */
 public double accruedInterest(final ZonedDateTime date) {
   double result = 0;
   final int nbCoupon = getCoupons().getNumberOfPayments();
   int couponIndex = 0;
   for (int loopcpn = 0; loopcpn < nbCoupon; loopcpn++) {
     if (getCoupons().getNthPayment(loopcpn).getAccrualEndDate().isAfter(date)) {
       couponIndex = loopcpn;
       break;
     }
   }
   final ZonedDateTime previousAccrualDate =
       getCoupons().getNthPayment(couponIndex).getAccrualStartDate();
   final ZonedDateTime nextAccrualDate =
       getCoupons().getNthPayment(couponIndex).getAccrualEndDate();
   final CouponInflationWithMargin currentCoupon =
       ((CouponInflationWithMargin) getCoupons().getNthPayment(couponIndex));
   final double accruedInterest =
       AccruedInterestCalculator.getAccruedInterest(
               getDayCount(),
               couponIndex,
               nbCoupon,
               previousAccrualDate,
               date,
               nextAccrualDate,
               currentCoupon.getFactor(),
               getCouponPerYear(),
               isEOM())
           * getCoupons().getNthPayment(couponIndex).getNotional();
   if (getExCouponDays() != 0 && nextAccrualDate.minusDays(getExCouponDays()).isBefore(date)) {
     result = accruedInterest - currentCoupon.getFactor() / _couponPerYear;
   } else {
     result = accruedInterest;
   }
   return result;
 }
 /**
  * Constructor of a fixed coupon bond transaction from all the transaction details.
  *
  * @param underlyingBond The fixed coupon bond underlying the transaction.
  * @param quantity The number of bonds purchased (can be negative or positive).
  * @param settlementDate Transaction settlement date.
  * @param dirtyPrice The (dirty) price of the transaction in relative term (i.e. 0.90 if the dirty
  *     price is 90% of nominal).
  */
 public BondFixedTransactionDefinition(
     final BondFixedSecurityDefinition underlyingBond,
     final double quantity,
     final ZonedDateTime settlementDate,
     final double dirtyPrice) {
   super(underlyingBond, quantity, settlementDate, dirtyPrice);
   _accruedInterestAtSettlement = 0;
   final int nbCoupon = underlyingBond.getCoupons().getNumberOfPayments();
   final double accruedInterest =
       AccruedInterestCalculator.getAccruedInterest(
           getUnderlyingBond().getDayCount(),
           getCouponIndex(),
           nbCoupon,
           getPreviousAccrualDate(),
           settlementDate,
           getNextAccrualDate(),
           underlyingBond.getCoupons().getNthPayment(getCouponIndex()).getRate(),
           underlyingBond.getCouponPerYear(),
           underlyingBond.isEOM());
   if (underlyingBond.getExCouponDays() != 0
       && getNextAccrualDate()
           .minusDays(underlyingBond.getExCouponDays())
           .isBefore(settlementDate)) {
     _accruedInterestAtSettlement =
         accruedInterest - underlyingBond.getCoupons().getNthPayment(getCouponIndex()).getRate();
   } else {
     _accruedInterestAtSettlement = accruedInterest;
   }
 }