data[i] = new BlackFunctionData(F, 1, SVI.evaluate(strikes[i]));
options[i] = new EuropeanVanillaOption(strikes[i], T, true);
}
final double[] initialValues = new double[] {0.04, 1, -0.3, 0.2 };
final BitSet fixed = new BitSet();
final SABRHaganVolatilityFunction sabr = new SABRHaganVolatilityFunction();
final SABRNonLinearLeastSquareFitter fitter = new SABRNonLinearLeastSquareFitter(sabr);
final LeastSquareResultsWithTransform result = fitter.getFitResult(options, data, errors, initialValues, fixed);
final double chiSqr = result.getChiSq();
final DoubleMatrix1D params = result.getModelParameters();
final SABRFormulaData fittedData = new SABRFormulaData(params.getEntry(0), params.getEntry(1), params.getEntry(2), params.getEntry(3));
final Function1D<Double, Double> sabrFunction = new Function1D<Double, Double>() {
@Override
public Double evaluate(final Double k) {
final EuropeanVanillaOption option = new EuropeanVanillaOption(k, T, true);
return sabr.getVolatilityFunction(option, F).evaluate(fittedData);
}
};
final ProbabilityDistribution<Double> sabrDist = new DistributionFromImpliedVolatility(F, T, sabrFunction);