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.math.minimization.SingleRangeLimitTransform.java

/**
 * {@inheritDoc}//from   w w  w  . j  ava  2 s .c  om
 */
@Override
public double inverseTransform(final double y) {
    if (y > EXP_MAX) {
        return _limit + _sign * y;
    } else if (y < -EXP_MAX) {
        return _limit;
    }
    return _limit + _sign * Math.log(Math.exp(y) + 1);
}

From source file:com.opengamma.analytics.financial.interestrate.market.description.MarketForwardTimeDecorated.java

@Override
public double getForwardRate(IborIndex index, double startTime, double endTime, double accuralFactor) {
    if (index == _index) {
        if (_time == startTime) {
            double rateStart = -Math.log(_forwardCurve.getDiscountFactor(_time)) / _time;
            double dfStart = Math.exp(-(rateStart + _shift) * _time);
            return (dfStart / _forwardCurve.getDiscountFactor(endTime) - 1) / accuralFactor;
        }/*from w  w  w.  j a  v  a  2  s  .  co m*/
        if (_time == endTime) {
            double rateEnd = -Math.log(_forwardCurve.getDiscountFactor(_time)) / _time;
            double dfEnd = Math.exp(-(rateEnd + _shift) * _time);
            return (_forwardCurve.getDiscountFactor(startTime) / dfEnd - 1) / accuralFactor;
        }
    }
    return super.getForwardRate(index, startTime, endTime, accuralFactor);
}

From source file:de.biomedical_imaging.ij.steger.Convol.java

public double phi2(double x, double sigma) {
    double t;//from   www . j a  v  a2s . c om
    t = x / sigma;
    return -x * SQRT_2_PI_INV / Math.pow(sigma, 3.0) * Math.exp(-0.5 * t * t);
}

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

@Override
public Double interpolate(final Interpolator1DDataBundle data, final Double value) {
    Validate.notNull(value, "value");
    Validate.notNull(data, "data bundle");
    Validate.isTrue(data instanceof Interpolator1DMonotonicIncreasingDataBundle);
    final Interpolator1DMonotonicIncreasingDataBundle miData = (Interpolator1DMonotonicIncreasingDataBundle) data;

    final int n = data.size() - 1;
    final double[] xData = data.getKeys();
    final double[] yData = data.getValues();

    double h, dx, a, b;
    if (value < data.firstKey()) {
        h = 0;/*ww  w. j av  a  2s.  c o  m*/
        dx = value;
        a = miData.getA(0);
        b = miData.getB(0);
    } else if (value > data.lastKey()) {
        h = yData[n];
        dx = value - xData[n];
        a = miData.getA(n + 1);
        b = miData.getB(n + 1);
    } else {
        final int low = data.getLowerBoundIndex(value);
        h = yData[low];
        dx = value - xData[low];
        a = miData.getA(low + 1);
        b = miData.getB(low + 1);
    }
    if (Math.abs(b * dx) < 1e-8) {
        return h + a * (dx + b * dx * dx / 2);
    }
    return h + a / b * (Math.exp(b * dx) - 1);

}

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 uniform on (0,1) and 
 * given by $z_i = i/(N-1)$. /*from ww w .jav  a  2s .  co m*/
 * @param lowerBound The value of $x_0$
 * @param upperBound The value of $x_{N-1}$
 * @param nPoints Number of Points (equal to N in the above formula)
 * @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}$
 */
public ExponentialMeshing(final double lowerBound, final double upperBound, final int nPoints,
        final double lambda) {
    super(nPoints);
    Validate.isTrue(upperBound > lowerBound, "need upperBound>lowerBound");
    _l = lowerBound;
    _r = upperBound;
    _lambda = lambda;

    if (lambda == 0.0) {
        _linear = true;
        _theta = lowerBound;
        _eta = (upperBound - lowerBound);
    } else {
        _linear = false;
        _eta = (upperBound - lowerBound) / (Math.exp(lambda) - 1);
        _theta = lowerBound - _eta;
    }
    _um = new UniformMeshing(nPoints);
    _fpValues = null;
}

From source file:hivemall.utils.math.MathUtils.java

public static double lnSigmoid(final double x) {
    double ex = Math.exp(-x);
    return ex / (1.d + ex);
}

From source file:com.opengamma.analytics.financial.model.volatility.curve.FXVannaVolgaVolatilityCurveModel.java

