Package com.opengamma.analytics.math.interpolation.data

Examples of com.opengamma.analytics.math.interpolation.data.Interpolator1DCubicSplineDataBundle


  @Override
  public Double interpolate(final Interpolator1DDataBundle data, final Double value) {
    Validate.notNull(value, "value");
    Validate.notNull(data, "data bundle");
    Validate.isTrue(data instanceof Interpolator1DCubicSplineDataBundle);
    Interpolator1DCubicSplineDataBundle splineData = (Interpolator1DCubicSplineDataBundle) data;
    final int low = data.getLowerBoundIndex(value);
    final int high = low + 1;
    final int n = data.size() - 1;
    final double[] xData = data.getKeys();
    final double[] yData = data.getValues();
    if (data.getLowerBoundIndex(value) == n) {
      return yData[n];
    }
    final double delta = xData[high] - xData[low];
    if (Math.abs(delta) < _eps) {
      throw new MathException("x data points were not distinct");
    }
    final double a = (xData[high] - value) / delta;
    final double b = (value - xData[low]) / delta;
    final double[] y2 = splineData.getSecondDerivatives();
    return a * yData[low] + b * yData[high] + (a * (a * a - 1) * y2[low] + b * (b * b - 1) * y2[high]) * delta * delta / 6.;
  }
View Full Code Here


  @Override
  public double firstDerivative(final Interpolator1DDataBundle data, final Double value) {
    Validate.notNull(value, "value");
    Validate.notNull(data, "data bundle");
    Validate.isTrue(data instanceof Interpolator1DCubicSplineDataBundle);
    Interpolator1DCubicSplineDataBundle splineData = (Interpolator1DCubicSplineDataBundle) data;
    final int low = data.getLowerBoundIndex(value);
    final int high = low + 1;
    final int n = data.size() - 1;
    final double[] xData = data.getKeys();
    final double[] yData = data.getValues();
    if (data.getLowerBoundIndex(value) == n) {
      return yData[n];
    }
    final double delta = xData[high] - xData[low];
    if (Math.abs(delta) < _eps) {
      throw new MathException("x data points were not distinct");
    }
    final double a = (xData[high] - value) / delta;
    final double b = (value - xData[low]) / delta;
    final double[] y2 = splineData.getSecondDerivatives();
    return (yData[high] - yData[low]) / delta + ((-3. * a * a + 1.) * y2[low] + (3. * b * b - 1.) * y2[high]) * delta / 6.;
  }
View Full Code Here

  @Override
  public double[] getNodeSensitivitiesForValue(final Interpolator1DDataBundle data, final Double value) {
    Validate.notNull(data, "data");
    Validate.isTrue(data instanceof Interpolator1DCubicSplineDataBundle);
    Interpolator1DCubicSplineDataBundle cubicData = (Interpolator1DCubicSplineDataBundle) data;
    final int n = cubicData.size();
    final double[] result = new double[n];
    if (cubicData.getLowerBoundIndex(value) == n - 1) {
      result[n - 1] = 1.0;
      return result;
    }
    final double[] xData = cubicData.getKeys();
    final int low = cubicData.getLowerBoundIndex(value);
    final int high = low + 1;
    final double delta = xData[high] - xData[low];
    final double a = (xData[high] - value) / delta;
    final double b = (value - xData[low]) / delta;
    final double c = a * (a * a - 1) * delta * delta / 6.;
    final double d = b * (b * b - 1) * delta * delta / 6.;
    final double[][] y2Sensitivities = cubicData.getSecondDerivativesSensitivities();
    for (int i = 0; i < n; i++) {
      result[i] = c * y2Sensitivities[low][i] + d * y2Sensitivities[high][i];
    }
    result[low] += a;
    result[high] += b;
View Full Code Here

    return result;
  }

  @Override
  public Interpolator1DDataBundle getDataBundle(final double[] x, final double[] y) {
    return new Interpolator1DCubicSplineDataBundle(new ArrayInterpolator1DDataBundle(x, y));
  }
View Full Code Here

    return new Interpolator1DCubicSplineDataBundle(new ArrayInterpolator1DDataBundle(x, y));
  }

  @Override
  public Interpolator1DDataBundle getDataBundleFromSortedArrays(final double[] x, final double[] y) {
    return new Interpolator1DCubicSplineDataBundle(new ArrayInterpolator1DDataBundle(x, y, true));
  }
View Full Code Here

      y[0] = 0.0;
      System.arraycopy(_fpValues, 0, y, 1, m);
      y[m + 1] = 1.0;
      Interpolator1DDataBundle data = INTERPOLATOR.getDataBundleFromSortedArrays(x, y);
      final double grad = 1.0 / (nPoints - 1);
      _db = new Interpolator1DCubicSplineDataBundle(data, grad, grad);
    }
  }
View Full Code Here

    final int n = fwdTimes.length;
    final double[] rates = new double[n];
    for (int i = 0; i < n; i++) {
      rates[i] = FUNCTION.evaluate(fwdTimes[i]);
    }
    final Interpolator1DCubicSplineDataBundle data = new Interpolator1DCubicSplineDataBundle(INTERPOLATOR.getDataBundleFromSortedArrays(fwdTimes, rates));
    final double[] sensitivity1 = INTERPOLATOR.getNodeSensitivitiesForValue(data, 0.25);
    final double[] sensitivity2 = INTERPOLATOR.getNodeSensitivitiesForValue(data, 0.25, true);
    for (int j = 0; j < sensitivity1.length; j++) {
      assertEquals(sensitivity1[j], sensitivity2[j], EPS);
    }
View Full Code Here

    final double[] x = new double[] {0.0, 2.0, 3.0, 4.0, 5.0, 8.0, 12.0 };
    final double[] y = new double[] {0, 0.145000000000000, 0.190000000000000, 0.200000000000000, 0.250000000000000, 0.700000000000000, 1.000000000000000 };

    final double grad = 1. / 12;
    final Interpolator1DDataBundle nat = INTERPOLATOR.getDataBundleFromSortedArrays(x, y);
    final Interpolator1DCubicSplineDataBundle cub = new Interpolator1DCubicSplineDataBundle(nat, grad, grad);

    final double mlNat = 1.041605684280713;
    final double mlCub = 0.931260400907716;

    final double ans1 = INTERPOLATOR.interpolate(nat, 11.0);
View Full Code Here

  public void debugTest() {
    final double[] x = new double[] {0.0, 2.0, 3.0, 4.0, 5.0, 8.0, 12.0 };
    final double[] y = new double[] {0, 0.145000000000000, 0.190000000000000, 0.200000000000000, 0.250000000000000, 0.700000000000000, 1.000000000000000 };
    final double grad = 1. / 12;
    final Interpolator1DDataBundle nat = INTERPOLATOR.getDataBundleFromSortedArrays(x, y);
    final Interpolator1DCubicSplineDataBundle cub = new Interpolator1DCubicSplineDataBundle(nat, grad, grad);

    for (int i = 0; i < 121; i++) {
      final double xx = i / 10.0;
      final double yy1 = INTERPOLATOR.interpolate(nat, xx);
      final double yy2 = INTERPOLATOR.interpolate(cub, xx);
View Full Code Here

TOP

Related Classes of com.opengamma.analytics.math.interpolation.data.Interpolator1DCubicSplineDataBundle

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.