List of usage examples for org.apache.commons.math.analysis.interpolation SplineInterpolator interpolate
public PolynomialSplineFunction interpolate(double x[], double y[])
From source file:ch.algotrader.option.OptionUtil.java
/** * Gets the implied volatility of a {@link Option} based on a {@link SABRSurfaceVO}. *//*w w w . jav a 2 s .co m*/ public static double getImpliedVolatilitySABR(final double underlyingSpot, final double strike, final double years, final double intrest, final double dividend, final OptionType type, final SABRSurfaceVO surface) throws MathException { double forward = getForward(underlyingSpot, years, intrest, dividend); // get sabrVolas for all durations at the specified strike int i = 0; double[] yearsArray = new double[surface.getSmiles().size()]; double[] volArray = new double[surface.getSmiles().size()]; for (SABRSmileVO smile : surface.getSmiles()) { double vol = SABR.volByAtmVol(forward, strike, smile.getAtmVol(), smile.getYears(), beta, smile.getRho(), smile.getVolVol()); yearsArray[i] = smile.getYears(); volArray[i] = vol; i++; } // spline interpolation for years SplineInterpolator interpolator = new SplineInterpolator(); PolynomialSplineFunction function = interpolator.interpolate(yearsArray, volArray); return function.value(years); }