CouponIborAverageFixingDatesCompoundingDiscountingMethod { public MultipleCurrencyAmount presentValue(final CouponIborAverageFixingDatesCompounding coupon, final MulticurveProviderInterface multicurves) { ArgumentChecker.notNull(coupon, "Coupon"); ArgumentChecker.notNull(multicurves, "Multi-curves provider"); final int nPeriods = coupon.getFixingTime().length; double payOff = coupon.getInvestmentFactor(); for (int i = 0; i < nPeriods; ++i) { double forward = ((i == 0) ? coupon.getAmountAccrued() : 0.0); final int nDates = coupon.getFixingTime()[i].length; for (int j = 0; j < nDates; ++j) { final double forward1 = multicurves.getSimplyCompoundForwardRate(coupon.getIndex(), coupon.getFixingPeriodStartTime()[i][j], coupon.getFixingPeriodEndTime()[i][j], coupon.getFixingPeriodAccrualFactor()[i][j]); forward += coupon.getWeight()[i][j] * forward1; } payOff *= (1.0 + forward * coupon.getPaymentAccrualFactors()[i]); } final double df = multicurves.getDiscountFactor(coupon.getCurrency(), coupon.getPaymentTime()); final double pv = coupon.getNotional() * (payOff - 1.0) * df; return MultipleCurrencyAmount.of(coupon.getCurrency(), pv); } private  CouponIborAverageFixingDatesCompoundingDiscountingMethod(); static CouponIborAverageFixingDatesCompoundingDiscountingMethod getInstance(); MultipleCurrencyAmount presentValue(final CouponIborAverageFixingDatesCompounding coupon, final MulticurveProviderInterface multicurves); MultipleCurrencyMulticurveSensitivity presentValueCurveSensitivity(final CouponIborAverageFixingDatesCompounding coupon, final MulticurveProviderInterface multicurve);  }
@Test public void presentValueFixedTest() { final MultipleCurrencyAmount pvComputed = METHOD.presentValue(DER1, MULTICURVES); double fwd = AMOUNT_ACC; for (int j = 0; j < NUM_OBS_INI; ++j) { fwd += WEIGHTS1[0][j] * MULTICURVES.getSimplyCompoundForwardRate(INDEX1, FIXING_PERIOD_START_TIMES1[0][j], FIXING_PERIOD_END_TIMES1[0][j], FIX_ACC_FACTORS1[0][j]); } double invFactor = RATE_FIXED; invFactor *= (1.0 + fwd * DER1.getPaymentAccrualFactors()[0]); for (int i = 1; i < NUM_PRDS; ++i) { double forward = 0.0; for (int j = 0; j < NUM_OBS; ++j) { forward += WEIGHTS1[i][j] * MULTICURVES.getSimplyCompoundForwardRate(INDEX1, FIXING_PERIOD_START_TIMES1[i][j], FIXING_PERIOD_END_TIMES1[i][j], FIX_ACC_FACTORS1[i][j]); } invFactor *= (1.0 + forward * DER1.getPaymentAccrualFactors()[i]); } final double pvExpected = DER1.getNotional() * MULTICURVES.getDiscountFactor(DER1.getCurrency(), DER1.getPaymentTime()) * (invFactor - 1.0); assertEquals("CouponIborAverageCompoundingDiscountingMethod: present value", pvExpected, pvComputed.getAmount(DER1.getCurrency()), TOLERANCE_PV); final MultipleCurrencyAmount pvWithCalc = PVDC.visitCouponIborAverageCompounding(DER1, MULTICURVES); assertEquals("CouponIborAverageCompoundingDiscountingMethod: present value", pvWithCalc.getAmount(DER1.getCurrency()), pvComputed.getAmount(DER1.getCurrency()), TOLERANCE_PV); }
@Test public void presentValueNotFixedTest() { final MultipleCurrencyAmount pvComputed = METHOD.presentValue(DER2, MULTICURVES); double invFactor = 1.0; for (int i = 0; i < NUM_PRDS; ++i) { double forward = 0.0; for (int j = 0; j < NUM_OBS; ++j) { forward += WEIGHTS2[i][j] * MULTICURVES.getSimplyCompoundForwardRate(INDEX2, FIXING_PERIOD_START_TIMES2[i][j], FIXING_PERIOD_END_TIMES2[i][j], FIX_ACC_FACTORS2[i][j]); } invFactor *= (1.0 + forward * DER2.getPaymentAccrualFactors()[i]); } final double pvExpected = DER2.getNotional() * MULTICURVES.getDiscountFactor(DER2.getCurrency(), DER2.getPaymentTime()) * (invFactor - 1.0); assertEquals(pvExpected, pvComputed.getAmount(DER2.getCurrency()), TOLERANCE_PV); final MultipleCurrencyAmount pvWithCalc = PVDC.visitCouponIborAverageCompounding(DER2, MULTICURVES); assertEquals(pvWithCalc.getAmount(DER2.getCurrency()), pvComputed.getAmount(DER2.getCurrency()), EPS * Math.abs(pvExpected)); }
@Test public void presentValueNotFixedNoSquareTest() { final MultipleCurrencyAmount pvComputed = METHOD.presentValue(DER3, MULTICURVES); double invFactor = DER3.getInvestmentFactor(); double fwd = DER3.getAmountAccrued(); for (int j = 0; j < DER3.getFixingPeriodAccrualFactor()[0].length; ++j) { fwd += WEIGHTS_3[0][j] * MULTICURVES.getSimplyCompoundForwardRate(INDEX1, DER3.getFixingPeriodStartTime()[0][j], DER3.getFixingPeriodEndTime()[0][j], DER3.getFixingPeriodAccrualFactor()[0][j]); } invFactor *= (1.0 + fwd * DER3.getPaymentAccrualFactors()[0]); for (int i = 1; i < DER3.getFixingPeriodAccrualFactor().length; ++i) { double forward = 0.0; for (int j = 0; j < DER3.getFixingPeriodAccrualFactor()[i].length; ++j) { forward += WEIGHTS_3[i][j] * MULTICURVES.getSimplyCompoundForwardRate(INDEX1, DER3.getFixingPeriodStartTime()[i][j], DER3.getFixingPeriodEndTime()[i][j], DER3.getFixingPeriodAccrualFactor()[i][j]); } invFactor *= (1.0 + forward * DER3.getPaymentAccrualFactors()[i]); } final double pvExpected = DER3.getNotional() * MULTICURVES.getDiscountFactor(DER3.getCurrency(), DER3.getPaymentTime()) * (invFactor - 1.0); assertEquals(pvExpected, pvComputed.getAmount(DER3.getCurrency()), EPS * Math.abs(pvExpected)); final MultipleCurrencyAmount pvWithCalc = PVDC.visitCouponIborAverageCompounding(DER3, MULTICURVES); assertEquals(pvWithCalc.getAmount(DER3.getCurrency()), pvComputed.getAmount(DER3.getCurrency()), EPS * Math.abs(pvExpected)); }