YieldAndDiscountCurveUtils { public static double zeroCouponRate(final YieldAndDiscountCurve curve, final ZonedDateTime curveDate, final ZonedDateTime payDate, final DayCount dc, final int paymentPerYear) { ArgumentChecker.notNull(curve, "curve"); ArgumentChecker.notNull(curveDate, "curveDate"); ArgumentChecker.notNull(payDate, "payDate"); ArgumentChecker.notNull(dc, "dayCount"); final double timeCurve = TimeCalculator.getTimeBetween(curveDate, payDate); final double df = curve.getDiscountFactor(timeCurve); final double timeDc = dc.getDayCountFraction(curveDate, payDate); if (paymentPerYear > 0) { final double rate = paymentPerYear * (Math.pow(df, -1.0 / (paymentPerYear * timeDc)) - 1.0); return rate; } final double rate = -Math.log(df) / timeDc; return rate; }  static double forwardRateFromCurve(final YieldAndDiscountCurve curve, final ZonedDateTime curveDate, final ZonedDateTime fixingDate, final IborIndex index, final Calendar cal); static double forwardRateFromProvider(final MulticurveProviderInterface multicurve, final ZonedDateTime curveDate, final ZonedDateTime fixingDate,
      final IborIndex index, final Calendar cal); static double zeroCouponRate(final YieldAndDiscountCurve curve, final ZonedDateTime curveDate, final ZonedDateTime payDate, final DayCount dc, final int paymentPerYear); static double discountFactor(final YieldAndDiscountCurve curve, final ZonedDateTime curveDate, final ZonedDateTime payDate);  }
@Test public void zeroCouponRatePeriodicTest() { final YieldAndDiscountCurve curve3M = MULTICURVE.getCurve(USDLIBOR3M); final ZonedDateTime paymentDate = DateUtils.getUTCDate(2013, 10, 28); final double timeCurve = TimeCalculator.getTimeBetween(CURVE_DATE, paymentDate); final double df = curve3M.getDiscountFactor(timeCurve); final DayCount dc = DayCounts.ACT_365; final double timeDc = dc.getDayCountFraction(CURVE_DATE, paymentDate); final int paymentPerYear = 4; final double rateExpected = paymentPerYear * (Math.pow(df, -1.0 / (paymentPerYear * timeDc)) - 1.0); final double rateComputed = YieldAndDiscountCurveUtils.zeroCouponRate(curve3M, CURVE_DATE, paymentDate, dc, paymentPerYear); assertEquals("zeroCouponRatePeriodic", rateExpected, rateComputed, TOLERANCE_RATE); }
@Test public void zeroCouponRateContinuousTest() { final YieldAndDiscountCurve curve3M = MULTICURVE.getCurve(USDLIBOR3M); final ZonedDateTime paymentDate = DateUtils.getUTCDate(2013, 10, 28); final double timeCurve = TimeCalculator.getTimeBetween(CURVE_DATE, paymentDate); final double df = curve3M.getDiscountFactor(timeCurve); final DayCount dc = DayCounts.ACT_365; final double timeDc = dc.getDayCountFraction(CURVE_DATE, paymentDate); final double rateExpected = -Math.log(df) / timeDc; final double rateComputed = YieldAndDiscountCurveUtils.zeroCouponRate(curve3M, CURVE_DATE, paymentDate, dc, 0); assertEquals("zeroCouponRatePeriodic", rateExpected, rateComputed, TOLERANCE_RATE); }