SwaptionPhysicalFixedIborHullWhiteMethod { public double[] presentValueHullWhiteSensitivity(final SwaptionPhysicalFixedIbor swaption, final HullWhiteOneFactorProviderInterface hullWhite) { ArgumentChecker.notNull(swaption, "Swaption"); ArgumentChecker.notNull(hullWhite, "Hull-White provider"); final int nbSigma = hullWhite.getHullWhiteParameters().getVolatility().length; final double[] sigmaBar = new double[nbSigma]; final AnnuityPaymentFixed cfe = swaption.getUnderlyingSwap().accept(CFEC, hullWhite.getMulticurveProvider()); final double expiryTime = swaption.getTimeToExpiry(); final double[] alpha = new double[cfe.getNumberOfPayments()]; final double[][] alphaDerivatives = new double[cfe.getNumberOfPayments()][nbSigma]; final double[] df = new double[cfe.getNumberOfPayments()]; final double[] discountedCashFlow = new double[cfe.getNumberOfPayments()]; for (int loopcf = 0; loopcf < cfe.getNumberOfPayments(); loopcf++) { alpha[loopcf] = MODEL.alpha(hullWhite.getHullWhiteParameters(), 0.0, expiryTime, expiryTime, cfe.getNthPayment(loopcf).getPaymentTime(), alphaDerivatives[loopcf]); df[loopcf] = hullWhite.getMulticurveProvider().getDiscountFactor(swaption.getCurrency(), cfe.getNthPayment(loopcf).getPaymentTime()); discountedCashFlow[loopcf] = df[loopcf] * cfe.getNthPayment(loopcf).getAmount(); } final double kappa = MODEL.kappa(discountedCashFlow, alpha); final double omega = (swaption.getUnderlyingSwap().getFixedLeg().isPayer() ? -1.0 : 1.0); final double pvBar = 1.0; final double[] alphaBar = new double[cfe.getNumberOfPayments()]; for (int loopcf = 0; loopcf < cfe.getNumberOfPayments(); loopcf++) { alphaBar[loopcf] = discountedCashFlow[loopcf] * NORMAL.getPDF(omega * (kappa + alpha[loopcf])) * omega * pvBar; } for (int loopsigma = 0; loopsigma < nbSigma; loopsigma++) { for (int loopcf = 0; loopcf < cfe.getNumberOfPayments(); loopcf++) { sigmaBar[loopsigma] += alphaDerivatives[loopcf][loopsigma] * alphaBar[loopcf]; } } if (!swaption.isLong()) { for (int loopsigma = 0; loopsigma < nbSigma; loopsigma++) { sigmaBar[loopsigma] *= -1.0; } } return sigmaBar; } private  SwaptionPhysicalFixedIborHullWhiteMethod(); static SwaptionPhysicalFixedIborHullWhiteMethod getInstance(); MultipleCurrencyAmount presentValue(final SwaptionPhysicalFixedIbor swaption, final HullWhiteOneFactorProviderInterface hullWhite); MultipleCurrencyAmount presentValue(final SwaptionPhysicalFixedIbor swaption, final AnnuityPaymentFixed cfe, final HullWhiteOneFactorProviderInterface hullWhite); double[] presentValueHullWhiteSensitivity(final SwaptionPhysicalFixedIbor swaption, final HullWhiteOneFactorProviderInterface hullWhite); MultipleCurrencyMulticurveSensitivity presentValueCurveSensitivity(final SwaptionPhysicalFixedIbor swaption, final HullWhiteOneFactorProviderInterface hullWhite);  }
@Test public void presentValueHullWhiteSensitivitylongShortParityExplicit() { final double[] pvhwsLong = METHOD_HW.presentValueHullWhiteSensitivity(SWAPTION_LONG_PAYER, HW_MULTICURVES); final double[] pvhwsShort = METHOD_HW.presentValueHullWhiteSensitivity(SWAPTION_SHORT_PAYER, HW_MULTICURVES); for (int loophw = 0; loophw < pvhwsLong.length; loophw++) { assertEquals("Swaption physical - Hull-White - presentValueHullWhiteSensitivity - long/short parity", pvhwsLong[loophw], -pvhwsShort[loophw], TOLERANCE_PV_DELTA); } }
@Test public void presentValueHullWhiteSensitivitypayerReceiverParityExplicit() { final double[] pvhwsReceiverLong = METHOD_HW.presentValueHullWhiteSensitivity(SWAPTION_LONG_RECEIVER, HW_MULTICURVES); final double[] pvhwsPayerShort = METHOD_HW.presentValueHullWhiteSensitivity(SWAPTION_SHORT_PAYER, HW_MULTICURVES); for (int loophw = 0; loophw < pvhwsReceiverLong.length; loophw++) { assertEquals("Swaption physical - Hull-White - present value - payer/receiver/swap parity", 0, pvhwsReceiverLong[loophw] + pvhwsPayerShort[loophw], TOLERANCE_PV_DELTA); } }