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:desmoj.core.dist.DiscreteDistPoisson.java

/**
 * Returns the next poisson distributed sample from this distribution.
 * /*w  w  w .j ava 2  s  .  c om*/
 * @return Long : The next Poisson distributed sample. This will be zero if
 *         the given mean value <= 0.
 */
public Long sample() {

    incrementObservations();

    double l = Math.exp(-mean);
    long k = 0;
    double p = 1;

    do {
        k++;
        if (antithetic)
            p *= randomGenerator.nextDouble();
        else
            p *= (1 - randomGenerator.nextDouble());
    } while (p > l);

    if (this.currentlySendTraceNotes())
        this.traceLastSample(Long.toString(k - 1));

    return k - 1;
}

From source file:com.opengamma.analytics.math.interpolation.ExponentialExtrapolator1D.java

private Double rightExtrapolateDerivative(final Interpolator1DDataBundle data, final Double value) {
    Validate.notNull(data, "data");
    Validate.notNull(value, "value");
    final double x = data.lastKey();
    final double y = data.lastValue();
    final double m = Math.log(y) / x;
    return m * Math.exp(m * value);
}

From source file:feast.expressions.ExpCalculatorParametricDistribution.java

@Override
public Distribution getDistribution() {

    return new ContinuousDistribution() {

        @Override/*from   w  w w .  ja  v a  2  s  . c  om*/
        public double inverseCumulativeProbability(double p) throws MathException {
            throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        }

        @Override
        public double density(double x) {
            if (isLogInput.get())
                return Math.exp(getExpressionValue(x));
            else
                return getExpressionValue(x);
        }

        @Override
        public double logDensity(double x) {
            if (isLogInput.get())
                return getExpressionValue(x);
            else
                return Math.log(getExpressionValue(x));
        }

        @Override
        public double cumulativeProbability(double x) throws MathException {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public double cumulativeProbability(double x0, double x1) throws MathException {
            throw new UnsupportedOperationException("Not supported yet.");
        }
    };

}

From source file:com.opengamma.analytics.financial.interestrate.annuity.YieldSensitivityCalculator.java

/**
 * Calculate the present value of a set of cash flows given a yield 
 * @param annuity  Set of known cash flows 
 * @param yield Continuously compounded constant interest rate 
 * @return Present value (dirty price)/*from  w w w. j  av  a 2s . com*/
 */
public double calculatePriceForYield(final Annuity<? extends PaymentFixed> annuity, final double yield) {
    Validate.notNull(annuity, "annuity");
    double sum = 0;

    final int n = annuity.getNumberOfPayments();
    PaymentFixed temp;
    for (int i = 0; i < n; i++) {
        temp = annuity.getNthPayment(i);
        sum += temp.getAmount() * Math.exp(-yield * temp.getPaymentTime());
    }
    return sum;
}

From source file:edu.packt.neuralnet.som.CompetitiveLearning.java

public double getLearningRate(int epoch) {
    double exponent = (double) (epoch) / (double) (referenceEpoch);
    return initialLearningRate * Math.exp(-exponent);
}

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

/**
 * Gets the pricing function for a European-style relative outperformance option
 * @param definition The option definition
 * @return The pricing function/*from  ww  w.  j av  a  2 s.com*/
 * @throws IllegalArgumentException If the definition is null
 */
@Override
public Function1D<StandardTwoAssetOptionDataBundle, Double> getPricingFunction(
        final RelativeOutperformanceOptionDefinition 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 * Math.exp(t * (b1 - b2 + sigma2 * sigma2 - rho * sigma1 * sigma2)) / s2;
            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:edu.brown.utils.MathUtil.java

/**
 * Returns the geometric mean of the entries in the input array. If the
 * zero_value is not null, all zeroes will be replaced with that value
 * //w  w  w.  j  a v  a2s.c o  m
 * @param values
 * @param zero_value
 * @return
 */
public static final double geometricMean(final double[] values, final Double zero_value) {
    double sumLog = 0.0d;
    for (double v : values) {
        if (v == 0 && zero_value != null)
            v = zero_value;
        sumLog += Math.log(v);
    }
    return Math.exp(sumLog / (double) values.length);
}

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

/**
 * Gets the pricing function for a European-style exchange asset option 
 * @param definition The option definition
 * @return The pricing function/*from  w  w  w .ja v  a2 s .com*/
 * @throws IllegalArgumentException If the definition is null
 */
@Override
public Function1D<StandardTwoAssetOptionDataBundle, Double> getPricingFunction(
        final EuropeanExchangeAssetOptionDefinition 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 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, s1);
            final double sigma2 = data.getSecondVolatility(t, s2);
            final double rho = data.getCorrelation();
            final double q1 = definition.getFirstQuantity();
            final double q2 = definition.getSecondQuantity();
            final double sigma = Math.sqrt(sigma1 * sigma1 + sigma2 * sigma2 - 2 * rho * sigma1 * sigma2);
            final double sigmaT = sigma * Math.sqrt(t);
            final double d1 = (Math.log(q1 * s1 / q2 / s2) + t * (b1 - b2 + sigma * sigma / 2)) / sigmaT;
            final double d2 = d1 - sigmaT;
            return q1 * s1 * Math.exp(t * (b1 - r)) * NORMAL.getCDF(d1)
                    - q2 * s2 * Math.exp(t * (b2 - r)) * NORMAL.getCDF(d2);
        }

    };
}

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

