HullWhiteOneFactorPiecewiseConstantInterestRateModel { public double kappa(final double[] discountedCashFlow, final double[] alpha) { final Function1D<Double, Double> swapValue = new Function1D<Double, Double>() { @Override public Double evaluate(final Double x) { double error = 0.0; for (int loopcf = 0; loopcf < alpha.length; loopcf++) { error += discountedCashFlow[loopcf] * Math.exp(-0.5 * alpha[loopcf] * alpha[loopcf] - (alpha[loopcf] - alpha[0]) * x); } return error; } }; final BracketRoot bracketer = new BracketRoot(); double accuracy = 1.0E-8; final RidderSingleRootFinder rootFinder = new RidderSingleRootFinder(accuracy); final double[] range = bracketer.getBracketedPoints(swapValue, -2.0, 2.0); return rootFinder.getRoot(swapValue, range[0], range[1]); }  double futuresConvexityFactor(final HullWhiteOneFactorPiecewiseConstantParameters data, double t0, double t1, double t2); double futuresConvexityFactor(final HullWhiteOneFactorPiecewiseConstantParameters data, final double t0, final double t1, final double t2, final double[] derivatives); double paymentDelayConvexityFactor(final HullWhiteOneFactorPiecewiseConstantParameters parameters, final double startExpiry, final double endExpiry,
      final double u, final double v, final double tp); double alpha(final HullWhiteOneFactorPiecewiseConstantParameters data, final double startExpiry, final double endExpiry, final double numeraireTime, final double bondMaturity); double alpha(final HullWhiteOneFactorPiecewiseConstantParameters data, final double startExpiry, final double endExpiry, final double numeraireTime, final double bondMaturity,
      double[] derivatives); double kappa(final double[] discountedCashFlow, final double[] alpha); double beta(final HullWhiteOneFactorPiecewiseConstantParameters data, final double startExpiry, final double endExpiry); double lambda(final double[] discountedCashFlow, final double[] alpha2, final double[] hwH); double[][] volatilityMaturityPart(final HullWhiteOneFactorPiecewiseConstantParameters hwParameters, double u, double[][] v); double gamma(final HullWhiteOneFactorPiecewiseConstantParameters hwParameters, double theta0, double theta1); double swapRate(final double x, final double[] discountedCashFlowFixed, final double[] alphaFixed, final double[] discountedCashFlowIbor, final double[] alphaIbor); double swapRateDx1(final double x, final double[] discountedCashFlowFixed, final double[] alphaFixed, final double[] discountedCashFlowIbor, final double[] alphaIbor); double swapRateDx2(final double x, final double[] discountedCashFlowFixed, final double[] alphaFixed, final double[] discountedCashFlowIbor, final double[] alphaIbor); double[] swapRateDdcfi1(final double x, final double[] discountedCashFlowFixed, final double[] alphaFixed, final double[] discountedCashFlowIbor, final double[] alphaIbor); double[] swapRateDdcff1(final double x, final double[] discountedCashFlowFixed, final double[] alphaFixed, final double[] discountedCashFlowIbor, final double[] alphaIbor); double[] swapRateDai1(final double x, final double[] discountedCashFlowFixed, final double[] alphaFixed, final double[] discountedCashFlowIbor, final double[] alphaIbor); double[] swapRateDaf1(final double x, final double[] discountedCashFlowFixed, final double[] alphaFixed, final double[] discountedCashFlowIbor, final double[] alphaIbor); Pair<double[], double[]> swapRateDx2Ddcf1(final double x, final double[] discountedCashFlowFixed, final double[] alphaFixed, final double[] discountedCashFlowIbor, final double[] alphaIbor); Pair<double[], double[]> swapRateDx2Da1(final double x, final double[] discountedCashFlowFixed, final double[] alphaFixed, final double[] discountedCashFlowIbor, final double[] alphaIbor);  }
@Test public void kappa() { final double[] cashFlowAmount = new double[] {-1.0, 0.05, 0.05, 0.05, 0.05, 1.05 }; final double notional = 100000000; final double[] cashFlowTime = new double[] {10.0, 11.0, 12.0, 13.0, 14.00, 15.00 }; final double expiryTime = cashFlowTime[0] - 2.0 / 365.0; final int nbCF = cashFlowAmount.length; final double[] discountedCashFlow = new double[nbCF]; final double[] alpha = new double[nbCF]; final double rate = 0.04; for (int loopcf = 0; loopcf < nbCF; loopcf++) { discountedCashFlow[loopcf] = cashFlowAmount[loopcf] * Math.exp(-rate * cashFlowTime[loopcf]) * notional; alpha[loopcf] = MODEL.alpha(MODEL_PARAMETERS, 0.0, expiryTime, expiryTime, cashFlowTime[loopcf]); } final double kappa = MODEL.kappa(discountedCashFlow, alpha); double swapValue = 0.0; for (int loopcf = 0; loopcf < nbCF; loopcf++) { swapValue += discountedCashFlow[loopcf] * Math.exp(-Math.pow(alpha[loopcf], 2.0) / 2.0 - alpha[loopcf] * kappa); } assertEquals("Exercise boundary", 0.0, swapValue, 1.0E-1); }