}
// Calibration and price
final LiborMarketModelDisplacedDiffusionParameters lmmParameters = TestsDataSetLiborMarketModelDisplacedDiffusion.createLMMParametersDisplacementAngle(REFERENCE_DATE,
swapCalibrationDefinition[swapTenorYear.length - 1].getIborLeg(), 0.10, Math.PI / 2);
final SwaptionPhysicalLMMDDSuccessiveRootFinderCalibrationObjective objective = new SwaptionPhysicalLMMDDSuccessiveRootFinderCalibrationObjective(lmmParameters);
final SuccessiveRootFinderCalibrationEngine calibrationEngine = new SwaptionPhysicalLMMDDSuccessiveRootFinderCalibrationEngine(objective);
calibrationEngine.addInstrument(swaptionCalibration2, METHOD_SABR);
calibrationEngine.calibrate(sabrBundle);
final LiborMarketModelDisplacedDiffusionDataBundle lmmBundle = new LiborMarketModelDisplacedDiffusionDataBundle(lmmParameters, CURVES);
final CurrencyAmount pvAmortized = METHOD_LMM.presentValue(swaptionAmortized, lmmBundle);
final double pvAmortizedPrevious = 3058997.117;
assertEquals("LMM Amortized pricing", pvAmortizedPrevious, pvAmortized.getAmount(), 1.0E-2);
// Method
final SwaptionPhysicalFixedIborSABRLMMExactMethod method = new SwaptionPhysicalFixedIborSABRLMMExactMethod();
final CurrencyAmount pvAmortizedMethod = method.presentValue(swaptionAmortized, sabrBundle);
assertEquals("LMM Amortized pricing", pvAmortized.getAmount(), pvAmortizedMethod.getAmount(), 1.0E-2);
// SABR parameters sensitivity in all-in-one method.
final List<Object> results = method.presentValueCurveSABRSensitivity(swaptionAmortized, sabrBundle);
final InterestRateCurveSensitivity pvcs1 = (InterestRateCurveSensitivity) results.get(1);
final PresentValueSABRSensitivityDataBundle pvss1 = (PresentValueSABRSensitivityDataBundle) results.get(2);
// SABR parameters sensitivity
final PresentValueSABRSensitivityDataBundle pvss = method.presentValueSABRSensitivity(swaptionAmortized, sabrBundle);
// SABR parameters sensitivity (all-in-one)
for (final SwaptionPhysicalFixedIbor element : swaptionCalibration) {
final DoublesPair expiryMaturity = new DoublesPair(element.getTimeToExpiry(), element.getMaturityTime());
assertEquals("Sensitivity swaption pv to alpha", pvss1.getAlpha().getMap().get(expiryMaturity), pvss.getAlpha().getMap().get(expiryMaturity), 1E-2);
assertEquals("Sensitivity swaption pv to rho", pvss1.getRho().getMap().get(expiryMaturity), pvss.getRho().getMap().get(expiryMaturity), 1E-2);
assertEquals("Sensitivity swaption pv to nu", pvss1.getNu().getMap().get(expiryMaturity), pvss.getNu().getMap().get(expiryMaturity), 1E-2);
}
// SABR parameters sensitivity (parallel shift check)
SABRInterestRateParameters sabrParameterShift;
SABRInterestRateDataBundle sabrBundleShift;
final LiborMarketModelDisplacedDiffusionParameters lmmParametersShift = TestsDataSetLiborMarketModelDisplacedDiffusion.createLMMParametersDisplacementAngle(REFERENCE_DATE,
swapCalibrationDefinition[swapTenorYear.length - 1].getIborLeg(), 0.10, Math.PI / 2);
final SwaptionPhysicalLMMDDSuccessiveRootFinderCalibrationObjective objectiveShift = new SwaptionPhysicalLMMDDSuccessiveRootFinderCalibrationObjective(lmmParametersShift);
final SuccessiveRootFinderCalibrationEngine calibrationEngineShift = new SwaptionPhysicalLMMDDSuccessiveRootFinderCalibrationEngine(objectiveShift);
calibrationEngineShift.addInstrument(swaptionCalibration2, METHOD_SABR);
final LiborMarketModelDisplacedDiffusionDataBundle lmmBundleShift = new LiborMarketModelDisplacedDiffusionDataBundle(lmmParametersShift, CURVES);
double alphaVegaTotalComputed = 0.0;
assertEquals("Number of alpha sensitivity", pvss.getAlpha().getMap().keySet().size(), swaptionCalibration.length);
for (final SwaptionPhysicalFixedIbor element : swaptionCalibration) {
final DoublesPair expiryMaturity = new DoublesPair(element.getTimeToExpiry(), element.getMaturityTime());
alphaVegaTotalComputed += pvss.getAlpha().getMap().get(expiryMaturity);
}
final double shiftAlpha = 0.00001;
sabrParameterShift = TestsDataSetsSABR.createSABR1AlphaBumped(shiftAlpha);
sabrBundleShift = new SABRInterestRateDataBundle(sabrParameterShift, CURVES);
calibrationEngineShift.calibrate(sabrBundleShift);
final CurrencyAmount pvAmortizedShiftAlpha = METHOD_LMM.presentValue(swaptionAmortized, lmmBundleShift);
final double alphaVegaTotalExpected = (pvAmortizedShiftAlpha.getAmount() - pvAmortized.getAmount()) / shiftAlpha;
assertEquals("Alpha sensitivity value", alphaVegaTotalExpected, alphaVegaTotalComputed, 1.0E+2);
double rhoVegaTotalComputed = 0.0;
assertEquals("Number of alpha sensitivity", pvss.getRho().getMap().keySet().size(), swaptionCalibration.length);
for (final SwaptionPhysicalFixedIbor element : swaptionCalibration) {
final DoublesPair expiryMaturity = new DoublesPair(element.getTimeToExpiry(), element.getMaturityTime());
rhoVegaTotalComputed += pvss.getRho().getMap().get(expiryMaturity);
}
final double shiftRho = 0.00001;
sabrParameterShift = TestsDataSetsSABR.createSABR1RhoBumped(shiftRho);
sabrBundleShift = new SABRInterestRateDataBundle(sabrParameterShift, CURVES);
calibrationEngineShift.calibrate(sabrBundleShift);
final CurrencyAmount pvAmortizedShiftRho = METHOD_LMM.presentValue(swaptionAmortized, lmmBundleShift);
final double rhoVegaTotalExpected = (pvAmortizedShiftRho.getAmount() - pvAmortized.getAmount()) / shiftRho;
assertEquals("Rho sensitivity value", rhoVegaTotalExpected, rhoVegaTotalComputed, 1.0E+1);
double nuVegaTotalComputed = 0.0;
assertEquals("Number of alpha sensitivity", pvss.getNu().getMap().keySet().size(), swaptionCalibration.length);
for (final SwaptionPhysicalFixedIbor element : swaptionCalibration) {
final DoublesPair expiryMaturity = new DoublesPair(element.getTimeToExpiry(), element.getMaturityTime());
nuVegaTotalComputed += pvss.getNu().getMap().get(expiryMaturity);
}
final double shiftNu = 0.00001;
sabrParameterShift = TestsDataSetsSABR.createSABR1NuBumped(shiftNu);
sabrBundleShift = new SABRInterestRateDataBundle(sabrParameterShift, CURVES);
calibrationEngineShift.calibrate(sabrBundleShift);
final CurrencyAmount pvAmortizedShiftNu = METHOD_LMM.presentValue(swaptionAmortized, lmmBundleShift);
final double nuVegaTotalExpected = (pvAmortizedShiftNu.getAmount() - pvAmortized.getAmount()) / shiftNu;
assertEquals("Nu sensitivity value", nuVegaTotalExpected, nuVegaTotalComputed, 1.0E+1);
// Curve sensitivity