Example usage for java.lang Math exp

List of usage examples for java.lang Math exp

Introduction

In this page you can find the example usage for java.lang Math exp.

Prototype

@HotSpotIntrinsicCandidate
public static double exp(double a) 

Source Link

Document

Returns Euler's number e raised to the power of a double value.

Usage

From source file:com.opengamma.analytics.financial.model.option.pricing.analytic.AnalyticOptionModel.java

protected double getDF(final double r, final double b, final double t) {
    return Math.exp(t * (b - r));
}

From source file:StatFunctions.java

public static double pnorm(double z, boolean upper) {
    /*/*from w w w .j  a  v a2s  .c om*/
     * Reference: I. D. Hill Algorithm AS 66: "The Normal Integral" Applied
     * Statistics
     */
    double ltone = 7.0, utzero = 18.66, con = 1.28, a1 = 0.398942280444, a2 = 0.399903438504,
            a3 = 5.75885480458, a4 = 29.8213557808, a5 = 2.62433121679, a6 = 48.6959930692, a7 = 5.92885724438,
            b1 = 0.398942280385, b2 = 3.8052e-8, b3 = 1.00000615302, b4 = 3.98064794e-4, b5 = 1.986153813664,
            b6 = 0.151679116635, b7 = 5.29330324926, b8 = 4.8385912808, b9 = 15.1508972451,
            b10 = 0.742380924027, b11 = 30.789933034, b12 = 3.99019417011;
    double y, alnorm;

    if (z < 0) {
        upper = !upper;
        z = -z;
    }
    if (z <= ltone || upper && z <= utzero) {
        y = 0.5 * z * z;
        if (z > con) {
            alnorm = b1 * Math.exp(-y) / (z - b2
                    + b3 / (z + b4 + b5 / (z - b6 + b7 / (z + b8 - b9 / (z + b10 + b11 / (z + b12))))));
        } else {
            alnorm = 0.5 - z * (a1 - a2 * y / (y + a3 - a4 / (y + a5 + a6 / (y + a7))));
        }
    } else {
        alnorm = 0;
    }
    if (!upper)
        alnorm = 1 - alnorm;
    return (alnorm);
}

From source file:Methods.CalculusNewtonRaphson.java

public static void newtonRaphson3(double xold, double decPoint) {//method used calculate root point acording the paramethers that enter the method and store the data in a global paramether linked list

    double xnew, fxold, fxnew, fdashxold, diff;
    int iteration;
    iteration = 0;//from   w  w w.  j ava2s . co  m
    xNewLinkedList.head = null;//Clearing the linked list before using it
    xLinkedList.head = null;

    do {
        iteration += 1;
        // determine f(xold) and f(xold)
        fxold = (Math.exp(xold)) - (3.0 * xold);
        fdashxold = (Math.exp(xold) - 3.0);
        xnew = xold - (fxold / fdashxold);
        fxnew = xnew - Math.pow(xnew, 2.0);
        System.out.println("Approx for iteration{}" + iteration + " is " + xnew);

        if (iteration == 1) {//Block used to insert data in the linked list
            xNewLinkedList.addFirst(xold, fxold, iteration);
            xLinkedList.addFirst(xnew, fxnew, iteration);
        } else {
            xNewLinkedList.addMid(xold, fxold, iteration, iteration - 1);
            xLinkedList.addMid(xnew, fxnew, iteration, iteration - 1);
        }

        diff = Math.abs(xnew - xold);
        xold = xnew;
    } while (diff > decPoint);
    xNewLinkedList.addMid(xnew, 0.0, iteration + 1, iteration);//Block used to insert data in the linked list
    xLinkedList.addMid(xnew, 0.0, iteration + 1, iteration);
    System.out.println("root to six decimal places is " + xnew);

}

From source file:com.analog.lyric.dimple.factorfunctions.NegativeExpGamma.java

@Override
public final double evalEnergy(Value[] arguments) {
    int index = 0;
    if (!_parametersConstant) {
        _alpha = arguments[index++].getDouble(); // First input is alpha parameter (must be non-negative)
        if (_alpha <= 0)
            return Double.POSITIVE_INFINITY;
        _beta = arguments[index++].getDouble(); // Second input is beta parameter (must be non-negative)
        if (_beta <= 0)
            return Double.POSITIVE_INFINITY;
        _alphaMinusOne = _alpha - 1;//w  w w.  ja v  a 2s .  co  m
        _logGammaAlphaMinusAlphaLogBeta = org.apache.commons.math3.special.Gamma.logGamma(_alpha)
                - _alpha * Math.log(_beta);
    }
    final int length = arguments.length;
    final int N = length - index; // Number of non-parameter variables
    double sum = 0;
    for (; index < length; index++) {
        final double x = arguments[index].getDouble(); // Remaining inputs are NegativeExpGamma variables
        sum += x * _alphaMinusOne + Math.exp(-x) * _beta;
    }
    return sum + N * _logGammaAlphaMinusAlphaLogBeta;
}

