@Test
 public void testReturnsWithZeroesInSeries() {
   final int n = 20;
   final LocalDate[] times = new LocalDate[n];
   final double[] data = new double[n];
   final double[] returns = new double[n - 3];
   double random;
   for (int i = 0; i < n - 2; i++) {
     times[i] = LocalDate.ofEpochDay(i);
     random = RANDOM.nextDouble();
     data[i] = random;
     if (i > 0) {
       returns[i - 1] = Math.log(random / data[i - 1]);
     }
   }
   times[n - 2] = LocalDate.ofEpochDay(n - 2);
   data[n - 2] = 0;
   times[n - 1] = LocalDate.ofEpochDay(n - 1);
   data[n - 1] = RANDOM.nextDouble();
   final LocalDateDoubleTimeSeries priceTS = ImmutableLocalDateDoubleTimeSeries.of(times, data);
   final LocalDateDoubleTimeSeries returnTS =
       ImmutableLocalDateDoubleTimeSeries.of(Arrays.copyOfRange(times, 1, n - 2), returns);
   final TimeSeriesReturnCalculator strict =
       new ContinuouslyCompoundedTimeSeriesReturnCalculator(CalculationMode.STRICT);
   final LocalDateDoubleTimeSeries[] tsArray = new LocalDateDoubleTimeSeries[] {priceTS};
   try {
     strict.evaluate(tsArray);
     Assert.fail();
   } catch (final TimeSeriesException e) {
     // Expected
   }
   final TimeSeriesReturnCalculator lenient =
       new ContinuouslyCompoundedTimeSeriesReturnCalculator(CalculationMode.LENIENT);
   assertTrue(lenient.evaluate(tsArray).equals(returnTS));
 }
 @Test
 public void testReturnsWithDividendsAtDifferentTimes() {
   final int n = 20;
   final LocalDate[] times = new LocalDate[n];
   final double[] data = new double[n];
   final double[] returns = new double[n - 1];
   double random;
   for (int i = 0; i < n; i++) {
     times[i] = LocalDate.ofEpochDay(i);
     random = RANDOM.nextDouble();
     data[i] = random;
     if (i > 0) {
       returns[i - 1] = Math.log(random / data[i - 1]);
     }
   }
   final LocalDateDoubleTimeSeries dividendTS =
       ImmutableLocalDateDoubleTimeSeries.of(
           new LocalDate[] {LocalDate.ofEpochDay(300)}, new double[] {3});
   final LocalDateDoubleTimeSeries priceTS = ImmutableLocalDateDoubleTimeSeries.of(times, data);
   final LocalDateDoubleTimeSeries returnTS =
       ImmutableLocalDateDoubleTimeSeries.of(Arrays.copyOfRange(times, 1, n), returns);
   assertTrue(
       CALCULATOR
           .evaluate(new LocalDateDoubleTimeSeries[] {priceTS, dividendTS})
           .equals(returnTS));
 }
 @Test(expectedExceptions = TimeSeriesException.class)
 public void testWithBadInputs() {
   final LocalDateDoubleTimeSeries ts =
       ImmutableLocalDateDoubleTimeSeries.of(
           new LocalDate[] {LocalDate.ofEpochDay(1)}, new double[] {4});
   CALCULATOR.evaluate(new LocalDateDoubleTimeSeries[] {ts});
 }