Examples of Array


Examples of org.jquantlib.math.matrixutilities.Array

    @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

Examples of org.jquantlib.math.matrixutilities.Array

        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

Examples of org.jquantlib.math.matrixutilities.Array

                                              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

Examples of org.jquantlib.math.matrixutilities.Array

    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

Examples of org.jquantlib.math.matrixutilities.Array

      // 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

Examples of org.jquantlib.math.matrixutilities.Array

  @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

Examples of org.jquantlib.math.matrixutilities.Array

      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

Examples of org.jquantlib.math.matrixutilities.Array

     */
    @Test
    public void testNonRestrictiveHymanFilter() {
        final int n = 4;

        Array x, y;
        x = xRange(-2.0, 2.0, n);
        y = parabolic(x);
        final double zero=0.0;
        double interpolated;
        final double expected=0.0;
View Full Code Here

Examples of org.jquantlib.math.matrixutilities.Array

              for (int k_b=0; k_b<isBetaFixed.length; ++k_b) {
                for (int k_n=0; k_n<isNuFixed.length; ++k_n) {
                  for (int k_r=0; k_r<isRhoFixed.length; ++k_r) {
//FIXME: uncomment
                    final SABRInterpolation sabrInterpolation = new SABRInterpolation(
                            new Array(strikes), new Array(volatilities),
                            expiry, forward,
                            alphaGuess, betaGuess, nuGuess, rhoGuess,
                            isAlphaFixed[k_a], isBetaFixed[k_b],
                            isNuFixed[k_n], isRhoFixed[k_r],
                            vegaWeighted[i],
View Full Code Here

Examples of org.jquantlib.math.matrixutilities.Array

        final double dx = (finish-start)/(size-1);
        for(int i=0; i<size-1; i++) {
            x[i]=start+i*dx;
        }
        x[size-1] = finish;
        return new Array(x);
    }
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.