final double[][] cpnRate = new double[nbCpn][nbPath];
final double[] annuityPathValue = new double[nbPath];
double ibor;
for (int loopcpn = 0; loopcpn < nbCpn; loopcpn++) { //nbCpn
if (annuity.isFixed()[loopcpn]) { // Coupon already fixed: only one cash flow
final CouponFixed cpn = (CouponFixed) annuity.getNthPayment(loopcpn);
for (int looppath = 0; looppath < nbPath; looppath++) {
cpnRate[loopcpn][looppath] = cpn.getFixedRate();
annuityPathValue[looppath] += impactAmount[loopcpn][0] * discounting[loopcpn][impactIndex[loopcpn][0]][looppath];
}
} else {
if (annuity.getNthPayment(loopcpn) instanceof CouponIborRatchet) {
final CouponIborRatchet cpn = (CouponIborRatchet) annuity.getNthPayment(loopcpn);
for (int looppath = 0; looppath < nbPath; looppath++) {
ibor = (-impactAmount[loopcpn][0] * discounting[loopcpn][impactIndex[loopcpn][0]][looppath] / (impactAmount[loopcpn][1] * discounting[loopcpn][impactIndex[loopcpn][1]][looppath]) - 1.0)
/ cpn.getFixingAccrualFactor();
final double cpnMain = cpn.getMainCoefficients()[0] * cpnRate[loopcpn - 1][looppath] + cpn.getMainCoefficients()[1] * ibor + cpn.getMainCoefficients()[2];
final double cpnFloor = cpn.getFloorCoefficients()[0] * cpnRate[loopcpn - 1][looppath] + cpn.getFloorCoefficients()[1] * ibor + cpn.getFloorCoefficients()[2];
final double cpnCap = cpn.getCapCoefficients()[0] * cpnRate[loopcpn - 1][looppath] + cpn.getCapCoefficients()[1] * ibor + cpn.getCapCoefficients()[2];
cpnRate[loopcpn][looppath] = Math.min(Math.max(cpnFloor, cpnMain), cpnCap);
annuityPathValue[looppath] += cpnRate[loopcpn][looppath] * cpn.getPaymentYearFraction() * cpn.getNotional() * discounting[loopcpn][impactIndex[loopcpn][1]][looppath];
}
} else {
final CouponIborGearing cpn = (CouponIborGearing) annuity.getNthPayment(loopcpn); // Only possible for the first coupon
for (int looppath = 0; looppath < nbPath; looppath++) {
ibor = (-impactAmount[0][0] * discounting[loopcpn][impactIndex[loopcpn][0]][looppath] / (impactAmount[0][1] * discounting[loopcpn][impactIndex[loopcpn][1]][looppath]) - 1.0)
/ cpn.getFixingAccrualFactor();
cpnRate[loopcpn][looppath] = cpn.getFactor() * ibor + cpn.getSpread();
annuityPathValue[looppath] += cpnRate[loopcpn][looppath] * cpn.getPaymentYearFraction() * cpn.getNotional() * discounting[loopcpn][impactIndex[loopcpn][1]][looppath];
}
}
}
}
double price = 0.0;