/**
* Tests the cash-flow equivalent of a fixed-Ibor swap.
*/
public void swapFixedIbor() {
final Annuity<Coupon> leg = SWAP.getSecondLeg();
CouponIbor cpnIbor = (CouponIbor) SWAP.getSecondLeg().getNthPayment(0);
final AnnuityPaymentFixed cfe = SWAP.accept(CFEC, CURVES);
assertEquals("Swap: Number of flows", FIXED_PAYMENT_PAYMENT_BY_YEAR * SWAP_TENOR_YEAR * 2 + 1, cfe.getNumberOfPayments());
assertEquals("Swap: Time", cpnIbor.getFixingPeriodStartTime(), cfe.getNthPayment(0).getPaymentTime(), 1E-5);
double beta = CURVES.getCurve(FORWARD_CURVE_NAME).getDiscountFactor(cpnIbor.getFixingPeriodStartTime()) / CURVES.getCurve(FORWARD_CURVE_NAME).getDiscountFactor(cpnIbor.getFixingPeriodEndTime())
* CURVES.getCurve(FUNDING_CURVE_NAME).getDiscountFactor(cpnIbor.getPaymentTime()) / CURVES.getCurve(FUNDING_CURVE_NAME).getDiscountFactor(cpnIbor.getFixingPeriodStartTime());
assertEquals("Swap: Amount", beta * NOTIONAL * (FIXED_IS_PAYER ? 1.0 : -1.0), cfe.getNthPayment(0).getAmount(), 1E-4);
CouponIbor cpnIborPrevious;
for (int loopcf = 2; loopcf < leg.getNumberOfPayments(); loopcf += 2) {
cpnIborPrevious = (CouponIbor) SWAP.getSecondLeg().getNthPayment(loopcf - 1);
cpnIbor = (CouponIbor) SWAP.getSecondLeg().getNthPayment(loopcf);
beta = CURVES.getCurve(FORWARD_CURVE_NAME).getDiscountFactor(cpnIbor.getFixingPeriodStartTime()) / CURVES.getCurve(FORWARD_CURVE_NAME).getDiscountFactor(cpnIbor.getFixingPeriodEndTime())
* CURVES.getCurve(FUNDING_CURVE_NAME).getDiscountFactor(cpnIbor.getPaymentTime()) / CURVES.getCurve(FUNDING_CURVE_NAME).getDiscountFactor(cpnIbor.getFixingPeriodStartTime());
assertEquals("Swap: Amount",
(beta * cpnIbor.getPaymentYearFraction() / cpnIbor.getFixingAccrualFactor() - 1 * cpnIborPrevious.getPaymentYearFraction() / cpnIborPrevious.getFixingAccrualFactor()) * NOTIONAL
* (FIXED_IS_PAYER ? 1.0 : -1.0) + SWAP.getFixedLeg().getNthPayment(loopcf / 2 - 1).getAmount(), cfe.getNthPayment(loopcf).getAmount(), 1E-4);
assertEquals("Swap: Time", leg.getNthPayment(loopcf - 1).getPaymentTime(), cfe.getNthPayment(loopcf).getPaymentTime(), 1E-5);
}
for (int loopcf = 1; loopcf < leg.getNumberOfPayments(); loopcf += 2) {
cpnIborPrevious = (CouponIbor) SWAP.getSecondLeg().getNthPayment(loopcf - 1);
cpnIbor = (CouponIbor) SWAP.getSecondLeg().getNthPayment(loopcf);
beta = CURVES.getCurve(FORWARD_CURVE_NAME).getDiscountFactor(cpnIbor.getFixingPeriodStartTime()) / CURVES.getCurve(FORWARD_CURVE_NAME).getDiscountFactor(cpnIbor.getFixingPeriodEndTime())
* CURVES.getCurve(FUNDING_CURVE_NAME).getDiscountFactor(cpnIbor.getPaymentTime()) / CURVES.getCurve(FUNDING_CURVE_NAME).getDiscountFactor(cpnIbor.getFixingPeriodStartTime());
assertEquals("Swap: Amount",
(beta * cpnIbor.getPaymentYearFraction() / cpnIbor.getFixingAccrualFactor() - 1 * cpnIborPrevious.getPaymentYearFraction() / cpnIborPrevious.getFixingAccrualFactor()) * NOTIONAL
* (FIXED_IS_PAYER ? 1.0 : -1.0), cfe.getNthPayment(loopcf).getAmount(), 1E-4);
assertEquals("Swap: Time", leg.getNthPayment(loopcf - 1).getPaymentTime(), cfe.getNthPayment(loopcf).getPaymentTime(), 1E-5);
}
assertEquals("Swap: Amount", (-1 * NOTIONAL * (FIXED_IS_PAYER ? 1.0 : -1.0)) + SWAP.getFixedLeg().getNthPayment(SWAP.getFixedLeg().getNumberOfPayments() - 1).getAmount(),
cfe.getNthPayment(leg.getNumberOfPayments()).getAmount(), 1E-4);