* @return The present value.
*/
public MultipleCurrencyAmount presentValue(final InstrumentDerivative instrument, final Currency ccy, final G2ppProviderInterface g2Data) {
MulticurveProviderInterface multicurves = g2Data.getMulticurveProvider();
G2ppPiecewiseConstantParameters parameters = g2Data.getG2ppParameters();
final DecisionSchedule decision = instrument.accept(DC, multicurves);
final double[] decisionTime = decision.getDecisionTime();
final double[][] impactTime = decision.getImpactTime();
final int nbJump = decisionTime.length;
final double numeraireTime = decisionTime[nbJump - 1];
final double pDN = multicurves.getDiscountFactor(ccy, numeraireTime);
// Discount factor to numeraire date for rebasing.
final double[][] pDI = new double[nbJump][];
// Initial discount factors to each impact date.
for (int loopjump = 0; loopjump < nbJump; loopjump++) {
pDI[loopjump] = new double[impactTime[loopjump].length];
for (int i = 0; i < impactTime[loopjump].length; i++) {
pDI[loopjump][i] = multicurves.getDiscountFactor(ccy, impactTime[loopjump][i]) / pDN;
}
}
final double rhog2pp = parameters.getCorrelation();
final double[][][] h = MODEL.volatilityMaturityPart(parameters, numeraireTime, impactTime); // factor/jump/cf
final double[][][] gamma = new double[nbJump][2][2]; // jump/factor/factor
final double[][] cov = new double[2 * nbJump][2 * nbJump]; // factor 0 - factor 1
for (int loopjump = 0; loopjump < nbJump; loopjump++) {
gamma[loopjump] = MODEL.gamma(parameters, 0.0, decisionTime[loopjump]);
for (int j = loopjump; j < nbJump; j++) {
cov[j][loopjump] = gamma[loopjump][0][0];
cov[loopjump][j] = gamma[loopjump][0][0];
cov[nbJump + j][nbJump + loopjump] = gamma[loopjump][1][1];
cov[nbJump + loopjump][nbJump + j] = gamma[loopjump][1][1];
cov[j][nbJump + loopjump] = rhog2pp * gamma[loopjump][0][1];
cov[loopjump][nbJump + j] = rhog2pp * gamma[loopjump][0][1];
cov[nbJump + j][loopjump] = rhog2pp * gamma[loopjump][0][1];
cov[nbJump + loopjump][j] = rhog2pp * gamma[loopjump][0][1];
}
}
final double[][][] alpha = new double[2][nbJump][]; // factor/jump/cf
final double[][] tau2 = new double[nbJump][];
for (int loopjump = 0; loopjump < nbJump; loopjump++) {
tau2[loopjump] = new double[impactTime[loopjump].length];
alpha[0][loopjump] = new double[impactTime[loopjump].length];
alpha[1][loopjump] = new double[impactTime[loopjump].length];
for (int loopcf = 0; loopcf < impactTime[loopjump].length; loopcf++) {
alpha[0][loopjump][loopcf] = Math.sqrt(gamma[loopjump][0][0]) * h[0][loopjump][loopcf];
alpha[1][loopjump][loopcf] = Math.sqrt(gamma[loopjump][1][1]) * h[1][loopjump][loopcf];
tau2[loopjump][loopcf] = alpha[0][loopjump][loopcf] * alpha[0][loopjump][loopcf] + alpha[1][loopjump][loopcf] * alpha[1][loopjump][loopcf] + 2 * rhog2pp * gamma[loopjump][0][1]
* h[0][loopjump][loopcf] * h[1][loopjump][loopcf];
}
}
final CholeskyDecompositionCommons cd = new CholeskyDecompositionCommons();
final CholeskyDecompositionResult cdr = cd.evaluate(new DoubleMatrix2D(cov));
final double[][] covCD = cdr.getL().getData();
final int nbBlock = (int) Math.round(Math.ceil(getNbPath() / ((double) BLOCK_SIZE)));
final int[] nbPath2 = new int[nbBlock];
for (int i = 0; i < nbBlock - 1; i++) {
nbPath2[i] = BLOCK_SIZE;
}
nbPath2[nbBlock - 1] = getNbPath() - (nbBlock - 1) * BLOCK_SIZE;
final double[][] impactAmount = decision.getImpactAmount();
double pv = 0;
for (int loopblock = 0; loopblock < nbBlock; loopblock++) {
final double[][] x = getNormalArray(2 * nbJump, nbPath2[loopblock]);
final double[][] y = new double[2 * nbJump][nbPath2[loopblock]]; // jump/path
for (int looppath = 0; looppath < nbPath2[loopblock]; looppath++) {