From source file:etomica.math.SpecialFunctions.java

private static double gser(double a, double x) {
    int nmax = 500;
    double epsilon = 3.0e-12;
    double ap = a;
    double sum = 1.0 / a;
    double del = sum;
    for (int n = 1; n <= nmax; n++) {
        ap++;//from   w w w.  jav  a  2 s . c  o  m
        del *= x / ap;
        sum += del;
        if (Math.abs(del) < Math.abs(sum) * epsilon)
            break;
    }
    return sum * Math.exp(-x + a * Math.log(x) - lnGamma(a));
}

From source file:com.opengamma.analytics.financial.model.option.pricing.analytic.EuropeanOptionOnEuropeanVanillaOptionModel.java

@Override
public Function1D<StandardOptionDataBundle, Double> getPricingFunction(
        final EuropeanOptionOnEuropeanVanillaOptionDefinition definition) {
    Validate.notNull(definition, "definition");
    return new Function1D<StandardOptionDataBundle, Double>() {

        @SuppressWarnings("synthetic-access")
        @Override//  www . j  av  a2  s .  c  om
        public Double evaluate(final StandardOptionDataBundle data) {
            Validate.notNull(data, "data");
            final double s = data.getSpot();
            final OptionDefinition underlying = definition.getUnderlyingOption();
            final double k1 = definition.getStrike();
            final double k2 = underlying.getStrike();
            final ZonedDateTime date = data.getDate();
            final double t1 = definition.getTimeToExpiry(date);
            final double t2 = definition.getUnderlyingOption().getTimeToExpiry(date);
            final double deltaT = t2 - t1;
            final double sigma = data.getVolatility(t1, k1); //REVIEW emcleod 20-7-10 This will work with a flat volatility surface but otherwise will give odd results
            final double r = data.getInterestRate(t1);
            final double b = data.getCostOfCarry();
            final double criticalValue = getCriticalValue(new EuropeanVanillaOptionDefinition(k2,
                    new Expiry(DateUtils.getDateOffsetWithYearFraction(date, deltaT)), underlying.isCall()),
                    data, k1);
            final double d1 = getD1(s, criticalValue, t1, sigma, b);
            final double d2 = getD2(d1, sigma, t1);
            final double d3 = getD1(s, k2, t2, sigma, b);
            final double d4 = getD2(d3, sigma, t2);
            if (definition.isCall()) {
                final double rho = Math.sqrt(t1 / t2);
                if (underlying.isCall()) {
                    return s * Math.exp(t2 * (b - r)) * BIVARIATE.getCDF(new double[] { d3, d1, rho })
                            - k2 * Math.exp(-r * t2) * BIVARIATE.getCDF(new double[] { d4, d2, rho })
                            - k1 * Math.exp(-r * t1) * NORMAL.getCDF(d2);
                }
                return k2 * Math.exp(-r * t2) * BIVARIATE.getCDF(new double[] { -d4, -d2, rho })
                        - s * Math.exp(t2 * (b - r)) * BIVARIATE.getCDF(new double[] { -d3, -d1, rho })
                        - k1 * Math.exp(-r * t1) * NORMAL.getCDF(-d2);
            }
            final double rho = -Math.sqrt(t1 / t2);
            if (underlying.isCall()) {
                return k2 * Math.exp(-r * t2) * BIVARIATE.getCDF(new double[] { d4, -d2, rho })
                        - s * Math.exp(t2 * (b - r)) * BIVARIATE.getCDF(new double[] { d3, -d1, rho })
                        + k1 * Math.exp(-r * t1) * NORMAL.getCDF(-d2);
            }
            return s * Math.exp(t2 * (b - r)) * BIVARIATE.getCDF(new double[] { -d3, d1, rho })
                    - k2 * Math.exp(-r * t2) * BIVARIATE.getCDF(new double[] { -d4, d2, rho })
                    + k1 * Math.exp(-r * t1) * NORMAL.getCDF(d2);
        }

    };
}

From source file:com.opengamma.analytics.math.statistics.distribution.GeneralizedExtremeValueDistribution.java

private double getT(final double x) {
    if (_ksiIsZero) {
        return Math.exp(-(x - _mu) / _sigma);
    }//from ww w . ja  va  2s. com
    if (_ksi < 0 && x > _mu - _sigma / _ksi) {
        throw new IllegalArgumentException(
                "Support for GEV is in the range -infinity -> mu - sigma / ksi when ksi < 0");
    }
    if (_ksi > 0 && x < _mu - _sigma / _ksi) {
        throw new IllegalArgumentException(
                "Support for GEV is in the range mu - sigma / ksi -> +infinity when ksi > 0");
    }
    return Math.pow(1 + _ksi * (x - _mu) / _sigma, -1. / _ksi);
}

From source file:com.opengamma.analytics.financial.model.option.pricing.analytic.twoasset.ProductOptionModel.java

