CouponIborCompoundingSimpleSpreadDiscountingMethod { public MultipleCurrencyAmount presentValue(final CouponIborCompoundingSimpleSpread coupon, final MulticurveProviderInterface multicurve) { ArgumentChecker.notNull(coupon, "coupon"); ArgumentChecker.notNull(multicurve, "multicurve"); final int nbSubPeriod = coupon.getFixingTimes().length; double cpa = coupon.getCompoundingPeriodAmountAccumulated(); for (int loopsub = 0; loopsub < nbSubPeriod; loopsub++) { final double forward = multicurve.getSimplyCompoundForwardRate(coupon.getIndex(), coupon.getFixingPeriodStartTimes()[loopsub], coupon.getFixingPeriodEndTimes()[loopsub], coupon.getFixingPeriodAccrualFactors()[loopsub]); cpa *= 1.0d + forward * coupon.getPaymentPeriodAccrualFactors()[loopsub]; } final double df = multicurve.getDiscountFactor(coupon.getCurrency(), coupon.getPaymentTime()); final double pv = (cpa - coupon.getNotional() + coupon.getNotional() * coupon.getPaymentYearFraction() * coupon.getSpread()) * df; return MultipleCurrencyAmount.of(coupon.getCurrency(), pv); } private  CouponIborCompoundingSimpleSpreadDiscountingMethod(); static CouponIborCompoundingSimpleSpreadDiscountingMethod getInstance(); MultipleCurrencyAmount presentValue(final CouponIborCompoundingSimpleSpread coupon, final MulticurveProviderInterface multicurve); MultipleCurrencyMulticurveSensitivity presentValueCurveSensitivity(final CouponIborCompoundingSimpleSpread coupon, final MulticurveProviderInterface multicurve);  }
@Test public void presentValueBeforeFirstFixing() { final MultipleCurrencyAmount pvComputed = METHOD_COMPOUNDED.presentValue(CPN_BEFORE, MULTICURVES); final int nbSub = CPN_BEFORE.getFixingTimes().length; double[] forward = new double[nbSub]; for (int loopsub = 0; loopsub < nbSub; loopsub++) { forward[loopsub] = MULTICURVES.getSimplyCompoundForwardRate(CADCDOR3M, CPN_BEFORE.getFixingPeriodStartTimes()[loopsub], CPN_BEFORE.getFixingPeriodEndTimes()[loopsub], CPN_BEFORE.getFixingPeriodAccrualFactors()[loopsub]); } final double cpa = cpa(CPN_BEFORE.getCompoundingPeriodAmountAccumulated(), forward, CPN_BEFORE.getPaymentPeriodAccrualFactors()); final double dfPayment = MULTICURVES.getDiscountFactor(CAD, CPN_BEFORE.getPaymentTime()); final double pvExpected = (cpa - NOTIONAL + NOTIONAL * SPREAD * CPN_BEFORE.getPaymentYearFraction()) * dfPayment; assertEquals("CouponIborCompoundingSimpleSpreadDiscountingMethod: Present value", pvExpected, pvComputed.getAmount(CAD), TOLERANCE_PV); }
@Test public void presentValueMethodVsCalculator() { final MultipleCurrencyAmount pvMethod = METHOD_COMPOUNDED.presentValue(CPN_BEFORE, MULTICURVES); final MultipleCurrencyAmount pvCalculator = CPN_BEFORE.accept(PVDC, MULTICURVES); assertEquals("CouponIborCompoundingSimpleSpreadDiscountingMethod: Present value", pvMethod.getAmount(CAD), pvCalculator.getAmount(CADCDOR3M.getCurrency()), TOLERANCE_PV); }
@Test public void presentValueAfter1Fixing() { final MultipleCurrencyAmount pvComputed = METHOD_COMPOUNDED.presentValue(CPN_1, MULTICURVES); final int nbSub = CPN_1.getFixingTimes().length; double[] forward = new double[nbSub]; for (int loopsub = 0; loopsub < nbSub; loopsub++) { forward[loopsub] = MULTICURVES.getSimplyCompoundForwardRate(CADCDOR3M, CPN_1.getFixingPeriodStartTimes()[loopsub], CPN_1.getFixingPeriodEndTimes()[loopsub], CPN_1.getFixingPeriodAccrualFactors()[loopsub]); } final double cpa = cpa(CPN_1.getCompoundingPeriodAmountAccumulated(), forward, CPN_1.getPaymentPeriodAccrualFactors()); final double dfPayment = MULTICURVES.getDiscountFactor(CAD, CPN_1.getPaymentTime()); final double pvExpected = (cpa - NOTIONAL + NOTIONAL * SPREAD * CPN_BEFORE.getPaymentYearFraction()) * dfPayment; assertEquals("CouponIborCompoundingSimpleSpreadDiscountingMethod: Present value", pvExpected, pvComputed.getAmount(CAD), TOLERANCE_PV); }