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.interestrate.curve.ForwardCurve.java

protected static Curve<Double, Double> getForwardCurve(final Double spot,
        final Curve<Double, Double> driftCurve) {
    final Function1D<Double, Double> fwd = new Function1D<Double, Double>() {

        @Override//from   w  ww  .j a va2 s . c  o m
        public Double evaluate(final Double t) {
            final Function1D<Double, Double> driftFunc = new Function1D<Double, Double>() {

                @Override
                public Double evaluate(final Double y) {
                    return driftCurve.getYValue(y);
                }

            };
            @SuppressWarnings("synthetic-access")
            final double temp = INTEGRATOR.integrate(driftFunc, 0.0, t);
            return spot * Math.exp(temp);
        }

    };
    return new FunctionalDoublesCurve(fwd) {

        public Object writeReplace() {
            return new InvokedSerializedForm(ForwardCurve.class, "getForwardCurve", spot, driftCurve);
        }
    };
}

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

public Map<String, List<DoublesPair>> calculatePriceSensitivityToCurve(final Annuity<? extends Payment> annuity,
        final YieldCurveBundle curves, final double zSpread) {
    Validate.notNull(annuity, "annuity");
    Validate.notNull(curves, "curves");

    final Map<String, List<DoublesPair>> temp = PV_SENSITIVITY_CALCULATOR.visit(annuity, curves);
    if (zSpread == 0.0) {
        return temp;
    }/*from w ww  .  jav  a  2s  . c  om*/
    final Map<String, List<DoublesPair>> result = new HashMap<String, List<DoublesPair>>();
    for (final String name : temp.keySet()) {
        final List<DoublesPair> unadjusted = temp.get(name);
        final ArrayList<DoublesPair> adjusted = new ArrayList<DoublesPair>(unadjusted.size());
        for (final DoublesPair pair : unadjusted) {
            final DoublesPair newPair = new DoublesPair(pair.first,
                    pair.second * Math.exp(-zSpread * pair.first));
            adjusted.add(newPair);
        }
        result.put(name, adjusted);
    }
    return result;
}

From source file:beast.math.MathUtils.java

/**
 * @param logpdf array of unnormalised log probabilities
 * @return a sample according to an unnormalised probability distribution
 *
 * Use this if probabilities are rounding to zero when converted to real space
 *///from  w w w  . j ava2s  . c om
public static int randomChoiceLogPDF(double[] logpdf) {

    double scalingFactor = Double.NEGATIVE_INFINITY;

    for (double aLogpdf : logpdf) {
        if (aLogpdf > scalingFactor) {
            scalingFactor = aLogpdf;
        }
    }

    if (scalingFactor == Double.NEGATIVE_INFINITY) {
        throw new Error("randomChoiceLogPDF falls through -- all -INF components in input distribution");
    }

    for (int j = 0; j < logpdf.length; j++) {
        logpdf[j] = logpdf[j] - scalingFactor;
    }

    double[] pdf = new double[logpdf.length];

    for (int j = 0; j < logpdf.length; j++) {
        pdf[j] = Math.exp(logpdf[j]);
    }

    return randomChoicePDF(pdf);

}

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

/**
 * {@inheritDoc}/*  w  ww  .j  a v a2s . c om*/
 */
@Override
public Function1D<StandardOptionDataBundle, Double> getPricingFunction(
        final EuropeanOptionOnEuropeanVanillaOptionDefinition 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 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 sigma = data.getVolatility(t1, k1);
            final double r = data.getInterestRate(t1);
            final double b = data.getCostOfCarry();
            final OptionDefinition callDefinition = underlying.isCall() ? underlying
                    : new EuropeanVanillaOptionDefinition(k2, underlying.getExpiry(), true);
            final GreekResultCollection result = BSM.getGreeks(callDefinition, data, REQUIRED_GREEKS);
            final double callBSM = result.get(Greek.FAIR_PRICE);
            final double callDelta = result.get(Greek.DELTA);
            final double underlyingSigma = sigma * Math.abs(callDelta) * s / callBSM;
            final double d1 = getD1(callBSM, k1, t1, underlyingSigma, b);
            final double d2 = getD2(d1, underlyingSigma, t1);
            final int sign = definition.isCall() ? 1 : -1;
            if (underlying.isCall()) {
                return sign * (callBSM * NORMAL.getCDF(sign * d1)
                        - k1 * Math.exp(-r * t1) * NORMAL.getCDF(sign * d2));
            }
            throw new NotImplementedException("This model can only price call-on-call or put-on-call options");
        }

    };
}

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

private double[] getRightSensitivities(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;
    final double ex = Math.exp(m * value);
    final double[] result = new double[data.size()];
    result[data.size() - 1] = ex * value / (x * y);
    return result;
}

From source file:com.xtructure.xneat.network.impl.Neuron.java

/**
 * Updates this {@link Neuron} by passing through its input signal. The new
 * output signal is becomes:<br>// w  ww. j  a  va  2  s.c  om
 * 1.0 / (1.0 + Math.exp(-activationSlope * inputSignal));
 * 
 * @return the difference between this {@link Neuron}'s new output signal
 *         and its old signal
 */
