CouponIborAverageFixingDatesCompoundingFlatSpreadDiscountingMethod { public MultipleCurrencyAmount presentValue(final CouponIborAverageFixingDatesCompoundingFlatSpread coupon, final MulticurveProviderInterface multicurves) { ArgumentChecker.notNull(coupon, "Coupon"); ArgumentChecker.notNull(multicurves, "Multi-curves provider"); final int nPeriods = coupon.getFixingTime().length; double payoff = coupon.getRateFixed(); for (int i = 0; i < nPeriods; ++i) { double forwardAverage = ((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]); forwardAverage += coupon.getWeight()[i][j] * forward1; } payoff += (forwardAverage + coupon.getSpread() + forwardAverage * payoff) * coupon.getPaymentAccrualFactors()[i]; } final double df = multicurves.getDiscountFactor(coupon.getCurrency(), coupon.getPaymentTime()); final double pv = coupon.getNotional() * payoff * df; return MultipleCurrencyAmount.of(coupon.getCurrency(), pv); } private  CouponIborAverageFixingDatesCompoundingFlatSpreadDiscountingMethod(); static CouponIborAverageFixingDatesCompoundingFlatSpreadDiscountingMethod getInstance(); MultipleCurrencyAmount presentValue(final CouponIborAverageFixingDatesCompoundingFlatSpread coupon, final MulticurveProviderInterface multicurves); MultipleCurrencyMulticurveSensitivity presentValueCurveSensitivity(final CouponIborAverageFixingDatesCompoundingFlatSpread coupon, final MulticurveProviderInterface multicurve);  }
@Test public void presentValueFixedTest() { final MultipleCurrencyAmount pvComputed = METHOD.presentValue(DER1, MULTICURVES); double cpaTotal = RATE_FIXED; final double[] fwds = new double[NUM_PRDS]; Arrays.fill(fwds, 0.0); final double[] cpas = new double[NUM_PRDS]; Arrays.fill(cpas, 0.0); fwds[0] += DER1.getAmountAccrued(); for (int j = 0; j < NUM_OBS_INI; ++j) { fwds[0] += WEIGHTS[0][j] * MULTICURVES.getSimplyCompoundForwardRate(IBOR_INDEXES[0], FIXING_PERIOD_START_TIMES[0][j], FIXING_PERIOD_END_TIMES[0][j], FIX_ACC_FACTORS[0][j]); } cpas[0] = (fwds[0] + DER1.getSpread()) * DER1.getPaymentAccrualFactors()[0] + DER1.getPaymentAccrualFactors()[0] * fwds[0] * cpaTotal; for (int i = 1; i < NUM_PRDS; ++i) { for (int j = 0; j < NUM_OBS; ++j) { fwds[i] += WEIGHTS[i][j] * MULTICURVES.getSimplyCompoundForwardRate(IBOR_INDEXES[0], FIXING_PERIOD_START_TIMES[i][j], FIXING_PERIOD_END_TIMES[i][j], FIX_ACC_FACTORS[i][j]); } } for (int i = 1; i < NUM_PRDS; ++i) { cpas[i] = DER1.getPaymentAccrualFactors()[i] * (fwds[i] + DER1.getSpread()); double sum = RATE_FIXED; for (int k = 0; k < i; ++k) { sum += cpas[k]; } cpas[i] += DER1.getPaymentAccrualFactors()[i] * fwds[i] * sum; } for (int i = 0; i < NUM_PRDS; ++i) { cpaTotal += cpas[i]; } final double pvExpected = DER1.getNotional() * MULTICURVES.getDiscountFactor(DER1.getCurrency(), DER1.getPaymentTime()) * cpaTotal; assertEquals("CouponIborAverageFixingDatesCompoundingFlatSpreadDiscountingMethod: present value", pvExpected, pvComputed.getAmount(DER1.getCurrency()), TOLERANCE_PV); final MultipleCurrencyAmount pvWithCalc = DER1.accept(PVDC, MULTICURVES); assertEquals("CouponIborAverageFixingDatesCompoundingFlatSpreadDiscountingMethod: present value", pvWithCalc.getAmount(DER1.getCurrency()), pvComputed.getAmount(DER1.getCurrency()), EPS * Math.abs(pvExpected)); }
@Test public void presentValueNotFixedTest() { final MultipleCurrencyAmount pvComputed = METHOD.presentValue(DER2, MULTICURVES); double cpaInit = 0.0; final double[] fwds = new double[NUM_PRDS]; Arrays.fill(fwds, 0.0); final double[] cpas = new double[NUM_PRDS]; Arrays.fill(cpas, 0.0); for (int i = 0; i < NUM_PRDS; ++i) { for (int j = 0; j < NUM_OBS; ++j) { fwds[i] += WEIGHTS_ORG[i][j] * MULTICURVES.getSimplyCompoundForwardRate(IBOR_INDEXES[2], FIXING_PERIOD_START_TIMES_ORG[i][j], FIXING_PERIOD_END_TIMES_ORG[i][j], FIX_ACC_FACTORS_ORG[i][j]); } } for (int i = 0; i < NUM_PRDS; ++i) { cpas[i] = (fwds[i] + DER2.getSpread()) * DER2.getPaymentAccrualFactors()[i]; double sum = 0.0; for (int k = 0; k < i; ++k) { sum += (cpas[k] * DER2.getPaymentAccrualFactors()[i] * fwds[i]); } cpas[i] += sum; } for (int i = 0; i < NUM_PRDS; ++i) { cpaInit += cpas[i]; } final double pvExpected = DER2.getNotional() * MULTICURVES.getDiscountFactor(DER2.getCurrency(), DER2.getPaymentTime()) * cpaInit; assertEquals("CouponIborAverageFixingDatesCompoundingFlatSpreadDiscountingMethod: present value", pvExpected, pvComputed.getAmount(DER2.getCurrency()), TOLERANCE_PV); final MultipleCurrencyAmount pvWithCalc = PVDC.visitCouponIborAverageFlatCompoundingSpread(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 acc = 0.0; final double[] fwds = new double[DER3.getFixingPeriodAccrualFactor().length]; Arrays.fill(fwds, 0.0); final double[] cpas = new double[DER3.getFixingPeriodAccrualFactor().length]; Arrays.fill(cpas, 0.0); for (int i = 0; i < DER3.getFixingPeriodAccrualFactor().length; ++i) { for (int j = 0; j < DER3.getFixingPeriodAccrualFactor()[i].length; ++j) { fwds[i] += WEIGHTS_3[i][j] * MULTICURVES.getSimplyCompoundForwardRate(IBOR_INDEXES[0], DER3.getFixingPeriodStartTime()[i][j], DER3.getFixingPeriodEndTime()[i][j], DER3.getFixingPeriodAccrualFactor()[i][j]); } } for (int i = 0; i < DER3.getFixingPeriodAccrualFactor().length; ++i) { cpas[i] = (fwds[i] + DER3.getSpread()) * DER3.getPaymentAccrualFactors()[i]; double sum = 0.0; for (int k = 0; k < i; ++k) { sum += (cpas[k] * DER3.getPaymentAccrualFactors()[i] * fwds[i]); } cpas[i] += sum; } for (int i = 0; i < DER3.getFixingPeriodAccrualFactor().length; ++i) { acc += cpas[i]; } final double pvExpected = DER3.getNotional() * MULTICURVES.getDiscountFactor(DER3.getCurrency(), DER3.getPaymentTime()) * acc; assertEquals(pvExpected, pvComputed.getAmount(DER3.getCurrency()), EPS * Math.abs(pvExpected)); final MultipleCurrencyAmount pvWithCalc = PVDC.visitCouponIborAverageFlatCompoundingSpread(DER3, MULTICURVES); assertEquals(pvWithCalc.getAmount(DER3.getCurrency()), pvComputed.getAmount(DER3.getCurrency()), EPS * Math.abs(pvExpected)); }