Package com.opengamma.analytics.math.interpolation

Examples of com.opengamma.analytics.math.interpolation.CombinedInterpolatorExtrapolator


    double[] ydata = {2.0, 4.0, 6.0};

    Interpolator1D interpolator = new LinearInterpolator1D();
    Interpolator1D leftExtrapolator = new LinearExtrapolator1D(interpolator);
    Interpolator1D rightExtrapolator = new LinearExtrapolator1D(interpolator);
    Interpolator1D combined = new CombinedInterpolatorExtrapolator(interpolator, leftExtrapolator, rightExtrapolator);

    Curve<Double, Double> curve = new InterpolatedDoublesCurve(xdata, ydata, combined, true);

    out.println(curve.getYValue(1.0));
    out.println(curve.getYValue(2.0));
View Full Code Here


   * @param yieldCurves The yield curves (should include the discount and relevant Ibor projection curve)
   */
  public CapletStrippingAbsoluteStrikeInterpolation(final List<CapFloor> caps, final YieldCurveBundle yieldCurves) {

    super(caps, yieldCurves);
    final CombinedInterpolatorExtrapolator baseInterpolator = CombinedInterpolatorExtrapolatorFactory.getInterpolator(DEFAULT_INTERPOLATOR, DEFAULT_EXTRAPOLATOR);
    _interpolator = new TransformedInterpolator1D(baseInterpolator, TRANSFORM);
    _knots = getKnots();
    // actually need direct access to interpolator
    _volModel = new InterpolatedVolatilityTermStructureProvider(_knots, _interpolator);
  }
View Full Code Here

  @Override
  public void init(final FunctionCompilationContext context) {
    _definition = _helper.init(context, this);
    final ComputationTargetSpecification targetSpec = ComputationTargetSpecification.of(_definition.getCurrency());
    final ValueProperties properties = createValueProperties().with(ValuePropertyNames.CURVE, _curveName).get();
    _interpolator = new CombinedInterpolatorExtrapolator(Interpolator1DFactory.getInterpolator(_definition.getInterpolatorName()), new FlatExtrapolator1D());
    final String curveReqName = _isYieldCurve ? ValueRequirementNames.YIELD_CURVE : ValueRequirementNames.DISCOUNT_CURVE;
    _result = new ValueSpecification(curveReqName, targetSpec, properties);
    _specResult = new ValueSpecification(ValueRequirementNames.YIELD_CURVE_SPEC, targetSpec, properties);
    _results = Sets.newHashSet(_result, _specResult);
  }
View Full Code Here

  /**
   * Test of VolatilitySurface that doesn't permit extrapolation in strike dimension
   */
  @Test(expectedExceptions = IllegalArgumentException.class)
  public void testSurfaceWithoutStrikeExtrapolation() {
    final CombinedInterpolatorExtrapolator interpOnlyStrike = getInterpolator(Interpolator1DFactory.LINEAR);
    final Interpolator2D interp2D = new GridInterpolator2D(INTERPOLATOR_1D_EXPIRY, interpOnlyStrike);
    final InterpolatedDoublesSurface surface = new InterpolatedDoublesSurface(EXPIRIES, STRIKES, VOLS, interp2D);
    final BlackVolatilitySurfaceStrike volSurface = new BlackVolatilitySurfaceStrike(surface);
    PRICER.expectedVariance(swap1, new StaticReplicationDataBundle(volSurface, DISCOUNT, FORWARD_CURVE));
  }
View Full Code Here

      final String leftExtrapolatorName = message.getString(LEFT_EXTRAPOLATOR_FIELD_NAME);
      final String rightExtrapolatorName = message.getString(RIGHT_EXTRAPOLATOR_FIELD_NAME);
      final Interpolator1D interpolator = Interpolator1DFactory.getInterpolator(interpolatorName);
      final Interpolator1D leftExtrapolator = getExtrapolator(leftExtrapolatorName, interpolator);
      final Interpolator1D rightExtrapolator = getExtrapolator(rightExtrapolatorName, interpolator);
      return new CombinedInterpolatorExtrapolator(interpolator, leftExtrapolator, rightExtrapolator);
    }
View Full Code Here

    assertEquals(cycled, CUBIC_SPLINE);
  }

  @Test
  public void testCombinedInterpolator() {
    final CombinedInterpolatorExtrapolator cycled = cycleObject(CombinedInterpolatorExtrapolator.class, COMBINED);
    assertEquals(cycled, COMBINED);
  }
View Full Code Here

        final Cash cashDepositCurve = new Cash(_currency, startTime, endTime, 1, 0, accrualFactor, impliedDepositCurveName);
        derivatives.add(cashDepositCurve);
        t[i] = endTime;
        r[i++] = parRate;
      }
      final CombinedInterpolatorExtrapolator interpolator = CombinedInterpolatorExtrapolatorFactory.getInterpolator(_interpolatorName, _leftExtrapolatorName,
          _rightExtrapolatorName);
      final double absoluteTolerance = Double.parseDouble(absoluteToleranceName);
      final double relativeTolerance = Double.parseDouble(relativeToleranceName);
      final int iterations = Integer.parseInt(iterationsName);
      final Decomposition<?> decomposition = DecompositionFactory.getDecomposition(decompositionName);
