Package org.jquantlib.math.solvers1D

Examples of org.jquantlib.math.solvers1D.NewtonSafe


            throw new IllegalArgumentException("stddev guess (" + guess + ") must be non-negative");



        final BlackImpliedStdDevHelper f = new BlackImpliedStdDevHelper(optionType, strike, forward, blackPrice / discount);
        final NewtonSafe solver = new NewtonSafe();
        solver.setMaxEvaluations(maxIterations);
        final double minSdtDev = 0.0, maxstddev = 3.0;
        final double stddev = solver.solve(f, accuracy, guess, minSdtDev, maxstddev);

        if (stddev >= 0.0) return stddev;
        throw new ArithmeticException("a negative value was calculated"); // TODO: add more logging
    }
View Full Code Here


            throw new IllegalArgumentException("stddev guess (" + guess + ") must be non-negative");



        final BlackImpliedStdDevHelper f = new BlackImpliedStdDevHelper(optionType, strike, forward, blackPrice / discount);
        final NewtonSafe solver = new NewtonSafe();
        solver.setMaxEvaluations(maxIterations);
        final double minSdtDev = 0.0, maxstddev = 3.0;
        final double stddev = solver.solve(f, accuracy, guess, minSdtDev, maxstddev);

        if (stddev >= 0.0) return stddev;
        throw new ArithmeticException("a negative value was calculated"); // TODO: add more logging
    }
View Full Code Here

      public double derivative (final double x) {
        return 2*x;
      }
    };

    final NewtonSafe newtonsafe = new NewtonSafe();

    double root = newtonsafe.solve(f, accuracy, guess, xMin, xMax);

    // assertEquals(1.0, root, accuracy);
    if (Math.abs(1.0-root)> accuracy) {
      fail("expected: 1.0" + " but root is: " + root);
    }

    // assertEquals(100, newtonsafe.getMaxEvaluations());
    if(newtonsafe.getMaxEvaluations() != 100){
      fail("expected: 100" + " but was: " + newtonsafe.getMaxEvaluations());
    }

    root = newtonsafe.solve(f, accuracy, 0.01, 0.1);

    // assertEquals(1.0, root, accuracy);
    if (Math.abs(1.0-root)> accuracy) {
      fail("expected: 1.0" + " but root is: " + root);
    }

    //assertEquals(10, newtonsafe.getNumEvaluations());
    if(newtonsafe.getNumEvaluations() != 10){
      fail("expected: 10" + " but was: " + newtonsafe.getNumEvaluations());
    }
  }
View Full Code Here

TOP

Related Classes of org.jquantlib.math.solvers1D.NewtonSafe

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.