super(numberGenerator, nbPath);
_maxJump = maxJump;
}
public MultipleCurrencyAmount presentValue(final InstrumentDerivative instrument, final Currency ccy, final LiborMarketModelDisplacedDiffusionProvider lmmData) {
final MulticurveProviderInterface multicurves = lmmData.getMulticurveProvider();
final LiborMarketModelDisplacedDiffusionParameters parameters = lmmData.getLMMParameters();
// The numeraire is the last time in the LMM description.
final DecisionSchedule decision = instrument.accept(DC, multicurves);
final int[][] impactIndex = index(decision.getImpactTime(), parameters);
final int nbPeriodLMM = parameters.getNbPeriod();
final double[] initL = new double[nbPeriodLMM];
final double[] deltaLMM = parameters.getAccrualFactor();
final double[] dfL = new double[nbPeriodLMM + 1];
for (int loopper = 0; loopper < nbPeriodLMM + 1; loopper++) {
dfL[loopper] = multicurves.getDiscountFactor(ccy, parameters.getIborTime()[loopper]);
}
for (int loopper = 0; loopper < nbPeriodLMM; loopper++) {
initL[loopper] = (dfL[loopper] / dfL[loopper + 1] - 1.0) / deltaLMM[loopper];
}
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;
double price = 0.0;
for (int loopblock = 0; loopblock < nbBlock; loopblock++) {
final double[][] initLPath = new double[nbPeriodLMM][nbPath2[loopblock]];
for (int loopper = 0; loopper < nbPeriodLMM; loopper++) {
for (int looppath = 0; looppath < nbPath2[loopblock]; looppath++) {
initLPath[loopper][looppath] = initL[loopper];
}
}
final double[][][] pathIbor = pathgeneratorlibor(decision.getDecisionTime(), initLPath, parameters);
price += instrument.accept(MCC, new MonteCarloIborRateDataBundle(pathIbor, deltaLMM, decision.getImpactAmount(), impactIndex));
}
price *= multicurves.getDiscountFactor(ccy, parameters.getIborTime()[parameters.getIborTime().length - 1]) / getNbPath();
return MultipleCurrencyAmount.of(ccy, price);
}