View Full Code Here

      final YieldCurveBundle knownCurve = new YieldCurveBundle(new String[] {fullForeignCurveName }, new YieldAndDiscountCurve[] {foreignCurve });
      final LinkedHashMap<String, double[]> curveKnots = new LinkedHashMap<>();
      curveKnots.put(fullDomesticCurveName, nodeTimes.toDoubleArray());
      final LinkedHashMap<String, double[]> curveNodes = new LinkedHashMap<>();
      final LinkedHashMap<String, Interpolator1D> interpolators = new LinkedHashMap<>();
      final CombinedInterpolatorExtrapolator interpolator = CombinedInterpolatorExtrapolatorFactory.getInterpolator(interpolatorName, leftExtrapolatorName,
          rightExtrapolatorName);
      curveNodes.put(fullDomesticCurveName, nodeTimes.toDoubleArray());
      interpolators.put(fullDomesticCurveName, interpolator);
      final FXMatrix fxMatrix = new FXMatrix();
      fxMatrix.addCurrency(foreignCurrency, domesticCurrency, invertFXQuotes ? spotFX : 1 / spotFX);
View Full Code Here

    List<Function1D<Double, Double>> basisFuncs = generator.generateSet(0, 12, 100, 3);
    List<Function1D<Double, Double>> basisFuncsLog = generator.generateSet(-5, 3, 100, 3);

    final GeneralizedLeastSquare gls = new GeneralizedLeastSquare();

    final Interpolator1D interpolator = new CombinedInterpolatorExtrapolator(new DoubleQuadraticInterpolator1D(), new FlatExtrapolator1D());

    //  final double[] xData = new double[] {0.4, 0.9, 1.0, 1.8, 2.8, 5 };
    //  final double[] yData = new double[] {0.8, 4., 4.1, 5.6, 7., 8.1 };

    final double[] xData = new double[] {7. / 365, 14 / 365., 21 / 365., 1 / 12., 3 / 12., 0.5, 0.75, 1, 5, 10 };
    final double[] yData = new double[] {0.972452371,
        0.749039802,
        0.759792085,
        0.714206462,
        0.604446956,
        0.517955313,
        0.474807307,
        0.443532132,
        0.2404755,
        0.197128583,

    };

    final int n = xData.length;
    final double[] lnX = new double[n];
    final double[] yData2 = new double[n];
    for (int i = 0; i < n; i++) {
      lnX[i] = Math.log(xData[i]);
      yData2[i] = yData[i] * yData[i] * xData[i];
    }

    Interpolator1DDataBundle db = interpolator.getDataBundle(xData, yData);
    Interpolator1DDataBundle dbLog = interpolator.getDataBundle(lnX, yData);
    Interpolator1DDataBundle dbVar = interpolator.getDataBundle(xData, yData2);
    Interpolator1DDataBundle dbVarLog = interpolator.getDataBundle(lnX, yData2);

    final double[] sigma = new double[n];
    Arrays.fill(sigma, 0.01);
    final GeneralizedLeastSquareResults<Double> results = gls.solve(xData, yData, sigma, basisFuncs, 1000.0, 2);
    final Function1D<Double, Double> spline = results.getFunction();
    final GeneralizedLeastSquareResults<Double> resultsLog = gls.solve(lnX, yData, sigma, basisFuncsLog, 1000.0, 2);
    final Function1D<Double, Double> splineLog = resultsLog.getFunction();
    final GeneralizedLeastSquareResults<Double> resultsVar = gls.solve(xData, yData2, sigma, basisFuncs, 1000.0, 2);
    final Function1D<Double, Double> splineVar = resultsVar.getFunction();
    final GeneralizedLeastSquareResults<Double> resultsVarLog = gls.solve(lnX, yData2, sigma, basisFuncsLog, 1000.0, 2);
    final Function1D<Double, Double> splineVarLog = resultsVarLog.getFunction();

    if (PRINT) {
      System.out.println("Chi^2:\t" + results.getChiSq());
      System.out.println("weights:\t" + results.getFitParameters());

      for (int i = 0; i < 101; i++) {
        final double logX = -5 + 8 * i / 100.;
        final double x = Math.exp(logX);
        System.out.println(x + "\t" + +logX + "\t" + spline.evaluate(x) + "\t" + interpolator.interpolate(db, x) + "\t"
            + splineLog.evaluate(logX) + "\t" + interpolator.interpolate(dbLog, logX) + "\t" + splineVar.evaluate(x) + "\t"
            + interpolator.interpolate(dbVar, x) + "\t" + splineVarLog.evaluate(logX) + "\t" + interpolator.interpolate(dbVarLog, logX));
      }
      for (int i = 0; i < n; i++) {
        System.out.println(lnX[i] + "\t" + yData[i]);
      }
    }
View Full Code Here

            final Cash cashDepositCurve = new Cash(_currency, startTime, endTime, 1, 0, accrualFactor, impliedDepositCurveName);
            derivatives.add(cashDepositCurve);
            t[i] = endTime;
            r[i++] = parRate;
          }
          final CombinedInterpolatorExtrapolator interpolator = CombinedInterpolatorExtrapolatorFactory.getInterpolator(_interpolatorName, _leftExtrapolatorName,
              _rightExtrapolatorName);
          final double absoluteTolerance = Double.parseDouble(absoluteToleranceName);
          final double relativeTolerance = Double.parseDouble(relativeToleranceName);
          final int iterations = Integer.parseInt(iterationsName);
          final Decomposition<?> decomposition = DecompositionFactory.getDecomposition(decompositionName);
View Full Code Here

TOP

Related Classes of com.opengamma.analytics.math.interpolation.CombinedInterpolatorExtrapolator

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.