Package com.opengamma.analytics.math.interpolation

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


    }

    final LinkedHashMap<String, Interpolator1D> transInterpolators = new LinkedHashMap<>();
    for (final Map.Entry<String, Interpolator1D> entry : interpolators.entrySet()) {
      final String name = entry.getKey();
      final Interpolator1D temp = new TransformedInterpolator1D(entry.getValue(), parameterTransforms.get(name));
      transInterpolators.put(name, temp);
    }

    _curveBuilder = new InterpolatedCurveBuildingFunction(knotPoints, transInterpolators);
View Full Code Here


    final LinkedHashMap<String, Interpolator1D> transInterpolators = new LinkedHashMap<>();
    final Set<String> names = interpolators.keySet();
    _parameterNames = names;
    for (final String name : names) {
      final Interpolator1D temp = new TransformedInterpolator1D(interpolators.get(name), parameterTransforms.get(name));
      transInterpolators.put(name, temp);
    }

    _capPricers = new ArrayList<>(caps.size());
    for (final CapFloor cap : caps) {
View Full Code Here

        greeks[tIndex] = SABR.getVolatilityAdjoint(option, f, data); //2nd and 3rd entries are forward & strike sensitivity which we don't use
        capletVega[tIndex] = capletDF[tIndex] * BlackFormulaRepository.vega(f, k, t, greeks[tIndex][0]);

        int parmIndex = 0;
        for (final String name : _parameterNames) {
          final Interpolator1D itrp = _interpolators.get(name);
          nodeSens[parmIndex++][tIndex] = itrp.getNodeSensitivitiesForValue(db.get(name), t);
        }
      }

      final double[] res = new double[x.getNumberOfElements()];
      for (int tIndex = 0; tIndex < nCaplets; tIndex++) {
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

    }
  }

  @Test(enabled = false)
  public void rootTest() {
    final Interpolator1D baseInterpolator = CombinedInterpolatorExtrapolatorFactory.getInterpolator(Interpolator1DFactory.DOUBLE_QUADRATIC, Interpolator1DFactory.LINEAR_EXTRAPOLATOR);

    final NewtonDefaultVectorRootFinder rootFinder = new NewtonDefaultVectorRootFinder();

    final Function1D<DoubleMatrix1D, DoubleMatrix1D> residualFunc = new Function1D<DoubleMatrix1D, DoubleMatrix1D>() {
      @SuppressWarnings("synthetic-access")
View Full Code Here

  @Test
  /**
   * Tests the present value with an explicit computation.
   */
  public void presentValueDoubleQuadratic() {
    final Interpolator1D interpolator = CombinedInterpolatorExtrapolatorFactory.getInterpolator(Interpolator1DFactory.DOUBLE_QUADRATIC,
        Interpolator1DFactory.LINEAR_EXTRAPOLATOR, Interpolator1DFactory.LINEAR_EXTRAPOLATOR);
    final SmileDeltaTermStructureParametersStrikeInterpolation smileTerm = FXDataSets.smile3points(REFERENCE_DATE, interpolator);
    final BlackForexSmileProviderDiscount smile = new BlackForexSmileProviderDiscount(MULTICURVES, smileTerm, Pair.of(EUR, USD));
    final double strikeM = STRIKE * (1 - CALL_SPREAD);
    final double strikeP = STRIKE * (1 + CALL_SPREAD);
View Full Code Here

  @Test(enabled = false)
  /**
   * Analyzes the profile for digital options.
   */
  public void profile() {
    final Interpolator1D interpolator = CombinedInterpolatorExtrapolatorFactory.getInterpolator(Interpolator1DFactory.DOUBLE_QUADRATIC,
        Interpolator1DFactory.LINEAR_EXTRAPOLATOR, Interpolator1DFactory.LINEAR_EXTRAPOLATOR);
    final SmileDeltaTermStructureParametersStrikeInterpolation smileTerm = FXDataSets.smile5points(REFERENCE_DATE, interpolator);
    final BlackForexSmileProviderDiscount smile = new BlackForexSmileProviderDiscount(MULTICURVES, smileTerm, Pair.of(EUR, USD));

    final int nbStrike = 100;
View Full Code Here

  @Test
  /**
   * Tests the present value with an explicit computation.
   */
  public void presentValueDoubleQuadratic() {
    final Interpolator1D interpolator = CombinedInterpolatorExtrapolatorFactory.getInterpolator(Interpolator1DFactory.DOUBLE_QUADRATIC, Interpolator1DFactory.LINEAR_EXTRAPOLATOR,
        Interpolator1DFactory.LINEAR_EXTRAPOLATOR);
    final SmileDeltaTermStructureParametersStrikeInterpolation smileTerm = TestsDataSetsForex.smile3points(REFERENCE_DATE, interpolator);
    final SmileDeltaTermStructureDataBundle smileBundle = new SmileDeltaTermStructureDataBundle(CURVES, smileTerm, Pair.of(EUR, USD));
    final double strikeM = STRIKE * (1 - STANDARD_SPREAD);
    final double strikeP = STRIKE * (1 + STANDARD_SPREAD);
View Full Code Here

  @Test(enabled = false)
  /**
   * Analyzes the profile for digital options.
   */
  public void profile() {
    final Interpolator1D interpolator = CombinedInterpolatorExtrapolatorFactory.getInterpolator(Interpolator1DFactory.DOUBLE_QUADRATIC, Interpolator1DFactory.LINEAR_EXTRAPOLATOR,
        Interpolator1DFactory.LINEAR_EXTRAPOLATOR);
    final SmileDeltaTermStructureParametersStrikeInterpolation smileTerm = TestsDataSetsForex.smile5points(REFERENCE_DATE, interpolator);
    final SmileDeltaTermStructureDataBundle smileBundle = new SmileDeltaTermStructureDataBundle(CURVES, smileTerm, Pair.of(EUR, USD));

    final int nbStrike = 100;
View Full Code Here

        }
        final Tenor tenor = node.getResolvedMaturity();
        tList.add(DateUtils.getDifferenceInYears(now, now.plus(tenor.getPeriod())));
        fxList.add(fxForward);
      }
      final Interpolator1D interpolator = CombinedInterpolatorExtrapolatorFactory.getInterpolator(interpolatorName,
          leftExtrapolatorName, rightExtrapolatorName);
      return InterpolatedDoublesCurve.from(tList.toDoubleArray(), fxList.toDoubleArray(), interpolator);
    }
View Full Code Here

TOP

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

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.