예제 #1
0
  public static List<Descriptor> getDescriptors(
      @NotNull ReportPeriod reportPeriod,
      @NotNull LocalDate startDate,
      @NotNull LocalDate endDate) {

    final List<Descriptor> descriptors = new ArrayList<>();

    LocalDate start = startDate;
    LocalDate end = startDate;

    switch (reportPeriod) {
      case YEARLY:
        while (end.isBefore(endDate)) {
          end = end.with(TemporalAdjusters.lastDayOfYear());
          descriptors.add(new Descriptor(start, end, "    " + start.getYear()));
          start = end.plusDays(1);
        }
        break;
      case QUARTERLY:
        int i = DateUtils.getQuarterNumber(start) - 1;
        while (end.isBefore(endDate)) {
          end = DateUtils.getLastDayOfTheQuarter(start);
          descriptors.add(new Descriptor(start, end, " " + start.getYear() + "-Q" + (1 + i++ % 4)));
          start = end.plusDays(1);
        }
        break;
      case MONTHLY:
        while (end.isBefore(endDate)) {
          end = DateUtils.getLastDayOfTheMonth(start);
          final int month = start.getMonthValue();
          descriptors.add(
              new Descriptor(
                  start, end, " " + start.getYear() + (month < 10 ? "/0" + month : "/" + month)));
          start = end.plusDays(1);
        }
        break;
      default:
    }

    return descriptors;
  }
  @Override
  public double yearDiff(final LocalDate start, final LocalDate end, final PeriodCountBasis basis) {
    double diff = 0.0;

    switch (basis) {
      case ACT_ACT:
        final int startYear = start.getYear();
        final int endYear = end.getYear();
        if (startYear != endYear) {

          final LocalDate endOfStartYear = start.with(TemporalAdjusters.lastDayOfYear());
          final LocalDate startOfEndYear = end.withDayOfYear(1);

          final long diff1 = ChronoUnit.DAYS.between(start, endOfStartYear);
          final long diff2 = ChronoUnit.DAYS.between(startOfEndYear, end);
          diff =
              (diff1 + 1.0) / start.lengthOfYear()
                  + (endYear - startYear - 1.0)
                  + (double) diff2 / (double) end.lengthOfYear();
        }
        break;

      case CONV_30_360:
      case CONV_360E_ISDA:
      case CONV_360E_ISMA:
      case ACT_360:
        diff = dayDiff(start, end, basis) / YEAR_360_0;
        break;

      case ACT_365:
        diff = dayDiff(start, end, basis) / YEAR_365_0;
        break;

      default:
        throw new UnsupportedOperationException("Sorry ACT_UST is not supported");
    }

    return diff;
  }