Examples of Interpolator1DDataBundle


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

    PDETerminalResults1D res = (PDETerminalResults1D) solver.solve(dbF);
    final double minK = Math.exp(-6 * rootT);
    final double maxK = Math.exp(6 * rootT);
    Map<Double, Double> vols = PDEUtilityTools.priceToImpliedVol(fwdCurve, t, res, minK, maxK, true);
    DoubleQuadraticInterpolator1D interpolator = Interpolator1DFactory.DOUBLE_QUADRATIC_INSTANCE;
    Interpolator1DDataBundle idb = interpolator.getDataBundle(vols);

    //set up for solving backwards PDE
    ConvectionDiffusionPDE1DStandardCoefficients pdeB = pdeProvider.getBackwardsLocalVol(t, lvsm);
    double sL = xL * spot;
    double sH = xH * spot;
 
View Full Code Here

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

    //run the PDE solver backward to the dividend date
    // PDE1DDataBundle<ConvectionDiffusionPDE1DCoefficients> db1 = new PDE1DDataBundle<ConvectionDiffusionPDE1DCoefficients>(pde, initialCon, lower1, upper1, grid1);
    final PDE1DDataBundle<ConvectionDiffusionPDE1DCoefficients> db1 = new PDE1DDataBundle<>(pde, payoff, lower, upper, grid);
    final PDETerminalResults1D res = (PDETerminalResults1D) solver.solve(db1);

    final Interpolator1DDataBundle interpolDB = INTEPOLATOR1D.getDataBundle(sNodes, res.getTerminalResults());

    final double val = INTEPOLATOR1D.interpolate(interpolDB, lnFT);
    assertEquals(0.41491529, Math.sqrt(-2 * (val) / EXPIRY), 5e-4); //Number from backwardsPDETest
    //   System.out.println(val + "\t" + Math.sqrt(-2 * val / EXPIRY));
  }
View Full Code Here

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

    //run the PDE solver backward from the dividend date to zero
    final PDE1DDataBundle<ConvectionDiffusionPDE1DCoefficients> db2 = new PDE1DDataBundle<>(pde, res1.getTerminalResults(), lower2, upper2, grid2);
    final PDETerminalResults1D res2 = (PDETerminalResults1D) solver.solve(db2);

    final Interpolator1DDataBundle interpolDB2 = INTEPOLATOR1D.getDataBundle(sNodes2, res2.getTerminalResults());
    final double val2 = INTEPOLATOR1D.interpolate(interpolDB2, Math.log(SPOT));
    return val2;
  }
