Package org.jquantlib.math.integrals

Examples of org.jquantlib.math.integrals.SimpsonIntegral


    }

    @Test
    public void testSimpson() {
        QL.info("Testing Simpson integration...");
        testSeveral(new SimpsonIntegral(tolerance, 10000) { /* anonymous */ } );
    }
View Full Code Here


      //     Hyman 1989 paper the n=17 nonmonotonicity is not filtered anymore
      //     so the error agrees with the non MC method.
      final double tabulatedMCErrors[]   = { 1.7e-2, 2.0e-3, 4.0e-5, 1.8e-6 };
      final double toleranceOnTabMCErr[] = { 0.1e-2, 0.1e-3, 0.1e-5, 0.1e-6 };

      final SimpsonIntegral integral = new SimpsonIntegral(1e-12, 10000);

      // 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,
                    CubicInterpolation.DerivativeApprox.Spline, false,
                    CubicInterpolation.BoundaryCondition.NotAKnot, Constants.NULL_REAL,
                    CubicInterpolation.BoundaryCondition.NotAKnot, Constants.NULL_REAL);
          f.update();

          result = Math.sqrt(integral.op(makeErrorFunction(f), -1.7, 1.9));
          result /= scaleFactor;
            assertFalse("Not-a-knot spline interpolation "
                    +"\n    sample points:      "+n
                    +"\n    norm of difference: "+result
                    +"\n    it should be:       "+tabulatedErrors[i],
                    abs(result-tabulatedErrors[i]) > toleranceOnTabErr[i]);

          // MC not-a-knot
          f = new CubicInterpolation(
                  x, y,
                    CubicInterpolation.DerivativeApprox.Spline, true,
                    CubicInterpolation.BoundaryCondition.NotAKnot, Constants.NULL_REAL,
                    CubicInterpolation.BoundaryCondition.NotAKnot, Constants.NULL_REAL);
          f.update();

            result = Math.sqrt(integral.op(makeErrorFunction(f), -1.7, 1.9));
          result /= scaleFactor;
            assertFalse ("MC Not-a-knot spline interpolation "
                    + "\n    sample points:      "
                    + "\n    norm of difference: " + result
                    + "\n    it should be:       " + tabulatedErrors[i],
View Full Code Here

    }

    @Test
    public void testSimpson() {
        QL.info("Testing Simpson integration...");
        testSeveral(new SimpsonIntegral(tolerance, 10000));
    }
View Full Code Here

      //     Hyman 1989 paper the n=17 nonmonotonicity is not filtered anymore
      //     so the error agrees with the non MC method.
      final double tabulatedMCErrors[]   = { 1.7e-2, 2.0e-3, 4.0e-5, 1.8e-6 };
      final double toleranceOnTabMCErr[] = { 0.1e-2, 0.1e-3, 0.1e-5, 0.1e-6 };

      final SimpsonIntegral integral = new SimpsonIntegral(1e-12, 10000);

      // 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,
                    CubicInterpolation.DerivativeApprox.Spline, false,
                    CubicInterpolation.BoundaryCondition.NotAKnot, Constants.NULL_REAL,
                    CubicInterpolation.BoundaryCondition.NotAKnot, Constants.NULL_REAL);
          f.update();

          result = Math.sqrt(integral.op(makeErrorFunction(f), -1.7, 1.9));
          result /= scaleFactor;
            assertFalse("Not-a-knot spline interpolation "
                    +"\n    sample points:      "+n
                    +"\n    norm of difference: "+result
                    +"\n    it should be:       "+tabulatedErrors[i],
                    abs(result-tabulatedErrors[i]) > toleranceOnTabErr[i]);

          // MC not-a-knot
          f = new CubicInterpolation(
                  x, y,
                    CubicInterpolation.DerivativeApprox.Spline, true,
                    CubicInterpolation.BoundaryCondition.NotAKnot, Constants.NULL_REAL,
                    CubicInterpolation.BoundaryCondition.NotAKnot, Constants.NULL_REAL);
          f.update();

            result = Math.sqrt(integral.op(makeErrorFunction(f), -1.7, 1.9));
          result /= scaleFactor;
            assertFalse ("MC Not-a-knot spline interpolation "
                    + "\n    sample points:      "
                    + "\n    norm of difference: " + result
                    + "\n    it should be:       " + tabulatedErrors[i],
View Full Code Here

TOP

Related Classes of org.jquantlib.math.integrals.SimpsonIntegral

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.