Package com.opengamma.analytics.math.curve

Examples of com.opengamma.analytics.math.curve.NodalDoublesCurve


    ArrayList<Double> ys = Lists.newArrayList(1.0, 2.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0);
    DoubleQuadraticInterpolator1D interpolator = new DoubleQuadraticInterpolator1D();

    InterpolatedDoublesCurve inputCurve = InterpolatedDoublesCurve.from(xs, ys, interpolator);

    NodalDoublesCurve interpolatedCurve = YieldCurveInterpolatingFunction.interpolateCurve(inputCurve);

    AssertJUnit.assertNotSame(0, interpolatedCurve.getXData().length);
    AssertJUnit.assertNotSame(0, interpolatedCurve.getYData().length);
    AssertJUnit.assertEquals(xs.get(0), interpolatedCurve.getXData()[0]);
    AssertJUnit.assertEquals(xs.get(xs.size() - 1),
        interpolatedCurve.getXData()[interpolatedCurve.getXData().length - 1]);

    for (int i = 0; i < interpolatedCurve.getXData().length; i++) {
      double x = interpolatedCurve.getXData()[i];
      double y = interpolatedCurve.getYData()[i];
      AssertJUnit.assertEquals(inputCurve.getYValue(x), y);
    }
   
    for (int i = 1; i < interpolatedCurve.getXData().length; i++) {
      double x = interpolatedCurve.getXData()[i];
      double prevX = interpolatedCurve.getXData()[i-1];
      assertTrue(prevX < x);
    }
  }
View Full Code Here


    for (int i = 0; i < n; i++) {
      final double t = i / 40.;
      xData[i] = t;
      yData[i] = curve.getForwardRate(t);
    }
    final NodalDoublesCurve forwardCurve = NodalDoublesCurve.from(xData, yData);
    final ValueProperties properties = Iterables.getOnlyElement(desiredValues).getConstraints();
    final ValueSpecification spec = new ValueSpecification(INSTANTANEOUS_FORWARD_CURVE, target.toSpecification(), properties);
    return Collections.singleton(new ComputedValue(spec, forwardCurve));
  }
View Full Code Here

    final Object objectFuturePriceData = inputs.getValue(ValueRequirementNames.FUTURE_PRICE_CURVE_DATA);
    if (objectFuturePriceData == null) {
      throw new OpenGammaRuntimeException("Could not get futures curve " + curveName);
    }
    final NodalDoublesCurve futurePriceData = (NodalDoublesCurve) objectFuturePriceData;

    final Interpolator1D interpolator = CombinedInterpolatorExtrapolatorFactory.getInterpolator(interpolatorName, leftExtrapolatorName, rightExtrapolatorName);

    final ForwardCurve curve = new ForwardCurve(InterpolatedDoublesCurve.from(futurePriceData.getXData(), futurePriceData.getYData(), interpolator));

    final ValueProperties properties = createValueProperties()
        .with(ForwardCurveValuePropertyNames.PROPERTY_FORWARD_CURVE_CALCULATION_METHOD, ForwardCurveValuePropertyNames.PROPERTY_FUTURE_PRICE_METHOD)
        .with(ValuePropertyNames.CURVE, curveName)
        .with(ForwardCurveValuePropertyNames.PROPERTY_FORWARD_CURVE_INTERPOLATOR, interpolatorName)
