GeneratorLegONArithmeticAverage extends GeneratorLegONAbstract { @Override public AnnuityDefinition<?> generateInstrument(final ZonedDateTime date, final double marketQuote, final double notional, final GeneratorAttributeIR attribute) { ArgumentChecker.notNull(date, "Reference date"); ArgumentChecker.notNull(attribute, "Attributes"); ZonedDateTime spot = ScheduleCalculator.getAdjustedDate(date, getSpotOffset(), getPaymentCalendar()); ZonedDateTime startDate = ScheduleCalculator.getAdjustedDate(spot, attribute.getStartPeriod(), getBusinessDayConvention(), getPaymentCalendar(), isEndOfMonth()); ZonedDateTime endDate = startDate.plus(attribute.getEndPeriod()); NotionalProvider notionalProvider = new NotionalProvider() { @Override public double getAmount(final LocalDate date) { return notional; } }; AdjustedDateParameters adjustedDateIndex = new AdjustedDateParameters(getIndexCalendar(), getBusinessDayConvention()); OffsetAdjustedDateParameters offsetFixing = new OffsetAdjustedDateParameters(0, OffsetType.BUSINESS, getIndexCalendar(), BusinessDayConventionFactory.of("Following")); AnnuityDefinition<?> leg = new FloatingAnnuityDefinitionBuilder(). payer(false).notional(notionalProvider).startDate(startDate.toLocalDate()).endDate(endDate.toLocalDate()). index(getIndexON()).accrualPeriodFrequency(getPaymentPeriod()). rollDateAdjuster(RollConvention.NONE.getRollDateAdjuster(0)).resetDateAdjustmentParameters(adjustedDateIndex). accrualPeriodParameters(adjustedDateIndex).dayCount(getIndexON().getDayCount()). fixingDateAdjustmentParameters(offsetFixing).currency(getIndexON().getCurrency()).spread(marketQuote).build(); return leg; } GeneratorLegONArithmeticAverage(String name, Currency ccy, IndexON indexON, Period paymentPeriod, 
      int spotOffset, int paymentOffset, BusinessDayConvention businessDayConvention, boolean endOfMonth, 
      StubType stubType, boolean isExchangeNotional, Calendar indexCalendar, Calendar paymentCalendar); @Override AnnuityDefinition<?> generateInstrument(final ZonedDateTime date, final double marketQuote, 
      final double notional, final GeneratorAttributeIR attribute);  }
@Test public void generateInstrument() { double notional = 1000000; double spread = 0.0025; int legTenorYear = 3; Period legTenor = Period.ofYears(legTenorYear); GeneratorAttributeIR attribute = new GeneratorAttributeIR(legTenor); ZonedDateTime valuationDate = DateUtils.getUTCDate(2014, 1, 22); AnnuityDefinition<?> instrumentDefinition = GENERATOR.generateInstrument(valuationDate, spread, notional, attribute); AnnuityDefinition<?> instrumentDefinitionSimplified = GENERATOR_SIMPLE.generateInstrument(valuationDate, spread, notional, attribute); assertEquals("GeneratorLegONCompounded: generate - number of coupons", instrumentDefinition.getNumberOfPayments(), legTenorYear); ZonedDateTime spotDate = ScheduleCalculator.getAdjustedDate(valuationDate, GENERATOR.getSpotOffset(), NYC); ZonedDateTime startDate = spotDate; ZonedDateTime endDate; for(int loopcpn = 0 ; loopcpn<legTenorYear; loopcpn++) { assertTrue("GeneratorLegONCompounded: generate - coupon type", instrumentDefinition.getNthPayment(loopcpn) instanceof CouponONArithmeticAverageSpreadDefinition); CouponONArithmeticAverageSpreadDefinition cpn = (CouponONArithmeticAverageSpreadDefinition) instrumentDefinition.getNthPayment(loopcpn); endDate = ScheduleCalculator.getAdjustedDate(spotDate, GENERATOR.getPaymentPeriod().multipliedBy(loopcpn+1), GENERATOR.getBusinessDayConvention(), NYC, GENERATOR.isEndOfMonth()); assertEquals("GeneratorLegONCompounded: generate - start accrual date", startDate, cpn.getAccrualStartDate()); assertEquals("GeneratorLegONCompounded: generate - end accrual date", endDate, cpn.getAccrualEndDate()); ZonedDateTime paymentDate = ScheduleCalculator.getAdjustedDate( cpn.getFixingPeriodDates()[cpn.getFixingPeriodDates().length-1], GENERATOR.getPaymentOffset(), NYC); assertEquals("GeneratorLegONCompounded: generate - payment date", paymentDate, cpn.getPaymentDate()); assertEquals("GeneratorLegONCompounded: generate - spread", spread, cpn.getSpread()); assertTrue("GeneratorLegONCompounded: generate - coupon type", instrumentDefinitionSimplified.getNthPayment(loopcpn) instanceof CouponONArithmeticAverageSpreadSimplifiedDefinition); CouponONArithmeticAverageSpreadSimplifiedDefinition cpnSim = (CouponONArithmeticAverageSpreadSimplifiedDefinition) instrumentDefinitionSimplified.getNthPayment(loopcpn); assertEquals("GeneratorLegONCompounded: generate - start accrual date", startDate, cpnSim.getAccrualStartDate()); assertEquals("GeneratorLegONCompounded: generate - end accrual date", endDate, cpnSim.getAccrualEndDate()); assertEquals("GeneratorLegONCompounded: generate - payment date", paymentDate, cpnSim.getPaymentDate()); assertEquals("GeneratorLegONCompounded: generate - spread", spread, cpnSim.getSpread()); startDate = endDate; } }