Example usage for org.apache.commons.math.analysis.interpolation SplineInterpolator interpolate

List of usage examples for org.apache.commons.math.analysis.interpolation SplineInterpolator interpolate

Introduction

In this page you can find the example usage for org.apache.commons.math.analysis.interpolation SplineInterpolator interpolate.

Prototype

public PolynomialSplineFunction interpolate(double x[], double y[]) 

Source Link

Document

Computes an interpolating function for the data set.

Usage

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);
}