public double calculateSignal() {
    LOGGER.trace("begin %s.calculateSignal()", getClass().getSimpleName());
    double oldSignal = getSignal();
    setSignal(1.0 / (1.0 + Math.exp(-activationSlope * getInputSignal())));
    setInputSignal(0.0);
    double rVal = getSignal() - oldSignal;
    LOGGER.trace("will return: %s", rVal);
    LOGGER.trace("end %s.calculateSignal()", getClass().getSimpleName());
    return rVal;
}

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

private double getLambda2(final double sigma, final double t, final double kurtosis) {
    final double q = Math.sqrt(Math.exp(sigma * sigma * t) - 1);
    final double q2 = q * q;
    final double q4 = q2 * q2;
    final double q6 = q4 * q2;
    final double q8 = q6 * q2;
    final double kurtosisDistribution = 16 * q2 + 15 * q4 + 6 * q6 + q8 + 3;
    return kurtosis - kurtosisDistribution;
}

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

@Override
public Function1D<T, RecombiningTrinomialTree<DoublesPair>> getTreeGeneratingFunction(
        final OptionDefinition definition) {
    return new Function1D<T, RecombiningTrinomialTree<DoublesPair>>() {

        @SuppressWarnings({ "synthetic-access" })
        @Override/*from w w w.  j  a  va  2 s. c o  m*/
        public RecombiningTrinomialTree<DoublesPair> evaluate(final T data) {
            final DoublesPair[][] spotAndOptionPrices = new DoublesPair[_maxDepthToSave + 1][_maxWidthToSave];
            final OptionPayoffFunction<T> payoffFunction = definition.getPayoffFunction();
            final OptionExerciseFunction<T> exerciseFunction = definition.getExerciseFunction();
            final double u = _model.getUpFactor(definition, data, _n, _j);
            final double m = _model.getMidFactor(definition, data, _n, _j);
            final double d = _model.getDownFactor(definition, data, _n, _j);
            final double spot = data.getSpot();
            final double t = definition.getTimeToExpiry(data.getDate());
            final double r = data.getInterestRate(t);
            final double edx = Math.exp(_model.getDX(definition, data, _n, _j));
            final double df = Math.exp(-r * t / _n);
            double newSpot = spot * Math.pow(edx, -_n);
            final DoublesPair[] tempResults = new DoublesPair[_j];
            for (int i = 0; i < _j; i++) {
                tempResults[i] = DoublesPair.of(newSpot,
                        payoffFunction.getPayoff((T) data.withSpot(newSpot), 0.));
                if (_n == _maxDepthToSave) {
                    spotAndOptionPrices[_n][i] = tempResults[i];
                }
                newSpot *= edx;
            }
            double optionValue, spotValue;
            T newData;
            for (int i = _n - 1; i >= 0; i--) {
                for (int j = 1; j <= RecombiningTrinomialTree.NODES.evaluate(i); j++) {
                    optionValue = df * (u * tempResults[j + 1].second + m * tempResults[j].second
                            + d * tempResults[j - 1].second);
                    spotValue = df * tempResults[j].first;
                    newData = (T) data.withSpot(spotValue);
                    tempResults[j - 1] = DoublesPair.of(spotValue,
                            exerciseFunction.shouldExercise(newData, optionValue)
                                    ? payoffFunction.getPayoff(newData, optionValue)
                                    : optionValue);
                    if (i <= _maxDepthToSave) {
                        spotAndOptionPrices[i][j - 1] = tempResults[j - 1];
                    }
                }
            }
            return new RecombiningTrinomialTree<DoublesPair>(spotAndOptionPrices);
        }

    };
}

From source file:edu.duke.cs.osprey.ematrix.epic.GaussianLowEnergySampler.java

private double radialIntegral(double a, int k) {
    //\int_0^a exp(-r^2/2) r^k dr
    if (k > 1)
        return (k - 1) * radialIntegral(a, k - 2) - Math.pow(a, k - 1) * Math.exp(-a * a / 2);
    else if (k == 1)
        return 1 - Math.exp(-a * a / 2);
    else if (k == 0)
        return Math.sqrt(Math.PI / 2) * Erf.erf(a / Math.sqrt(2));
    else//from www .  j av a 2  s .c o m
        throw new RuntimeException("ERROR: Negative k not supported here: " + k);
}

From source file:com.itemanalysis.psychometrics.irt.equating.RobustZEquatingTest.java

private void testA() throws IllegalArgumentException {
    double[] aDiff = new double[nA];
    za = new RobustZ[nA];

    for (int i = 0; i < nA; i++) {
        aDiff[i] = Math.log(aX[i]) - Math.log(aY[i]);
    }//from   ww w .j  a  va 2s . c  om

    double median = percentile.evaluate(aDiff, 50);
    double q3 = percentile.evaluate(aDiff, 75);
    double q1 = percentile.evaluate(aDiff, 25);
    double iqr = q3 - q1;
    Mean mean = new Mean();

    for (int i = 0; i < nA; i++) {
        za[i] = new RobustZ(aDiff[i], median, iqr);
        if (!za[i].significant(significanceLevel)) {
            mean.increment(aDiff[i]);
        }
    }
    slope = Math.exp(mean.getResult());
}