Package com.opengamma.analytics.math

Examples of com.opengamma.analytics.math.MathException


    final MultivariateRealOptimizer optimizer = new MultiDirectional();
    final MultivariateRealFunction commons = CommonsMathWrapper.wrapMultivariate(f);
    try {
      return new DoubleMatrix1D(CommonsMathWrapper.unwrap(optimizer.optimize(commons, MINIMIZER, initialPoint.getData())));
    } catch (final ConvergenceException e) {
      throw new MathException(e);
    } catch (final FunctionEvaluationException e) {
      throw new MathException(e);
    }
  }
View Full Code Here


      x3 = u;
      f1 = f2;
      f2 = f3;
      f3 = fu;
    }
    throw new MathException("Could not bracket a minimum in " + MAX_ITER + " attempts");
  }
View Full Code Here

          oldValue = xData[i];
          xData[i] += _eps;
          if (!domain.evaluate(x)) {
            xData[i] = oldValue - _twoEps;
            if (!domain.evaluate(x)) {
              throw new MathException("cannot get derivative at point " + x.toString() + " in direction " + i);
            }
            y[0] = function.evaluate(x);
            xData[i] = oldValue;
            y[2] = function.evaluate(x);
            xData[i] = oldValue - _eps;
View Full Code Here

          resetCount = 0;
        }
      }
    }
    final double value = function.evaluate(x);
    throw new MathException("ConjugateGradient failed to converge after " + _maxIterations + " iterations, with a tolerance of " + _relTol + ". Final value: " + value
        + ". Final position reached was " + x.toString());
  }
View Full Code Here

    data.setG0(y * y);
    data.setGrad(grad.evaluate(startPosition));
    data.setInverseHessianEsimate(getInitializedMatrix(startPosition));

    if (!getNextPosition(function, grad, data)) {
      throw new MathException("Cannot work with this starting position. Please choose another point");
    }

    int count = 0;
    int resetCount = 1;

    while (!isConverged(data)) {
      if ((resetCount) % RESET_FREQ == 0) {
        data.setInverseHessianEsimate(getInitializedMatrix(startPosition));
        resetCount = 1;
      } else {
        _hessainUpdater.update(data);
      }
      if (!getNextPosition(function, grad, data)) {
        data.setInverseHessianEsimate(getInitializedMatrix(startPosition));
        resetCount = 1;
        if (!getNextPosition(function, grad, data)) {
          throw new MathException("Failed to converge in backtracking");
        }
      }
      count++;
      resetCount++;
      if (count > _maxSteps) {
        throw new MathException("Failed to converge after " + _maxSteps + " iterations. Final point reached: " + data.getX().toString());
      }
    }
    return data.getX();
  }
View Full Code Here

    if (data.getLowerBoundIndex(value) == n) {
      return yData[n];
    }
    final double delta = xData[high] - xData[low];
    if (Math.abs(delta) < _eps) {
      throw new MathException("x data points were not distinct");
    }
    final double a = (xData[high] - value) / delta;
    final double b = (value - xData[low]) / delta;
    final double[] y2 = splineData.getSecondDerivatives();
    return a * yData[low] + b * yData[high] + (a * (a * a - 1) * y2[low] + b * (b * b - 1) * y2[high]) * delta * delta / 6.;
View Full Code Here

    if (data.getLowerBoundIndex(value) == n) {
      return yData[n];
    }
    final double delta = xData[high] - xData[low];
    if (Math.abs(delta) < _eps) {
      throw new MathException("x data points were not distinct");
    }
    final double a = (xData[high] - value) / delta;
    final double b = (value - xData[low]) / delta;
    final double[] y2 = splineData.getSecondDerivatives();
    return (yData[high] - yData[low]) / delta + ((-3. * a * a + 1.) * y2[low] + (3. * b * b - 1.) * y2[high]) * delta / 6.;
View Full Code Here

    final RungeKuttaIntegrator1D integrator = new RungeKuttaIntegrator1D(absoluteTolerance, relativeTolerance, NB_INTEGRATION);
    double pv = 0.0;
    try {
      pv = 1.0 / Math.sqrt(2.0 * Math.PI) * integrator.integrate(integrant, -limit, limit) * dfPayment * cmsCoupon.getNotional() * cmsCoupon.getPaymentYearFraction();
    } catch (final Exception e) {
      throw new MathException(e);
    }
    return CurrencyAmount.of(cmsCoupon.getCurrency(), pv);
  }
View Full Code Here

        h = _df2 * cdfd1 * (1 - 1 / _q2) + (1 - _df2 * NORMAL.getPDF(d1) / _sigmaRootT) / _q2;
        error = Math.abs(s - _k - rhs) / _k;
        count++;
      }
      if (count == MAX_INT) {
        throw new MathException("max iterations exceeded");
      }
      s = (_k + rhs - h * s) / (1 - h); //since we've calculated h & rhs, might as well update s

      return s;
    }
View Full Code Here

    for (final Double r : roots) {
      if (r > 0) {
        return data.withAlpha(r);
      }
    }
    throw new MathException("Could not find positive real root");
  }
View Full Code Here

TOP

Related Classes of com.opengamma.analytics.math.MathException

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.