View Full Code Here

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

  protected DoubleMatrix1D finiteDiffNodeSensitivitiesYield(final InstrumentDerivative ird, final InstrumentDerivativeVisitor<YieldCurveBundle, Double> valueCalculator,
      final YieldCurveBundle fixedCurves, final YieldCurveBundle interpolatedCurves) {

    int nNodes = 0;
    for (final String curveName : interpolatedCurves.getAllNames()) {
      final Interpolator1DDataBundle dataBundle = ((InterpolatedDoublesCurve) ((YieldCurve) interpolatedCurves.getCurve(curveName)).getCurve()).getDataBundle();
      nNodes += dataBundle.size();
    }

    final double[] yields = new double[nNodes];
    int index = 0;
    for (final String curveName : interpolatedCurves.getAllNames()) {
      final Interpolator1DDataBundle dataBundle = ((InterpolatedDoublesCurve) ((YieldCurve) interpolatedCurves.getCurve(curveName)).getCurve()).getDataBundle();
      for (final double y : dataBundle.getValues()) {
        yields[index++] = y;
      }
    }

    final Function1D<DoubleMatrix1D, Double> f = new Function1D<DoubleMatrix1D, Double>() {
      @Override
      public Double evaluate(final DoubleMatrix1D x) {
        final YieldCurveBundle curves = interpolatedCurves.copy();
        int index2 = 0;
        for (final String name : interpolatedCurves.getAllNames()) {
          final YieldCurve curve = (YieldCurve) interpolatedCurves.getCurve(name);
          final Interpolator1DDataBundle dataBundle = ((InterpolatedDoublesCurve) curve.getCurve()).getDataBundle();
          final int numberOfNodes = dataBundle.size();
          final double[] yields1 = Arrays.copyOfRange(x.getData(), index2, index2 + numberOfNodes);
          index2 += numberOfNodes;
          final YieldAndDiscountCurve newCurve = YieldCurve.from(InterpolatedDoublesCurve.from(dataBundle.getKeys(), yields1, ((InterpolatedDoublesCurve) curve.getCurve()).getInterpolator()));
          curves.replaceCurve(name, newCurve);
        }
        if (fixedCurves != null) {
          curves.addAll(fixedCurves);
        }
View Full Code Here

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

  protected DoubleMatrix1D finiteDiffNodeSensitivitiesDsc(final InstrumentDerivative ird, final InstrumentDerivativeVisitor<YieldCurveBundle, Double> valueCalculator,
      final YieldCurveBundle fixedCurves, final YieldCurveBundle interpolatedCurves) {
    int nNodes = 0;
    for (final String curveName : interpolatedCurves.getAllNames()) {
      ArgumentChecker.isTrue(interpolatedCurves.getCurve(curveName) instanceof DiscountCurve, "Curve should be DiscountCurve");
      final Interpolator1DDataBundle dataBundle = ((InterpolatedDoublesCurve) ((DiscountCurve) interpolatedCurves.getCurve(curveName)).getCurve()).getDataBundle();
      nNodes += dataBundle.size();
    }
    final double[] df = new double[nNodes];
    int index = 0;
    for (final String curveName : interpolatedCurves.getAllNames()) {
      final Interpolator1DDataBundle dataBundle = ((InterpolatedDoublesCurve) ((DiscountCurve) interpolatedCurves.getCurve(curveName)).getCurve()).getDataBundle();
      for (final double y : dataBundle.getValues()) {
        df[index++] = y;
      }
    }

    final Function1D<DoubleMatrix1D, Double> f = new Function1D<DoubleMatrix1D, Double>() {
      @Override
      public Double evaluate(final DoubleMatrix1D x) {
        final YieldCurveBundle curves = interpolatedCurves.copy();
        int index2 = 0;
        for (final String name : interpolatedCurves.getAllNames()) {
          final DiscountCurve curve = (DiscountCurve) interpolatedCurves.getCurve(name);
          final Interpolator1DDataBundle dataBundle = ((InterpolatedDoublesCurve) curve.getCurve()).getDataBundle();
          final int numberOfNodes = dataBundle.size();
          final double[] df1 = Arrays.copyOfRange(x.getData(), index2, index2 + numberOfNodes);
          index2 += numberOfNodes;
          final YieldAndDiscountCurve newCurve = DiscountCurve.from(InterpolatedDoublesCurve.from(dataBundle.getKeys(), df1, ((InterpolatedDoublesCurve) curve.getCurve()).getInterpolator()));
          curves.replaceCurve(name, newCurve);
        }
        if (fixedCurves != null) {
          curves.addAll(fixedCurves);
        }
View Full Code Here

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

    for (int i = 0; i < n; i++) {
      //      System.out.println(res.getSpaceValue(i) + "\t" + res.getFunctionValue(i));
      values[i] = res.getFunctionValue(i);
    }

    final Interpolator1DDataBundle idb = INTERPOLATOR.getDataBundle(grid.getSpaceNodes(), values);
    final double elogS = INTERPOLATOR.interpolate(idb, Math.log(ft));
    final double kVol = Math.sqrt(-2 * (elogS - Math.log(ft)) / EXPIRY);
    //  System.out.println("expected:" + expected + " actual:" + kVol);
    assertEquals(expected, kVol, 1e-3); //TODO Improve on 10bps error - local surface is (by construction) very smooth. NOTE: this has got worse since we improved the T -> 0
    //behaviour of the mixed log-normal local volatility surface
View Full Code Here

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

      double yInit = INTERPOLATOR.interpolate(DATA, x[loopx]);
      double[] ySensiCalculated = INTERPOLATOR.getNodeSensitivitiesForValue(DATA, x[loopx]);
      for (int loopsens = 0; loopsens < X.length; loopsens++) {
        double[] yVectorBumped = Y.clone();
        yVectorBumped[loopsens] += shift;
        Interpolator1DDataBundle dataBumped = INTERPOLATOR.getDataBundle(X, yVectorBumped);
        double yBumped = INTERPOLATOR.interpolate(dataBumped, x[loopx]);
        double ySensiExpected = (yBumped - yInit) / shift;
        assertEquals("TimeSquare interpolator: test " + loopx + " node " + loopsens, ySensiExpected, ySensiCalculated[loopsens], TOLERANCE_SENSI);
      }
    }
    int lenghtx = DATA.getKeys().length;
    double lastx = DATA.getKeys()[lenghtx - 1];
    double yInitLast = INTERPOLATOR.interpolate(DATA, lastx);
    double[] ySensiCalculated = INTERPOLATOR.getNodeSensitivitiesForValue(DATA, lastx);
    for (int loopsens = 0; loopsens < X.length; loopsens++) {
      double[] yVectorBumped = Y.clone();
      yVectorBumped[loopsens] += shift;
      Interpolator1DDataBundle dataBumped = INTERPOLATOR.getDataBundle(X, yVectorBumped);
      double yBumped = INTERPOLATOR.interpolate(dataBumped, lastx);
      double ySensiExpected = (yBumped - yInitLast) / shift;
      assertEquals("TimeSquare interpolator: test last node " + loopsens, ySensiExpected, ySensiCalculated[loopsens], TOLERANCE_SENSI);
    }
  }
View Full Code Here

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

  @Test(expectedExceptions = IllegalArgumentException.class)
  public void samexNodesTest() {
    final double[] xData = new double[] {0.4, 0.7, 0.9, 0.9, 1.3, 1.8 };
    final double[] yData = new double[] {0.4, 0.5, 0.3, 0.8, 0.7, 1.0 };
    final Interpolator1DDataBundle data = INTERPOLATOR.getDataBundle(xData, yData);
    double y = INTERPOLATOR.interpolate(data, 1.0);
    assertTrue("y: " + y, !Double.isNaN(y));
  }
View Full Code Here

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

  @Test
  public void testSingleData() {
    final double x = 1.4;
    final double y = 0.34;
    Interpolator1DDataBundle dataBundle = INTERPOLATOR.getDataBundleFromSortedArrays(new double[] {x }, new double[] {y });
    double value = INTERPOLATOR.interpolate(dataBundle, x);
    assertEquals(y, value, 0.0);
  }
View Full Code Here

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

  @Test
  public void testTwoData() {
    final double[] x = new double[] {1.4, 1.8 };
    final double[] y = new double[] {0.34, 0.56 };
    Interpolator1DDataBundle dataBundle = INTERPOLATOR.getDataBundleFromSortedArrays(x, y);
    double value = INTERPOLATOR.interpolate(dataBundle, 1.6);
    assertEquals((y[0] + y[1]) / 2, value, 0.0);
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.