CouponONCompoundedDiscountingMethod { public MultipleCurrencyAmount presentValue(final CouponONCompounded coupon, final MulticurveProviderInterface multicurve) { ArgumentChecker.notNull(coupon, "Coupon"); ArgumentChecker.notNull(multicurve, "Market"); double ratio = 1.0; for (int i = 0; i < coupon.getFixingPeriodAccrualFactors().length; i++) { ratio *= Math.pow( 1 + multicurve.getAnnuallyCompoundForwardRate(coupon.getIndex(), coupon.getFixingPeriodStartTimes()[i], coupon.getFixingPeriodEndTimes()[i], coupon.getFixingPeriodAccrualFactors()[i]), coupon.getFixingPeriodAccrualFactors()[i]); } final double df = multicurve.getDiscountFactor(coupon.getCurrency(), coupon.getPaymentTime()); final double pv = df * coupon.getNotionalAccrued() * ratio; return MultipleCurrencyAmount.of(coupon.getCurrency(), pv); } private  CouponONCompoundedDiscountingMethod(); static CouponONCompoundedDiscountingMethod getInstance(); MultipleCurrencyAmount presentValue(final CouponONCompounded coupon, final MulticurveProviderInterface multicurve); MultipleCurrencyMulticurveSensitivity presentValueCurveSensitivity(final CouponONCompounded coupon, final MulticurveProviderInterface multicurve);  }
@Test public void presentValue() { final MultipleCurrencyAmount pvComputed = METHOD_CPN_ON.presentValue(CPN_ON_COMPOUNDED, MULTICURVES); double ratio = 1.0; for (int i = 0; i < CPN_ON_COMPOUNDED.getFixingPeriodAccrualFactors().length; i++) { ratio *= Math.pow( 1 + MULTICURVES.getAnnuallyCompoundForwardRate(CPN_ON_COMPOUNDED.getIndex(), CPN_ON_COMPOUNDED.getFixingPeriodStartTimes()[i], CPN_ON_COMPOUNDED.getFixingPeriodEndTimes()[i], CPN_ON_COMPOUNDED.getFixingPeriodAccrualFactors()[i]), CPN_ON_COMPOUNDED.getFixingPeriodAccrualFactors()[i]); } final double df = MULTICURVES.getDiscountFactor(CPN_ON_COMPOUNDED.getCurrency(), CPN_ON_COMPOUNDED.getPaymentTime()); final double pvExpected = df * CPN_ON_COMPOUNDED.getNotionalAccrued() * ratio; assertEquals("CouponONCompoundedDiscountingMethod: present value", pvExpected, pvComputed.getAmount(INDEX_ON.getCurrency()), TOLERANCE_PV); }
@Test public void presentValueStarted() { final double fixing = 0.0015; final ZonedDateTimeDoubleTimeSeries TS_ON = ImmutableZonedDateTimeDoubleTimeSeries.ofUTC(new ZonedDateTime[] {DateUtils.getUTCDate(2011, 5, 20), DateUtils.getUTCDate(2011, 5, 23) }, new double[] { 0.0010, fixing }); final ZonedDateTime referenceDate = ScheduleCalculator.getAdjustedDate(EFFECTIVE_DATE, 1, TARGET); final CouponONCompounded cpnONCompoundedStarted = (CouponONCompounded) CPN_ON_COMPOUNDED_DEFINITION.toDerivative(referenceDate, TS_ON); final double notionalAccrued = NOTIONAL * Math.pow(1 + fixing, CPN_ON_COMPOUNDED_DEFINITION.getFixingPeriodAccrualFactors()[0]); assertEquals("CouponONCompoundedDiscountingMethod: present value", notionalAccrued, cpnONCompoundedStarted.getNotionalAccrued(), TOLERANCE_PV); final MultipleCurrencyAmount pvComputed = METHOD_CPN_ON.presentValue(cpnONCompoundedStarted, MULTICURVES); double ratio = 1.0; for (int i = 0; i < cpnONCompoundedStarted.getFixingPeriodAccrualFactors().length; i++) { ratio *= Math.pow( 1 + MULTICURVES.getAnnuallyCompoundForwardRate(cpnONCompoundedStarted.getIndex(), cpnONCompoundedStarted.getFixingPeriodStartTimes()[i], cpnONCompoundedStarted.getFixingPeriodEndTimes()[i], cpnONCompoundedStarted.getFixingPeriodAccrualFactors()[i]), cpnONCompoundedStarted.getFixingPeriodAccrualFactors()[i]); } final double df = MULTICURVES.getDiscountFactor(cpnONCompoundedStarted.getCurrency(), cpnONCompoundedStarted.getPaymentTime()); final double pvExpected = cpnONCompoundedStarted.getNotionalAccrued() * ratio * df; assertEquals("CouponONCompoundedDiscountingMethod: present value", pvExpected, pvComputed.getAmount(EUR), TOLERANCE_PV); }
@Test public void presentValueMethodVsCalculator() { final MultipleCurrencyAmount pvMethod = METHOD_CPN_ON.presentValue(CPN_ON_COMPOUNDED, MULTICURVES); final MultipleCurrencyAmount pvCalculator = CPN_ON_COMPOUNDED.accept(PVDC, MULTICURVES); assertEquals("CouponONCompoundedDiscountingMethod: present value", pvMethod.getAmount(EUR), pvCalculator.getAmount(EUR), TOLERANCE_PV); }