final double[] sigma = new double[MARKET_PRICES.length];
Arrays.fill(sigma, 0.0001); // 1bps
final NonLinearLeastSquare ls = new NonLinearLeastSquare();
final LeastSquareResults lsRes = ls.solve(new DoubleMatrix1D(MARKET_VOLS), new DoubleMatrix1D(sigma), func, jac, START);
final DoubleMatrix1D res = lsRes.getFitParameters();
assertTrue("chi^2 too large", lsRes.getChiSq() < 0.3);
// We don't recover exactly the initial curves. Why?
final LinkedHashMap<String, InterpolatedDoublesCurve> curves = CURVE_BUILDER.evaluate(res);
for (final String name : NAMES) {
final Curve<Double, Double> fitCurve = curves.get(name);
final ParameterLimitsTransform trans = TRANSFORMS.get(name);
final Curve<Double, Double> initialCurve = CURVES.get(name);
for (int i = 0; i < 25; i++) {
final double t = i * 20. / 25;
assertEquals(name + " - time: " + t, initialCurve.getYValue(t), trans.inverseTransform(fitCurve.getYValue(t)), 5e-2);
}
}
// diagnostics
final boolean print = false;
if (print) {
System.out.println("CapletStripingTest");
}
final VolatilityModel1D volModel = VOL_MODEL_PROVIDER.evaluate(lsRes.getFitParameters());
final Iterator<CapFloor> iter = CAPS.iterator();
CapFloor cap;
int i = 0;
while (iter.hasNext()) {