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

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


  public Double interpolate(final Interpolator1DDataBundle data, final Double value) {

    Validate.notNull(value, "Value to be interpolated must not be null");
    Validate.notNull(data, "Data bundle must not be null");
    try {
      final InterpolationBoundedValues boundedValues = data.getBoundedValues(value);

      // Avoid divide by zero errors (offset factors out of the final result if it is used)
      //R White where does this come from? The economically relevant quantity is x*y which is the (negative) log of the survival rate,
      //which is 0 for x (i.e. time t) equal 0. What this does is return y(1) for x = 0.0, which is arbitrary. 
      final double offset = value == 0.0 ? 1.0 : 0.0;

      final double x1 = boundedValues.getLowerBoundKey();
      final double y1 = boundedValues.getLowerBoundValue();
      final double y1x1 = y1 * (x1 + offset);

      if (data.getLowerBoundIndex(value) == data.size() - 1) {
        return y1;
      }

      final double x2 = boundedValues.getHigherBoundKey();
      final double y2 = boundedValues.getHigherBoundValue();
      final double y2x2 = y2 * (x2 + offset);

      return (y1x1 + (value - x1) / (x2 - x1) * (y2x2 - y1x1)) / (value + offset);
    } catch (final ArrayIndexOutOfBoundsException e) {
      throw e;
View Full Code Here


  public double firstDerivative(final Interpolator1DDataBundle data, final Double value) {

    Validate.notNull(value, "Value to be interpolated must not be null");
    Validate.notNull(data, "Data bundle must not be null");
    try {
      final InterpolationBoundedValues boundedValues = data.getBoundedValues(value);

      final double offset = value == 0.0 ? 1.0 : 0.0;

      final double x1 = boundedValues.getLowerBoundKey();
      final double y1 = boundedValues.getLowerBoundValue();
      final double y1x1 = y1 * (x1 + offset);

      if (data.getLowerBoundIndex(value) == data.size() - 1) {
        return 0.;
      }

      final double x2 = boundedValues.getHigherBoundKey();
      final double y2 = boundedValues.getHigherBoundValue();
      final double y2x2 = y2 * (x2 + offset);

      final double valueWithOffset = value + offset;
      return (y2x2 - y1x1) / (x2 - x1) / valueWithOffset - (y1x1 + (value - x1) / (x2 - x1) * (y2x2 - y1x1)) / valueWithOffset / valueWithOffset;
    } catch (final ArrayIndexOutOfBoundsException e) {
View Full Code Here

  @Override
  public Double interpolate(final Interpolator1DDataBundle model, final Double value) {
    Validate.notNull(value, "Value to be interpolated must not be null");
    Validate.notNull(model, "Data bundle must not be null");
    final InterpolationBoundedValues boundedValues = model.getBoundedValues(value);
    final double x1 = boundedValues.getLowerBoundKey();
    final double y1 = boundedValues.getLowerBoundValue();
    if (model.getLowerBoundIndex(value) == model.size() - 1) {
      return y1;
    }
    final double x2 = boundedValues.getHigherBoundKey();
    final double y2 = boundedValues.getHigherBoundValue();
    return y1 + (value - x1) / (x2 - x1) * (y2 - y1);
  }
View Full Code Here

  @Override
  public double firstDerivative(final Interpolator1DDataBundle model, final Double value) {
    Validate.notNull(value, "Value to be interpolated must not be null");
    Validate.notNull(model, "Data bundle must not be null");
    final InterpolationBoundedValues boundedValues = model.getBoundedValues(value);
    final double x1 = boundedValues.getLowerBoundKey();
    final double y1 = boundedValues.getLowerBoundValue();
    if (model.getLowerBoundIndex(value) == model.size() - 1) {
      return 0.;
    }
    final double x2 = boundedValues.getHigherBoundKey();
    final double y2 = boundedValues.getHigherBoundValue();
    return (y2 - y1) / (x2 - x1);
  }
View Full Code Here

  @Override
  public double[] getNodeSensitivitiesForValue(final Interpolator1DDataBundle data, final Double value) {
    Validate.notNull(data, "data");
    final int n = data.size();
    final double[] result = new double[n];
    final InterpolationBoundedValues boundedValues = data.getBoundedValues(value);
    if (boundedValues.getHigherBoundKey() == null) {
      result[n - 1] = 1.0;
      return result;
    }
    final int index = data.getLowerBoundIndex(value);
    final double x1 = boundedValues.getLowerBoundKey();
    final double x2 = boundedValues.getHigherBoundKey();
    final double dx = x2 - x1;
    final double a = (x2 - value) / dx;
    final double b = 1 - a;
    result[index] = a;
    result[index + 1] = b;
View Full Code Here

  @Override
  public Double interpolate(final Interpolator1DDataBundle model, final Double value) {
    Validate.notNull(value, "value");
    Validate.notNull(model, "data bundle");
    final InterpolationBoundedValues boundedValues = model.getBoundedValues(value);
    final Double x1 = boundedValues.getLowerBoundKey();
    final Double y1 = boundedValues.getLowerBoundValue();
    if (model.getLowerBoundIndex(value) == model.size() - 1) {
      return y1;
    }
    final Double x2 = boundedValues.getHigherBoundKey();
    final Double y2 = boundedValues.getHigherBoundValue();

    // nodes and values for the step interpolator
    final double[] nodes = new double[12];
    final double[] values = new double[12];
    nodes[0] = x1;
View Full Code Here

  @Override
  public Double interpolate(final Interpolator1DDataBundle data, final Double value) {
    Validate.notNull(value, "Value to be interpolated must not be null");
    ArgumentChecker.isTrue(value > 0, "Value should be stricly positive");
    Validate.notNull(data, "Data bundle must not be null");
    final InterpolationBoundedValues boundedValues = data.getBoundedValues(value);
    final double x1 = boundedValues.getLowerBoundKey();
    final double y1 = boundedValues.getLowerBoundValue();
    if (data.getLowerBoundIndex(value) == data.size() - 1) {
      return y1;
    }
    final double x2 = boundedValues.getHigherBoundKey();
    final double y2 = boundedValues.getHigherBoundValue();
    final double w = (x2 - value) / (x2 - x1);
    final double xy21 = x1 * y1 * y1;
    final double xy22 = x2 * y2 * y2;
    final double xy2 = w * xy21 + (1 - w) * xy22;
    return Math.sqrt(xy2 / value);
View Full Code Here

  @Override
  public double firstDerivative(final Interpolator1DDataBundle data, final Double value) {
    Validate.notNull(value, "Value to be interpolated must not be null");
    ArgumentChecker.isTrue(value > 0, "Value should be stricly positive");
    Validate.notNull(data, "Data bundle must not be null");
    final InterpolationBoundedValues boundedValues = data.getBoundedValues(value);
    final double x1 = boundedValues.getLowerBoundKey();
    final double y1 = boundedValues.getLowerBoundValue();
    if (data.getLowerBoundIndex(value) == data.size() - 1) {
      return 0.;
    }
    final double x2 = boundedValues.getHigherBoundKey();
    final double y2 = boundedValues.getHigherBoundValue();
    final double w = (x2 - value) / (x2 - x1);
    final double xy21 = x1 * y1 * y1;
    final double xy22 = x2 * y2 * y2;
    final double xy2 = w * xy21 + (1 - w) * xy22;
    return 0.5 * (-Math.sqrt(xy2 / value) + (-xy21 + xy22) / (x2 - x1) / Math.sqrt(xy2 / value)) / value;
View Full Code Here

  public double[] getNodeSensitivitiesForValue(final Interpolator1DDataBundle data, final Double value) {
    Validate.notNull(value, "Value to be interpolated must not be null");
    Validate.notNull(data, "Data bundle must not be null");
    final int n = data.size();
    final double[] resultSensitivity = new double[n];
    final InterpolationBoundedValues boundedValues = data.getBoundedValues(value);
    final double x1 = boundedValues.getLowerBoundKey();
    final double y1 = boundedValues.getLowerBoundValue();
    final int index = data.getLowerBoundIndex(value);
    if (index == n - 1) {
      resultSensitivity[n - 1] = 1.0;
      return resultSensitivity;
    }
    final double x2 = boundedValues.getHigherBoundKey();
    final double y2 = boundedValues.getHigherBoundValue();
    final double w = (x2 - value) / (x2 - x1);
    final double xy21 = x1 * y1 * y1;
    final double xy22 = x2 * y2 * y2;
    final double xy2 = w * xy21 + (1 - w) * xy22;
    final double resultValue = Math.sqrt(xy2 / value);
View Full Code Here

  @Override
  public Double interpolate(final Interpolator1DDataBundle model, final Double value) {
    Validate.notNull(value, "value");
    Validate.notNull(model, "data bundle");
    final InterpolationBoundedValues boundedValues = model.getBoundedValues(value);
    final Double x1 = boundedValues.getLowerBoundKey();
    final Double y1 = boundedValues.getLowerBoundValue();
    if (model.getLowerBoundIndex(value) == model.size() - 1) {
      return y1;
    }
    final Double x2 = boundedValues.getHigherBoundKey();
    final Double y2 = boundedValues.getHigherBoundValue();
    return Math.pow(y2 / y1, (value - x1) / (x2 - x1)) * y1;
  }
View Full Code Here

TOP

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

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.