RateReplacingVisitor extends InstrumentDerivativeVisitorAdapter<Double, InstrumentDerivative> { @Override public BondFixedSecurity visitBondFixedSecurity(final BondFixedSecurity bond, final Double rate) { final double originalRate = bond.getCoupon().getNthPayment(0).getFixedRate(); final double accruedInterest = rate * bond.getAccruedInterest() / originalRate; final AnnuityCouponFixed originalCoupons = (AnnuityCouponFixed) bond.getCoupon(); final AnnuityCouponFixed coupons = visitFixedCouponAnnuity(originalCoupons, rate); return new BondFixedSecurity((AnnuityPaymentFixed) bond.getNominal(), coupons, bond.getSettlementTime(), accruedInterest, bond.getFactorToNextCoupon(), bond.getYieldConvention(), bond.getCouponPerYear(), bond.getIssuerEntity()); } private  RateReplacingVisitor(); static RateReplacingVisitor getInstance(); @Override Cash visitCash(final Cash cash, final Double rate); @Override AnnuityCouponFixed visitFixedCouponAnnuity(final AnnuityCouponFixed annuity, final Double rate); @Override CouponFixed visitCouponFixed(final CouponFixed payment, final Double rate); @Override ForwardRateAgreement visitForwardRateAgreement(final ForwardRateAgreement fra, final Double rate); @Override SwapFixedCoupon<?> visitFixedCouponSwap(final SwapFixedCoupon<?> swap, final Double rate); @Override InterestRateFutureTransaction visitInterestRateFutureTransaction(final InterestRateFutureTransaction futures, final Double rate); @Override BondFixedSecurity visitBondFixedSecurity(final BondFixedSecurity bond, final Double rate);  }
@Test public void testBondFixedSecurity() { final ZonedDateTime maturityDate = DateUtils.getUTCDate(2020, 1, 1); final ZonedDateTime firstAccrualDate = DateUtils.getUTCDate(2010, 1, 1); final Period paymentPeriod = Period.ofMonths(6); final Calendar calendar = new MondayToFridayCalendar("A"); final DayCount dayCount = DayCounts.ACT_360; final BusinessDayConvention businessDay = BusinessDayConventions.FOLLOWING; final YieldConvention yieldConvention = SimpleYieldConvention.TRUE; final ZonedDateTime date = DateUtils.getUTCDate(2011, 1, 1); final BondFixedSecurity b1 = BondFixedSecurityDefinition.from(CUR, maturityDate, firstAccrualDate, paymentPeriod, R1, 0, calendar, dayCount, businessDay, yieldConvention, false, "I") .toDerivative(date); final BondFixedSecurity b2 = BondFixedSecurityDefinition.from(CUR, maturityDate, firstAccrualDate, paymentPeriod, R2, 0, calendar, dayCount, businessDay, yieldConvention, false, "I") .toDerivative(date); assertEquals(b2, VISITOR.visitBondFixedSecurity(b1, R2)); }