@Test
/**
* Approximation analysis.
*/
public void presentValueApproximationAnalysis() {
final BlackImpliedVolatilityFormula implied = new BlackImpliedVolatilityFormula();
final int nbStrike = 20;
final double[] pvExplicit = new double[nbStrike + 1];
final double[] pvApproximation = new double[nbStrike + 1];
final double[] strike = new double[nbStrike + 1];
final double[] volExplicit = new double[nbStrike + 1];
final double[] volApprox = new double[nbStrike + 1];
final double strikeRange = 0.035;
final SwapFixedCoupon<Coupon> swap = SWAP_PAYER_DEFINITION.toDerivative(REFERENCE_DATE, CURVES_NAME);
final double forward = swap.accept(ParRateCalculator.getInstance(), CURVES);
final double pvbp = METHOD_SWAP.presentValueBasisPoint(swap, CURVES);
for (int loopstrike = 0; loopstrike <= nbStrike; loopstrike++) {
strike[loopstrike] = forward - strikeRange + 3 * strikeRange * loopstrike / nbStrike; // From forward-strikeRange to forward+2*strikeRange
final SwapFixedIborDefinition swapDefinition = SwapFixedIborDefinition.from(SETTLEMENT_DATE, CMS_INDEX, NOTIONAL, strike[loopstrike], FIXED_IS_PAYER, CALENDAR);
final SwaptionPhysicalFixedIborDefinition swaptionDefinition = SwaptionPhysicalFixedIborDefinition.from(EXPIRY_DATE, swapDefinition, IS_LONG);
final SwaptionPhysicalFixedIbor swaption = swaptionDefinition.toDerivative(REFERENCE_DATE, CURVES_NAME);
pvExplicit[loopstrike] = METHOD_HW.presentValue(swaption, BUNDLE_HW).getAmount();
pvApproximation[loopstrike] = METHOD_HW_APPROXIMATION.presentValue(swaption, BUNDLE_HW).getAmount();
final BlackFunctionData data = new BlackFunctionData(forward, pvbp, 0.20);
volExplicit[loopstrike] = implied.getImpliedVolatility(data, swaption, pvExplicit[loopstrike]);
volApprox[loopstrike] = implied.getImpliedVolatility(data, swaption, pvApproximation[loopstrike]);
assertEquals("Swaption physical - Hull-White - implied volatility - explicit/approximation", volExplicit[loopstrike], volApprox[loopstrike], 0.1E-2); // 0.10%
}
}