/**
   * Test for the case where publication lag=0, effective offset=0 (GBP conventions) and no cutoff
   * period. The arithmetic average coupons are used mainly in USD. This test is more for
   * completeness than a real case.
   */
  public void rateGbpNoCutOff() {
    OvernightIndexRates mockRates = mock(OvernightIndexRates.class);
    when(mockRates.getIndex()).thenReturn(GBP_SONIA);
    SimpleRatesProvider simpleProv = new SimpleRatesProvider(mockRates);

    for (int i = 0; i < FIXING_DATES.length; i++) {
      when(mockRates.rate(FIXING_DATES[i])).thenReturn(FIXING_RATES[i]);
    }
    OvernightAveragedRateObservation ro =
        OvernightAveragedRateObservation.of(GBP_SONIA, FIXING_START_DATE, FIXING_END_DATE, 0);
    ForwardOvernightAveragedRateObservationFn obsFn =
        ForwardOvernightAveragedRateObservationFn.DEFAULT;
    double accrualFactorTotal = 0.0d;
    double accruedRate = 0.0d;
    int indexLast = 5; // Fixing in the observation period are from 1 to 5 (inclusive)
    for (int i = 1; i <= indexLast; i++) {
      LocalDate startDate = FIXING_DATES[i]; // no effective lag
      LocalDate endDate = GBP_SONIA.calculateMaturityFromEffective(startDate);
      double af = GBP_SONIA.getDayCount().yearFraction(startDate, endDate);
      accrualFactorTotal += af;
      accruedRate += FIXING_RATES[i] * af;
    }
    double rateExpected = accruedRate / accrualFactorTotal;
    double rateComputed =
        obsFn.rate(ro, DUMMY_ACCRUAL_START_DATE, DUMMY_ACCRUAL_END_DATE, simpleProv);
    assertEquals(rateExpected, rateComputed, TOLERANCE_RATE);
  }
  /**
   * Test for the case where publication lag=0, effective offset=0 (GBP conventions) and no cutoff
   * period. The arithmetic average coupons are used mainly in USD. This test is more for
   * completeness than a real case.
   */
  public void rateGbpNoCutOffSensitivity() {
    OvernightIndexRates mockRates = mock(OvernightIndexRates.class);
    when(mockRates.getIndex()).thenReturn(GBP_SONIA);
    SimpleRatesProvider simpleProv = new SimpleRatesProvider(mockRates);

    for (int i = 0; i < FIXING_DATES.length; i++) {
      when(mockRates.rate(FIXING_DATES[i])).thenReturn(FIXING_RATES[i]);
      LocalDate fixingStartDate = GBP_SONIA.calculateEffectiveFromFixing(FIXING_DATES[i]);
      LocalDate fixingEndDate = GBP_SONIA.calculateMaturityFromEffective(fixingStartDate);
      OvernightRateSensitivity sensitivity =
          OvernightRateSensitivity.of(
              GBP_SONIA, FIXING_DATES[i], fixingEndDate, GBP_SONIA.getCurrency(), 1d);
      when(mockRates.ratePointSensitivity(FIXING_DATES[i])).thenReturn(sensitivity);
    }
    OvernightAveragedRateObservation ro =
        OvernightAveragedRateObservation.of(GBP_SONIA, FIXING_START_DATE, FIXING_END_DATE, 0);
    ForwardOvernightAveragedRateObservationFn obsFn =
        ForwardOvernightAveragedRateObservationFn.DEFAULT;
    PointSensitivityBuilder sensitivityBuilderComputed =
        obsFn.rateSensitivity(ro, DUMMY_ACCRUAL_START_DATE, DUMMY_ACCRUAL_END_DATE, simpleProv);
    PointSensitivities sensitivityComputed = sensitivityBuilderComputed.build().normalized();
    Double[] sensitivityExpected = computedSensitivityFD(ro, GBP_SONIA);
    assertEquals(sensitivityComputed.getSensitivities().size(), sensitivityExpected.length);
    for (int i = 0; i < sensitivityExpected.length; ++i) {
      assertEquals(
          sensitivityComputed.getSensitivities().get(i).getSensitivity(),
          sensitivityExpected[i],
          EPS_FD);
    }
  }
 // -------------------------------------------------------------------------
 public void test_of() {
   OvernightRateSwapLegConvention test = OvernightRateSwapLegConvention.of(GBP_SONIA, P12M, 2);
   assertEquals(test.getIndex(), GBP_SONIA);
   assertEquals(test.getAccrualMethod(), COMPOUNDED);
   assertEquals(test.getRateCutOffDays(), 0);
   assertEquals(test.getCurrency(), GBP);
   assertEquals(test.getDayCount(), ACT_365F);
   assertEquals(test.getAccrualFrequency(), P12M);
   assertEquals(test.getAccrualBusinessDayAdjustment(), BDA_MOD_FOLLOW);
   assertEquals(test.getStartDateBusinessDayAdjustment(), BDA_MOD_FOLLOW);
   assertEquals(test.getEndDateBusinessDayAdjustment(), BDA_MOD_FOLLOW);
   assertEquals(test.getStubConvention(), StubConvention.SHORT_INITIAL);
   assertEquals(test.getRollConvention(), RollConventions.NONE);
   assertEquals(test.getPaymentFrequency(), P12M);
   assertEquals(
       test.getPaymentDateOffset(),
       DaysAdjustment.ofBusinessDays(2, GBP_SONIA.getFixingCalendar()));
   assertEquals(test.getCompoundingMethod(), CompoundingMethod.NONE);
 }