/**
 * {@inheritDoc}//  www  .  j a va 2  s  . c om
 */
@Override
public Function1D<StandardOptionDataBundle, Double> getPricingFunction(final OptionDefinition definition) {
    Validate.notNull(definition);
    final Function1D<StandardOptionDataBundle, Double> pricingFunction = new Function1D<StandardOptionDataBundle, Double>() {

        @SuppressWarnings("synthetic-access")
        @Override
        public Double evaluate(final StandardOptionDataBundle data) {
            Validate.notNull(data);
            final ZonedDateTime date = data.getDate();
            final double s = data.getSpot();
            final double k = definition.getStrike();
            final double t = definition.getTimeToExpiry(date);
            final double r = data.getInterestRate(t);
            final double b = data.getCostOfCarry();

            if (s == 0) {
                return definition.isCall() ? 0 : Math.exp(-r * t) * k;
            }

            final double sigma = data.getVolatility(t, k);
            final double d1 = getD1(s, k, t, sigma, b);
            final double d2 = getD2(d1, sigma, t);
            final int sign = definition.isCall() ? 1 : -1;
            return sign * Math.exp(-r * t)
                    * (s * Math.exp(b * t) * NORMAL.getCDF(sign * d1) - k * NORMAL.getCDF(sign * d2));
        }
    };
    return pricingFunction;
}

From source file:com.opengamma.analytics.financial.model.finitedifference.ExponentialMeshing.java

/**
 * creates a non-uniform set of points according to the formula $x_i = \theta + \eta*\exp(\lambda z_i)$, where the points run from 
 * $x_0$ to $x_{N-1}$ (i.e. there are N points), $\eta = (x_{N-1} - x_0)/(\exp(\lambda) - 1)$ and $\theta = x_0 - \eta$. 
 * The points $z_i$ are are close as possible to uniform on (0,1) while allowing the <em>fixedPoints</em> to be in the set of points.
 * @param lowerBound The value of $x_0$//from w w w  .ja va2 s. com
 * @param upperBound The value of $x_{N-1}$
 * @param nPoints Number of Points (equal to N in the above formula).The number of points must exceed the number of fixed points by at least 2.
 * @param lambda Bunching parameter. $\lambda = 0$ is uniform, $\lambda > 0$ gives a high density of points near $x_0$ and $\lambda < 0$ gives a high density
 * of points near $x_{N-1}$
 * @param fixedPoints set of points that must be included. These must be within the lower and upper bound (exclusive) 
 */
public ExponentialMeshing(final double lowerBound, final double upperBound, final int nPoints,
        final double lambda, final double[] fixedPoints) {
    super(nPoints);
    Validate.isTrue(upperBound > lowerBound, "need upperBound>lowerBound");
    ArgumentChecker.notNull(fixedPoints, "null fixedPoints");
    _lambda = lambda;
    _l = lowerBound;
    _r = upperBound;

    _fpValues = FunctionUtils.unique(fixedPoints);

    int m = _fpValues.length;
    final double[] fp = new double[m];

    if (lambda == 0.0) {
        _linear = true;
        _theta = lowerBound;
        _eta = (upperBound - lowerBound);
        for (int ii = 0; ii < m; ii++) {
            fp[ii] = (fixedPoints[ii] - _theta) / _eta;
        }
    } else {
        _linear = false;
        _eta = (upperBound - lowerBound) / (Math.exp(lambda) - 1);
        _theta = lowerBound - _eta;
        for (int ii = 0; ii < m; ii++) {
            fp[ii] = Math.log((_fpValues[ii] - _theta) / _eta) / lambda;
        }
    }
    _um = new UniformMeshing(nPoints, fp);
}