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:edu.byu.nlp.stats.VectorCategoricalDistribution.java

/** {@inheritDoc} */
@Override/*  w  w  w.  ja  v  a2 s . c  o m*/
public double entropy() {
    double entropy = 0.0;
    // TODO(rhaertel): when Apache fixes their iterator, then use that.
    for (int i = 0; i < logProbs.getDimension(); i++) {
        double logProb = logProbs.getEntry(i);
        if (logProb > Double.NEGATIVE_INFINITY) {
            entropy -= Math.exp(logProb) * logProb;
        }
    }
    return entropy;
}

From source file:com.insightml.math.distributions.GaussianDistribution.java

@Override
public double probability(final double x) {
    final double diff = x - mean;
    if (sigmaSquare == 0) {
        return diff == 0 ? 1 : 0;
    }//from  ww  w  .j  a v  a  2 s .com
    return factor * (diff == 0 ? 1 : Math.exp(-diff * diff / (2 * sigmaSquare)));
}

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

@Override
public Function1D<SkewKurtosisOptionDataBundle, Double> getPricingFunction(final OptionDefinition definition) {
    Validate.notNull(definition);// w w  w .j av a2  s .c  o m
    final Function1D<SkewKurtosisOptionDataBundle, Double> pricingFunction = new Function1D<SkewKurtosisOptionDataBundle, Double>() {

        @SuppressWarnings("synthetic-access")
        @Override
        public Double evaluate(final SkewKurtosisOptionDataBundle data) {
            Validate.notNull(data);
            final double s = data.getSpot();
            final double k = definition.getStrike();
            final double t = definition.getTimeToExpiry(data.getDate());
            final double b = data.getCostOfCarry();
            final double r = data.getInterestRate(t);
            final double sigma = data.getVolatility(t, k);
            final double sigmaT = sigma * Math.sqrt(t);
            final double d1 = getD1(s, k, t, sigma, b);
            final double d2 = getD2(d1, sigma, t);
            final double skew = data.getAnnualizedSkew();
            final double kurtosis = data.getAnnualizedPearsonKurtosis();
            final double correction = sigmaT * (skew * (2 * sigmaT - d1) / (6. * Math.sqrt(t))
                    - kurtosis * (1 - d1 * d1 + 3 * sigmaT * (d1 - sigmaT)) / (24 * t));
            final double df1 = Math.exp(-r * t);
            final double df2 = getDF(r, b, t);
            final double callPrice = s * df2 * (NORMAL.getCDF(d1) + NORMAL.getPDF(d1) * correction)
                    - k * df1 * NORMAL.getCDF(d2);
            if (!definition.isCall()) {
                return callPrice + k * df1 - s * df2;
            }
            return callPrice;
        }
    };
    return pricingFunction;
}

From source file:com.opengamma.analytics.financial.equity.future.pricing.EquityFutureCostOfCarry.java

/**
 * @param future EquityFuture derivative
 * @param dataBundle Contains funding curve, spot value and continuous dividend yield 
 * @return The change in the present value given a unit value change in the underlying's spot value
 *///from  w  w w .j  a va 2s .  co m
@Override
public double spotDelta(final EquityFuture future, final EquityFutureDataBundle dataBundle) {
    Validate.notNull(future, "Future");
    Validate.notNull(dataBundle);
    Validate.notNull(dataBundle.getCostOfCarry());
    return future.getUnitAmount() * Math.exp(dataBundle.getCostOfCarry() * future.getTimeToSettlement());
}

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

/**
 * {@inheritDoc}/*from   w  w w. j a  v a2  s.  co  m*/
 */
@Override
public Function1D<StandardOptionDataBundle, Double> getPricingFunction(
        final AssetOrNothingOptionDefinition definition) {
    Validate.notNull(definition, "definition");
    return new Function1D<StandardOptionDataBundle, Double>() {

        @SuppressWarnings("synthetic-access")
        @Override
        public Double evaluate(final StandardOptionDataBundle data) {
            Validate.notNull(data, "data");
            final double s = data.getSpot();
            final double k = definition.getStrike();
            final double t = definition.getTimeToExpiry(data.getDate());
            final double r = data.getInterestRate(t);
            final double sigma = data.getVolatility(t, k);
            final double b = data.getCostOfCarry();
            final double d = getD1(s, k, t, sigma, b);
            return s * Math.exp(t * (b - r)) * NORMAL.getCDF(definition.isCall() ? d : -d);
        }

    };
}

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

@Override
public Double interpolate(final Interpolator1DDataBundle data, final Double value) {
    Validate.notNull(value, "value");
    Validate.notNull(data, "data bundle");
    Validate.isTrue(data instanceof Interpolator1DLogPiecewisePoynomialDataBundle);
    final Interpolator1DLogPiecewisePoynomialDataBundle polyData = (Interpolator1DLogPiecewisePoynomialDataBundle) data;
    final DoubleMatrix1D res = FUNC.evaluate(polyData.getPiecewisePolynomialResultsWithSensitivity(), value);
    return Math.exp(res.getEntry(0));
}

From source file:bide.math.NormalDistribution.java

public static double pdf(double x, double m, double sd) {
    double a = 1.0 / (MATH_SQRT_2PI * sd);
    double b = -(x - m) * (x - m) / (2.0 * sd * sd);

    return a * Math.exp(b);
}

From source file:com.opengamma.analytics.financial.model.option.pricing.tree.LogNormalBinomialTreeBuilder.java

@Override
protected DoublesPair getCentralNodePair(double dt, double sigma, double forward, double centreLevel) {

    Function1D<Double, Double> func = new CentreNode(dt, sigma, forward, centreLevel);
    double[] limits = s_bracketRoot.getBracketedPoints(func, forward,
            forward * Math.exp(sigma * Math.sqrt(dt)));

    double upper = s_root.getRoot(func, limits[0], limits[1]);
    double lower = centreLevel * centreLevel / upper;
    return new DoublesPair(lower, upper);
}

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

/**
 * {@inheritDoc}/*from w w w  .j  av  a  2 s. c o m*/
 */
@Override
public double getCDF(final Double x) {
    Validate.notNull(x);
    return 0.5 * (1 + Math.signum(x - _mu) * (1 - Math.exp(-Math.abs(x - _mu) / _b)));
}

From source file:agents.firm.sales.prediction.LearningFixedElasticitySalesPredictor.java

@Override
protected void updateRegressorAndUseItToUpdatePredictor() {
    //force a regression
    regressor.updateModel();/*from ww  w.j  a  va2s .  co  m*/
    //update slope (we need to put the inverse as a sign because the number is subtracted from old price)
    if (!Double.isNaN(regressor.getSlope()))
        predictor.setDecrementDelta(
                (int) Math.round(-regressor.getSlope() * Math.exp(regressor.getLastPriceObserved())
                        / Math.exp(regressor.getLastQuantityConsumedObserved())));
    else
        predictor.setDecrementDelta(0);
}