@Override
public VolatilityCurve getCurve(final FXVannaVolgaVolatilityCurveDataBundle marketQuotes,
        final FXOptionDataBundle data) {
    Validate.notNull(marketQuotes);/*from w ww . j a  va 2 s . c om*/
    Validate.notNull(data);
    final double sigmaRR = marketQuotes.getRiskReversal();
    final double sigmaATM = marketQuotes.getAtTheMoney();
    final double sigmaVWB = marketQuotes.getVegaWeightedButterfly();
    final double sigmaDeltaCall = sigmaVWB + sigmaATM + 0.5 * sigmaRR;
    final double sigmaDeltaPut = sigmaDeltaCall - sigmaRR;
    final double t = DateUtils.getDifferenceInYears(data.getDate(), marketQuotes.getMaturity());
    if (t < 0) {
        throw new IllegalArgumentException("Cannot have date after time to maturity");
    }
    final double sqrtT = Math.sqrt(t);
    final double s = data.getSpot();
    final double rd = data.getInterestRate(t);
    final double rf = data.getForeignInterestRate(t);
    final double alpha = -NORMAL.getInverseCDF(Math.exp(rf * t) * marketQuotes.getDelta());
    final double k1 = s
            * Math.exp(-alpha * sigmaDeltaPut * sqrtT + t * (rd - rf + 0.5 * sigmaDeltaPut * sigmaDeltaPut));
    final double k2 = s * Math.exp(t * (rd - rf + 0.5 * sigmaATM * sigmaATM));
    final double k3 = s
            * Math.exp(alpha * sigmaDeltaCall * sqrtT + t * (rd - rf + 0.5 * sigmaDeltaCall * sigmaDeltaCall));
    final double lnk21 = Math.log(k2 / k1);
    final double lnk31 = Math.log(k3 / k1);
    final double lnk32 = Math.log(k3 / k2);
    final double sigma = sigmaATM;
    return new VolatilityCurve(FunctionalDoublesCurve.from(new Function1D<Double, Double>() {

        @SuppressWarnings("synthetic-access")
        @Override
        public Double evaluate(final Double x) {
            Validate.notNull(x);

            final double k = x;
            final double a1 = Math.log(k2 / k) * Math.log(k3 / k) / lnk21 / lnk31;
            final double a2 = Math.log(k / k1) * Math.log(k3 / k) / lnk21 / lnk32;
            final double a3 = Math.log(k / k1) * Math.log(k / k2) / lnk31 / lnk32;
            final double x1 = a1 * sigmaDeltaPut;
            final double x2 = a2 * sigmaATM;
            final double x3 = a3 * sigmaDeltaCall;
            final double e1 = x1 + x2 + x3 - sigma;
            final double d1k1 = getD1(s, k1, t, rd, rf, sigma, sqrtT);
            final double d1k2 = getD1(s, k2, t, rd, rf, sigma, sqrtT);
            final double d1k3 = getD1(s, k3, t, rd, rf, sigma, sqrtT);
            final double x4 = a1 * d1k1 * getD2(d1k1, sigma, sqrtT) * (sigmaDeltaPut - sigma)
                    * (sigmaDeltaPut - sigma);
            final double x5 = a2 * d1k2 * getD2(d1k2, sigma, sqrtT) * (sigmaATM - sigma) * (sigmaATM - sigma);
            final double x6 = a3 * d1k3 * getD2(d1k3, sigma, sqrtT) * (sigmaDeltaCall - sigma)
                    * (sigmaDeltaCall - sigma);
            final double e2 = x4 + x5 + x6;
            final double d1k = getD1(s, k, t, rd, rf, sigma, sqrtT);
            final double d2k = getD2(d1k, sigma, sqrtT);
            return sigma + (-sigma + Math.sqrt(sigma * sigma + d1k * d2k * (2 * sigma * e1 + e2))) / d1k / d2k;
        }

    }));
}

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

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

        @SuppressWarnings("synthetic-access")
        @Override//from  w ww.  ja v  a2  s . co m
        public Double evaluate(final StandardOptionDataBundle data) {
            Validate.notNull(data, "data");
            final ZonedDateTime date = data.getDate();
            final double s = data.getSpot();
            final double t = definition.getTimeToExpiry(date);
            final double start = definition.getTimeToStart(date);
            final double b = data.getCostOfCarry();
            final double r = data.getInterestRate(t); // does this need r at both times?
            final double alpha = definition.getAlpha();
            final double sigma = data.getVolatility(t, alpha * s);
            final double deltaT = t - start;
            final double df1 = Math.exp(start * (b - r));
            final double df2 = Math.exp(deltaT * (b - r));
            final double df3 = Math.exp(-r * deltaT);
            final double sigmaT = sigma * Math.sqrt(deltaT);
            final double d1 = (Math.log(1. / alpha) + deltaT * (b + 0.5 * sigma * sigma)) / sigmaT;
            final double d2 = d1 - sigmaT;
            final int sign = definition.isCall() ? 1 : -1;
            return s * df1 * (sign * (df2 * NORMAL.getCDF(sign * d1) - alpha * df3 * NORMAL.getCDF(sign * d2)));
        }

    };
}

From source file:hivemall.utils.math.StatsUtils.java

/**
 * @return value of probabilistic density function
 *///from w w w .  j  av  a2s.  c  o  m
public static double pdf(final double x, final double x_hat, final double sigma) {
    if (sigma == 0.d) {
        return 0.d;
    }
    double diff = x - x_hat;
    double numerator = Math.exp(-0.5d * diff * diff / sigma);
    double denominator = Math.sqrt(2.d * Math.PI) * Math.sqrt(sigma);
    return numerator / denominator;
}

From source file:it.uniroma2.sag.kelp.kernel.standard.RbfKernel.java

@Override
protected float kernelComputation(Example exA, Example exB) {
    float innerProductOfTheDiff = this.baseKernel.squaredNormOfTheDifference(exA, exB);
    return (float) Math.exp(-gamma * innerProductOfTheDiff);
}