/**
 * Gets the pricing function for a European-style product option 
 * @param definition The option definition
 * @return The pricing function/*  w  w  w.jav  a  2 s  .com*/
 * @throws IllegalArgumentException If the definition is null
 */
@Override
public Function1D<StandardTwoAssetOptionDataBundle, Double> getPricingFunction(
        final ProductOptionDefinition definition) {
    Validate.notNull(definition, "definition");
    return new Function1D<StandardTwoAssetOptionDataBundle, Double>() {

        @SuppressWarnings("synthetic-access")
        @Override
        public Double evaluate(final StandardTwoAssetOptionDataBundle data) {
            Validate.notNull(data, "data");
            final double s1 = data.getFirstSpot();
            final double s2 = data.getSecondSpot();
            final double k = definition.getStrike();
            final double b1 = data.getFirstCostOfCarry();
            final double b2 = data.getSecondCostOfCarry();
            final double t = definition.getTimeToExpiry(data.getDate());
            final double r = data.getInterestRate(t);
            final double sigma1 = data.getFirstVolatility(t, k);
            final double sigma2 = data.getSecondVolatility(t, k);
            final double rho = data.getCorrelation();
            final double sigma = Math.sqrt(sigma1 * sigma1 + sigma2 * sigma2 + 2 * rho * sigma1 * sigma2);
            final double sigmaT = sigma * Math.sqrt(t);
            final double f = s1 * s2 * Math.exp(t * (b1 + b2 + rho * sigma1 * sigma2));
            final double d1 = (Math.log(f / k) + t * sigma * sigma / 2) / sigmaT;
            final double d2 = d1 - sigmaT;
            final int sign = definition.isCall() ? 1 : -1;
            return Math.exp(-r * t) * sign * (f * NORMAL.getCDF(sign * d1) - k * NORMAL.getCDF(sign * d2));
        }

    };
}

From source file:classif.gmm.DTWGMMSymbolicSequence.java

public void cluster() {
    // init/*from   ww  w.  j a  va2  s  .  c om*/
    boolean isBig;
    ArrayList<Sequence>[] affectation = new ArrayList[nbClusters];
    int runtime = 0;
    do {
        if (runtime > 10)
            nbClusters -= 1;
        isBig = true;
        KMeansSymbolicSequence kmeans = new KMeansSymbolicSequence(nbClusters, data);
        kmeans.cluster();
        centroidsPerCluster = kmeans.centers;
        affectation = kmeans.affectation;
        for (ArrayList<Sequence> Eachaffectation : affectation) {
            if (Eachaffectation.size() < minObj) {
                isBig = false;
                break;
            }
        }
        runtime++;
    } while (isBig == false);

    sigmasPerCluster = new double[nbClusters];
    nck = new double[nbClusters];
    sumnck = data.size();
    for (int k = 0; k < nbClusters; k++) {
        if (centroidsPerCluster[k] != null) { // ~ if empty cluster
            // find the center
            nck[k] = affectation[k].size();
            // compute sigma
            double sumOfSquares = centroidsPerCluster[k].sumOfSquares(affectation[k]);
            sigmasPerCluster[k] = Math.sqrt(sumOfSquares / nck[k]);
        } else
            System.err.println("ERROR");
    }

    double sumoflog = 0.0;
    double prevsumoflog = -(Math.exp(308));

    // computing initial likelihood
    sumoflog = loglikelihood(centroidsPerCluster, sigmasPerCluster, nck);

    /*while (Math.abs(sumoflog - prevsumoflog) > threshold) {
       prevsumoflog = sumoflog;
       sumoflog = gmmprocess();
    }*/
    for (int i = 0; i < 10; i++) {
        gmmprocess(i);
    }
}

From source file:beast.math.distributions.BetaDistribution.java

/**
 * probability density function of the distribution
 *
 * @param x argument// w  w w.jav  a  2s  . co m
 * @return pdf value
 */
public double pdf(double x) {
    recomputeZ();
    if (x < 0 || x > 1) {
        return 0;
    } else if (x == 0) {
        if (alpha < 1) {
            // AR - throwing exceptions deep in numerical code causes trouble. Catching runtime
            // exceptions is bad. Better to return NaN and let the calling code deal with it.
            return Double.NaN;
            //                throw MathRuntimeException.createIllegalArgumentException(
            //                        "Cannot compute beta density at 0 when alpha = {0,number}", alpha);
        }
        return 0;
    } else if (x == 1) {
        if (beta < 1) {
            // AR - throwing exceptions deep in numerical code causes trouble. Catching runtime
            // exceptions is bad. Better to return NaN and let the calling code deal with it.
            return Double.NaN;
            //                throw MathRuntimeException.createIllegalArgumentException(
            //                        "Cannot compute beta density at 1 when beta = %.3g", beta);
        }
        return 0;
    } else {
        double logX = Math.log(x);
        double log1mX = Math.log1p(-x);
        return Math.exp((alpha - 1) * logX + (beta - 1) * log1mX - z);
    }
}