View Full Code Here

    final VolatilitySurfaceData<Double, Double> volatilitySurfaceData = (VolatilitySurfaceData<Double, Double>) objectSurfaceData;
    final Object objectFuturePriceData = inputs.getValue(_futurePriceRequirement);
    if (objectFuturePriceData == null) {
      throw new OpenGammaRuntimeException("Could not get futures price data");
    }
    final NodalDoublesCurve futurePriceData = (NodalDoublesCurve) objectFuturePriceData;
    //assumes that the sorting is first x, then y
    if (volatilitySurfaceData.size() == 0) {
      throw new OpenGammaRuntimeException("Interest rate future option volatility surface definition name=" + _definitionName + " contains no data");
    }
    final SortedSet<Double> x = volatilitySurfaceData.getUniqueXValues();
    final DoubleArrayList fittedOptionExpiryList = new DoubleArrayList();
    final DoubleArrayList futureDelayList = new DoubleArrayList();
    final DoubleArrayList kappaList = new DoubleArrayList();
    final DoubleArrayList thetaList = new DoubleArrayList();
    final DoubleArrayList vol0List = new DoubleArrayList();
    final DoubleArrayList omegaList = new DoubleArrayList();
    final DoubleArrayList rhoList = new DoubleArrayList();
    final DoubleArrayList chiSqList = new DoubleArrayList();
    final Map<DoublesPair, DoubleMatrix2D> inverseJacobians = new HashMap<DoublesPair, DoubleMatrix2D>();
    for (final Double t : x) {
      final List<ObjectsPair<Double, Double>> strip = volatilitySurfaceData.getYValuesForX(t);
      // FIXME This is bound to break. I changed x/t from an ordinal to an OG-Analytics Year,
      // via TimeCalculator.getTimeBetween(now, IRFutureOptionUtils.getTime(x,now)) where now is the valuationTime. See IRFutureOptionVolatilitySurfaceDataFunction
      final int n = strip.size();
      final DoubleArrayList strikesList = new DoubleArrayList(n);
      final DoubleArrayList sigmaList = new DoubleArrayList(n);
      final DoubleArrayList errorsList = new DoubleArrayList(n);
      final Double futurePrice = futurePriceData.getYValue(t);
      if (strip.size() > 4 && futurePrice != null) {
        final double forward = 1 - futurePrice;
        for (final ObjectsPair<Double, Double> value : strip) {
          if (value.first != null && value.second != null) {
            strikesList.add(1 - value.first / 100);
View Full Code Here

    // future curve
    final Object objectFuturePriceData = inputs.getValue(ValueRequirementNames.FUTURE_PRICE_CURVE_DATA);
    if (objectFuturePriceData == null) {
      throw new OpenGammaRuntimeException("Could not get futures price data");
    }
    final NodalDoublesCurve futurePriceData = (NodalDoublesCurve) objectFuturePriceData;

    // surface
    final String surfaceName = desiredValue.getConstraint(ValuePropertyNames.SURFACE);
    final Object objectSurfaceData = inputs.getValue(ValueRequirementNames.STANDARD_VOLATILITY_SURFACE_DATA);
    if (objectSurfaceData == null) {
      throw new OpenGammaRuntimeException("Could not get volatility surface data");
    }
    @SuppressWarnings("unchecked")
    final VolatilitySurfaceData<Double, Double> volatilitySurfaceData = (VolatilitySurfaceData<Double, Double>) objectSurfaceData;

    //assumes that the sorting is first x, then y
    if (volatilitySurfaceData.size() == 0) {
      throw new OpenGammaRuntimeException("Interest rate future option volatility surface definition name=" + futurePriceData.getName() + " contains no data");
    }

    final SortedSet<Double> x = volatilitySurfaceData.getUniqueXValues();
    final DoubleArrayList fittedOptionExpiryList = new DoubleArrayList();
    final DoubleArrayList futureDelayList = new DoubleArrayList();
    final DoubleArrayList kappaList = new DoubleArrayList();
    final DoubleArrayList thetaList = new DoubleArrayList();
    final DoubleArrayList vol0List = new DoubleArrayList();
    final DoubleArrayList omegaList = new DoubleArrayList();
    final DoubleArrayList rhoList = new DoubleArrayList();
    final DoubleArrayList chiSqList = new DoubleArrayList();
    final Map<DoublesPair, DoubleMatrix2D> inverseJacobians = new HashMap<DoublesPair, DoubleMatrix2D>();
    for (final Double t : x) {
      final List<ObjectsPair<Double, Double>> strip = volatilitySurfaceData.getYValuesForX(t);
      final int n = strip.size();
      final DoubleArrayList strikesList = new DoubleArrayList(n);
      final DoubleArrayList sigmaList = new DoubleArrayList(n);
      final DoubleArrayList errorsList = new DoubleArrayList(n);
      final Double futurePrice = futurePriceData.getYValue(t);
      if (strip.size() > 4 && futurePrice != null) {
        final double forward = 1 - futurePrice / 100;
        for (final ObjectsPair<Double, Double> value : strip) {
          if (value.first != null && value.second != null) {
            strikesList.add(1 - value.first / 100);
View Full Code Here

    final VolatilitySurfaceData<Number, Double> volatilitySurfaceData = (VolatilitySurfaceData<Number, Double>) objectSurfaceData;
    final Object objectFuturePriceData = inputs.getValue(ValueRequirementNames.FUTURE_PRICE_CURVE_DATA);
    if (objectFuturePriceData == null) {
      throw new OpenGammaRuntimeException("Could not get futures price data");
    }
    final NodalDoublesCurve futurePriceData = (NodalDoublesCurve) objectFuturePriceData;
    //assumes that the sorting is first x, then y
    if (volatilitySurfaceData.size() == 0) {
      throw new OpenGammaRuntimeException("Interest rate future option volatility surface name" + desiredValue.getConstraint(ValuePropertyNames.SURFACE) + " contains no data");
    }
    final Double error = Double.parseDouble(desiredValue.getConstraint(PROPERTY_ERROR));
    final DoubleMatrix1D sabrInitialValues = SABRFittingPropertyUtils.getStartingValues(desiredValue);
    final BitSet fixed = SABRFittingPropertyUtils.getFixedValues(desiredValue);
    final Interpolator2D interpolator = SABRFittingPropertyUtils.getInterpolator(desiredValue);
    final SortedSet<Number> timeValues = volatilitySurfaceData.getUniqueXValues();
    final DoubleArrayList fittedOptionExpiryList = new DoubleArrayList();
    final DoubleArrayList futureDelayList = new DoubleArrayList();
    final DoubleArrayList alphaList = new DoubleArrayList();
    final DoubleArrayList betaList = new DoubleArrayList();
    final DoubleArrayList nuList = new DoubleArrayList();
    final DoubleArrayList rhoList = new DoubleArrayList();
    final DoubleArrayList chiSqList = new DoubleArrayList();
    final Map<DoublesPair, DoubleMatrix2D> inverseJacobians = new HashMap<DoublesPair, DoubleMatrix2D>();
    final Map<Double, List<Double>> dataPointsForStrip = new HashMap<Double, List<Double>>();
    for (final Number ttm : timeValues) {
      final List<Double> fittedPointsForStrip = new ArrayList<Double>();
      final List<ObjectsPair<Double, Double>> strip = volatilitySurfaceData.getYValuesForX(ttm);
      final DoubleArrayList errors = new DoubleArrayList();
      final DoubleArrayList strikes = new DoubleArrayList();
      final DoubleArrayList blackVols = new DoubleArrayList();
      if (strip.size() > 4) {
        try {
          final Double forward = futurePriceData.getYValue(ttm.doubleValue());
          for (final ObjectsPair<Double, Double> value : strip) {
            if (value.second != null) {
              strikes.add(1 - value.first);
              blackVols.add(value.second);
              errors.add(error);
View Full Code Here

    final Object objectFuturePriceData = inputs.getValue(ValueRequirementNames.FUTURE_PRICE_CURVE_DATA);
    if (objectFuturePriceData == null) {
      throw new OpenGammaRuntimeException("Could not get futures curve " + curveName);
    }
    final NodalDoublesCurve futurePriceData = (NodalDoublesCurve) objectFuturePriceData;

    final Interpolator1D interpolator = CombinedInterpolatorExtrapolatorFactory.getInterpolator(interpolatorName, leftExtrapolatorName, rightExtrapolatorName);

    final ForwardCurve curve = new ForwardCurve(InterpolatedDoublesCurve.from(futurePriceData.getXData(), futurePriceData.getYData(), interpolator));

    final ValueProperties properties = createValueProperties()
        .with(ForwardCurveValuePropertyNames.PROPERTY_FORWARD_CURVE_CALCULATION_METHOD, ForwardCurveValuePropertyNames.PROPERTY_FUTURE_PRICE_METHOD)
        .with(ValuePropertyNames.CURVE, curveName)
        .with(ForwardCurveValuePropertyNames.PROPERTY_FORWARD_CURVE_INTERPOLATOR, interpolatorName)
View Full Code Here

    final Object objectFuturePriceData = inputs.getValue(ValueRequirementNames.FUTURE_PRICE_CURVE_DATA);
    if (objectFuturePriceData == null) {
      throw new OpenGammaRuntimeException("Could not get futures curve " + curveName);
    }
    final NodalDoublesCurve futurePriceData = (NodalDoublesCurve) objectFuturePriceData;

    final Interpolator1D interpolator = CombinedInterpolatorExtrapolatorFactory.getInterpolator(interpolatorName, leftExtrapolatorName, rightExtrapolatorName);

    final ForwardCurve curve = new ForwardCurve(InterpolatedDoublesCurve.from(futurePriceData.getXData(), futurePriceData.getYData(), interpolator));

    final ValueProperties properties = createValueProperties()
        .with(ForwardCurveValuePropertyNames.PROPERTY_FORWARD_CURVE_CALCULATION_METHOD, ForwardCurveValuePropertyNames.PROPERTY_FUTURE_PRICE_METHOD)
        .with(ValuePropertyNames.CURVE, curveName)
        .with(ForwardCurveValuePropertyNames.PROPERTY_FORWARD_CURVE_INTERPOLATOR, interpolatorName)
View Full Code Here

      return null;
    }
  }

  private List<Double[]> formatExpanded(YieldCurve value) {
    NodalDoublesCurve detailedCurve = YieldCurveInterpolatingFunction.interpolateCurve(value.getCurve());
    List<Double[]> detailedData = new ArrayList<Double[]>();
    Double[] xs = detailedCurve.getXData();
    Double[] ys = detailedCurve.getYData();
    for (int i = 0; i < ys.length; i++) {
      detailedData.add(new Double[]{xs[i], ys[i]});
    }
    return detailedData;
  }
View Full Code Here

      for (int i = 0; i < interpolatedCurve.size(); i++) {
        data.add(new Double[] {xData[i], yData[i]});
      }
      return data;
    } else if (value instanceof NodalDoublesCurve) {
      NodalDoublesCurve nodalCurve = (NodalDoublesCurve) value;
      List<Double[]> data = new ArrayList<>();
      double[] xData = nodalCurve.getXDataAsPrimitive();
      double[] yData = nodalCurve.getYDataAsPrimitive();
      for (int i = 0; i < nodalCurve.size(); i++) {
        data.add(new Double[] {xData[i], yData[i]});
      }
      return data;     
    }
    return FORMATTING_ERROR;
View Full Code Here

TOP

Related Classes of com.opengamma.analytics.math.curve.NodalDoublesCurve

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.