Package org.jquantlib.math.matrixutilities

Examples of org.jquantlib.math.matrixutilities.Array


                unique.add(curr);
            }
            prev = curr;
        }

        this.times = new Array(unique.size());
        int i=0;
        for (final double d : Iterables.unmodifiableIterable(unique.iterator())) {
            this.times.set(i, d);
            i++;
        }
View Full Code Here


    @Test
    public void testSplineOnGenericValues() {

        QL.info("Testing spline interpolation on generic values...");

        final Array generic_x = new Array(new double[]{ 0.0, 1.0, 3.0, 4.0 });
        final Array generic_y = new Array(new double[]{ 0.0, 0.0, 2.0, 2.0 });
        final Array generic_natural_y2 = new Array(new double[]{ 0.0, 1.5, -1.5, 0.0 });

        double interpolated, error;
        final int n = generic_x.size();
        final double[] x35 = new double[3];

        // Natural spline
        CubicInterpolation f = new CubicInterpolation(
                generic_x, generic_y,
                CubicInterpolation.DerivativeApprox.Spline, false,
                CubicInterpolation.BoundaryCondition.SecondDerivative, generic_natural_y2.first(),
                CubicInterpolation.BoundaryCondition.SecondDerivative, generic_natural_y2.last());
        f.update();

        checkValues("Natural spline", f, generic_x, generic_y);
        // cached second derivative
        for (int i=0; i<n; i++) {
            interpolated = f.secondDerivative(generic_x.get(i));
            error = interpolated - generic_natural_y2.get(i);
            assertFalse("Natural spline interpolation "
                  +"second derivative failed at x="+generic_x.get(i)
                  +"\n interpolated value: "+interpolated
                  +"\n expected value:     "+generic_natural_y2.get(i)
                  +"\n error:              "+error,
                  abs(error) > 3e-16);
        }
        x35[1] = f.op(3.5);
View Full Code Here

        QL.info("Testing symmetry of spline interpolation end-conditions...");

        final int n = 9;

        final Array x = xRange(-1.8, 1.8, n);
        final Array y = gaussian(x);

        // Not-a-knot spline
        CubicInterpolation f = new CubicInterpolation(
                x, y,
                CubicInterpolation.DerivativeApprox.Spline, false,
View Full Code Here

    @Test
    public void testForwardFlat() {

        QL.info("Testing forward-flat interpolation...");

        final Array x = new Array(new double[] { 0.0, 1.0, 2.0, 3.0, 4.0 });
        final Array y = new Array(new double[] { 5.0, 4.0, 3.0, 2.0, 1.0 });

        final Interpolation f = new ForwardFlatInterpolation(x, y);
        f.update();

        final int N = x.size();
        final double tolerance = 1.0e-12;

        // at original points
        for (int i=0; i<N; i++) {
            final double p = x.get(i);
            final double calculated = f.op(p);
            final double expected = y.get(i);
            assertFalse("failed to reproduce expected datum"
                    +"\n    expected value:   "+expected
                    +"\n    calculated value: "+calculated
                    +"\n    error:              "+Math.abs(calculated-expected),
                    Math.abs(calculated - expected) > tolerance);
        }

        // at middle points
        for (int i=0; i<N-1; i++) {
            final double p = (x.get(i) + x.get(i+1))/2;
            final double calculated = f.op(p);
            final double expected = y.get(i);
            assertFalse("failed to reproduce expected datum"
                    +"\n    expected value:   "+expected
                    +"\n    calculated value: "+calculated
                    +"\n    error:              "+Math.abs(calculated-expected),
                    Math.abs(calculated - expected) > tolerance);
        }

        // outside the original range
        f.enableExtrapolation();

        {
            double p = x.get(0) - 0.5;
            double calculated = f.op(p);
            double expected = y.get(0);
            assertFalse("failed to reproduce expected datum"
                    +"\n    expected value:   "+expected
                    +"\n    calculated value: "+calculated
                    +"\n    error:              "+Math.abs(calculated-expected),
                    Math.abs(calculated - expected) > tolerance);

            p = x.get(N-1) + 0.5;
            calculated = f.op(p);
            expected = y.get(N-1);
            assertFalse("failed to reproduce expected datum"
                    +"\n    expected value:   "+expected
                    +"\n    calculated value: "+calculated
                    +"\n    error:              "+Math.abs(calculated-expected),
                    Math.abs(calculated - expected) > tolerance);

            // primitive at original points
            calculated = f.primitive(x.get(0));
            expected = 0.0;
            assertFalse("failed to reproduce expected datum"
                    +"\n    expected value:   "+expected
                    +"\n    calculated value: "+calculated
                    +"\n    error:              "+Math.abs(calculated-expected),
                    Math.abs(calculated - expected) > tolerance);
        }

        double sum = 0.0;
        for (int i=1; i<N; i++) {
            sum += (x.get(i) - x.get(i-1)) * y.get(i-1);
            final double calculated = f.primitive(x.get(i));
            final double expected = sum;
            assertFalse("failed to reproduce expected datum"
                    +"\n    expected value:   "+expected
                    +"\n    calculated value: "+calculated
                    +"\n    error:              "+Math.abs(calculated-expected),
                    Math.abs(calculated - expected) > tolerance);
        }

        // primitive at middle points
        sum = 0.0;
        for (int i=0; i<N-1; i++) {
            final double p = (x.get(i) + x.get(i+1))/2;
            sum += (x.get(i+1) - x.get(i)) * y.get(i)/2;
            final double calculated = f.primitive(p);
            final double expected = sum;
            sum += (x.get(i+1) - x.get(i)) * y.get(i)/2;
            assertFalse("failed to reproduce expected datum"
                    +"\n    expected value:   "+expected
                    +"\n    calculated value: "+calculated
                    +"\n    error:              "+Math.abs(calculated-expected),
                    Math.abs(calculated - expected) > tolerance);
View Full Code Here

        double u = args[2];
        double v = args[3];
        double w = args[4];

        //TODO: final SplineGrid grid = new SplineGrid(5);
        final Array grid[] = new Array[5]; //XXX: just to compile

        double r = 0.15;

        for (int i = 0; i < 5; ++i) {
// TODO: translate this code
//            double temp = offsets[i];
//            for (int j = 0; j < dim[i]; temp += r, ++j) {
//                grid[i].push_back(temp);
//            }
            grid[i] = new Array(); //XXX: just to compile
        }

        r = 0.01;

        //TODO: MultiCubicSpline<5>::data_table y5(dim);
View Full Code Here

                                              ts_->interpolation_,
                                              nInsts+1);
                */
                //bootstrapable.getInterpolation ().update ();

                ts.setInterpolation(interpolator.interpolate(new Array(times, i+2), new Array(data)));

                if (i >= localisation) {
                    startArray[localisation-dataAdjust] = traits.guess(ts, dates[i]);
                } else {
                    startArray[localisation-dataAdjust] = data[0];
                }

                final PenaltyFunction currentCost = new PenaltyFunction(initialDataPoint, (i - localisation + 1), (i + 1));

                final Problem toSolve = new Problem(currentCost, solverConstraint, new Array(startArray));
                final EndCriteria.Type endType = solver.minimize (toSolve, endCriteria);

                QL.require (endType == EndCriteria.Type.StationaryFunctionAccuracy ||
                            endType == EndCriteria.Type.StationaryFunctionValue,
                            "Unable to strip yieldcurve to required accuracy");
View Full Code Here

    public void testDerivativeEndConditions() {

        QL.info("Testing derivative end-conditions for spline interpolation...");

        final int n = 4;
        final Array x = xRange(-2.0, 2.0, n);
        final Array y = parabolic(x);

        // Not-a-knot spline
        CubicInterpolation f = new CubicInterpolation(
                x, y,
                CubicInterpolation.DerivativeApprox.Spline, false,
View Full Code Here

      // still unexplained scale factor needed to obtain the numerical results from the paper
      final double scaleFactor = 1.9;

      for (int i=0; i<points.length; i++) {
          final int n = points[i];
          final Array x = xRange(-1.7, 1.9, n);
          final Array y = gaussian(x);
          double result;

          // Not-a-knot
          CubicInterpolation f = new CubicInterpolation(
                  x, y,
View Full Code Here

  @Test
  public void testSplineOnRPN15AValues(){

    QL.info("Testing Clamped spline interpolation on RPN15A data set...");

    final Array RPN15A_x = new Array(new double[] { 7.99, 8.09, 8.19, 8.7, 9.2, 10.0, 12.0, 15.0, 20.0 });
    final Array RPN15A_y = new Array(new double[] { 0.0, 2.76429e-5, 4.37498e-5, 0.169183, 0.469428, 0.943740, 0.998636, 0.999919, 0.999994 });

    double interpolated;


      // Natural spline
View Full Code Here

      QL.info("Testing spline interpolation on a Gaussian data set...");

        double interpolated, interpolated2;
        final int n = 5;

        Array x, y;

        final double x1_bad=-1.7, x2_bad=1.7;

        for (double start = -1.9, j=0; j<2; start+=0.2, j++) {
            x = xRange(start, start+3.6, n);
View Full Code Here

TOP

Related Classes of org.jquantlib.math.matrixutilities.Array

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.