if (n == 3) {
if (gRes.getChiSq() / n > 1.0) {
s_logger.warn("chi^2 on SABR fit to ", +n + " points is " + gRes.getChiSq());
}
modelParams[0] = new SABRFormulaData(gRes.getModelParameters().getData());
} else {
//impose a global beta on the remaining 3 point fits
final double[] gFitParms = gRes.getModelParameters().getData();
final double beta = gFitParms[1];
start = new DoubleMatrix1D(gFitParms[0], gFitParms[2], gFitParms[3]);
final BroydenVectorRootFinder rootFinder = new BroydenVectorRootFinder();
double[] tStrikes = new double[3];
double[] tVols = new double[3];
for (int i = 0; i < n - 2; i++) {
tStrikes = Arrays.copyOfRange(strikes, i, i + 3);
tVols = Arrays.copyOfRange(impliedVols, i, i + 3);
final Function1D<DoubleMatrix1D, DoubleMatrix1D> func = getVolDiffFunc(forward, tStrikes, expiry, tVols);
final Function1D<DoubleMatrix1D, DoubleMatrix2D> jac = getVolJacFunc(forward, tStrikes, expiry, beta);
final NonLinearTransformFunction tf = new NonLinearTransformFunction(func, jac, TRANSFORM);
final DoubleMatrix1D res = rootFinder.getRoot(tf.getFittingFunction(), tf.getFittingJacobian(), start);
final double[] root = TRANSFORM.inverseTransform(res).getData();
modelParams[i] = new SABRFormulaData(new double[] {root[0], beta, root[1], root[2] });
}
}
return modelParams;
}