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:de.termininistic.serein.examples.benchmarks.functions.multimodal.AckleyFunction.java

@Override
public double map(RealVector v) {
    double[] x = v.toArray();
    int n = x.length;
    double sum1 = 0.0, sum2 = 0.0;

    for (int i = 0; i < n; i++) {
        sum1 += x[i] * x[i];/*  w w  w.  j a  v a2 s  . co m*/
        sum2 += Math.cos(2 * Math.PI * x[i]);
    }
    double fx = -20 * Math.exp(-0.2 * Math.sqrt(sum1 / n)) - Math.exp(sum2 / n) + 20 + Math.E;
    return fx;
}

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

@Override
public double getDiscountFactor(Currency ccy, Double time) {
    if ((ccy == _ccy) && (_time == time)) {
        double rate = -Math.log(super.getDiscountFactor(ccy, time)) / time;
        return Math.exp(-(rate + _shift) * time);
    }//from  w  w w.j  a  va 2 s . co m
    return super.getDiscountFactor(ccy, time);
}

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 Present value of the derivative
 *///from   w ww .  j a  va  2s .co m
@Override
public double presentValue(final EquityFuture future, final EquityFutureDataBundle dataBundle) {
    Validate.notNull(future, "Future");
    Validate.notNull(dataBundle);
    Validate.notNull(dataBundle.getCostOfCarry());
    Validate.notNull(dataBundle.getSpotValue());

    double fwdPrice = dataBundle.getSpotValue()
            * Math.exp(dataBundle.getCostOfCarry() * future.getTimeToSettlement());
    return (fwdPrice - future.getStrike()) * future.getUnitAmount();
}

From source file:com.opengamma.analytics.financial.model.interestrate.curve.DiscountCurve.java

/**
 * Builder of an interpolated discount factor curve from yields (continuously compounded).
 * @param nodePoints The node points for the interpolated curve.
 * @param yields The yields (cc) at the node points.
 * @param interpolator The discount factors interpolator.
 * @param name The curve name./* w ww  .  j  a  v  a  2s  .  co  m*/
 * @return The discount curve.
 */
public static DiscountCurve fromYieldsInterpolated(final double[] nodePoints, final double[] yields,
        final Interpolator1D interpolator, final String name) {
    final int nbYields = yields.length;
    ArgumentChecker.isTrue(nodePoints.length == nbYields, "Yields array of incorrect length");
    final double[] discountFactor = new double[nbYields];
    for (int loopy = 0; loopy < nbYields; loopy++) {
        discountFactor[loopy] = Math.exp(-nodePoints[loopy] * yields[loopy]);
    }
    final InterpolatedDoublesCurve curve = new InterpolatedDoublesCurve(nodePoints, discountFactor,
            interpolator, false);
    return new DiscountCurve(name, curve);
}

From source file:com.opengamma.analytics.financial.model.interestrate.VasicekInterestRateModel.java

@Override
public Function1D<VasicekDataBundle, Double> getDiscountBondFunction(final ZonedDateTime time,
        final ZonedDateTime maturity) {
    Validate.notNull(time);/*from   w w w . j  a v  a  2 s  .  c  o m*/
    Validate.notNull(maturity);
    return new Function1D<VasicekDataBundle, Double>() {

        @Override
        public Double evaluate(final VasicekDataBundle data) {
            Validate.notNull(data);
            final double lt = data.getLongTermInterestRate();
            final double speed = data.getReversionSpeed();
            final double dt = DateUtils.getDifferenceInYears(time, maturity);
            final double t = DateUtils.getDifferenceInYears(data.getDate(), time);
            final double sigma = data.getShortRateVolatility(t);
            final double r = data.getShortRate(t);
            final double sigmaSq = sigma * sigma;
            final double speedSq = speed * speed;
            final double rInfinity = lt - 0.5 * sigmaSq / speedSq;
            final double factor = 1 - Math.exp(-speed * dt);
            final double a = rInfinity * (factor / speed - dt)
                    - sigmaSq * factor * factor / (4 * speedSq * speed);
            final double b = factor / speed;
            return Math.exp(a - r * b);
        }

    };
}

From source file:com.github.tteofili.looseen.yay.SoftmaxActivationFunction.java

public RealMatrix applyMatrix(RealMatrix weights) {
    RealMatrix matrix = weights.copy();//from  w  w  w .  j  av  a2s .co  m
    final double finalD = expDen(matrix);
    matrix.walkInOptimizedOrder(new RealMatrixChangingVisitor() {
        @Override
        public void start(int rows, int columns, int startRow, int endRow, int startColumn, int endColumn) {

        }

        @Override
        public double visit(int row, int column, double value) {
            return Math.exp(value) / finalD;
        }

        @Override
        public double end() {
            return 0;
        }
    });
    return matrix;
}

From source file:com.opengamma.analytics.financial.model.volatility.surface.SABRATMVolatilityCalibrationFunction.java

public SABRDataBundle calibrate(final OptionDefinition option, final SABRDataBundle data) {
    Validate.notNull(option, "option");
    Validate.notNull(data, "data");
    final double beta = data.getBeta();
    final double t = option.getTimeToExpiry(data.getDate());
    final double rho = data.getRho();
    final double ksi = data.getVolOfVol();
    final double sigmaATM = data.getVolatility(t, option.getStrike());
    final double b = data.getCostOfCarry();
    final double f = data.getSpot() * Math.exp(b * t);
    final double beta1 = 1 - beta;
    final double f1 = Math.pow(f, beta1);
    final double a0 = -sigmaATM * f1;
    final double a1 = 1 + (2 - 3 * rho * rho) * ksi * ksi * t / 24;
    final double a2 = rho * beta * ksi * t / 4 / f1;
    final double a3 = beta1 * beta1 * t / 24 / f1 / f1;
    Double[] roots;//from  w  w w . j  a va2  s.com
    if (CompareUtils.closeEquals(a3, 0, 1e-16)) {
        roots = QUADRATIC_FINDER.getRoots(new RealPolynomialFunction1D(new double[] { a0, a1, a2 }));
    } else {
        roots = ROOT_FINDER.getRoots(new RealPolynomialFunction1D(new double[] { a0, a1, a2, a3 }));
    }
    Arrays.sort(roots);
    if (roots[0] > 0) {
        return data.withAlpha(roots[0]);
    }
    for (final Double r : roots) {
        if (r > 0) {
            return data.withAlpha(r);
        }
    }
    throw new MathException("Could not find positive real root");
}

From source file:com.opengamma.analytics.financial.interestrate.ContinuousInterestRate.java

@Override
public PeriodicInterestRate toPeriodic(final int periodsPerYear) {
    ArgumentChecker.notNegativeOrZero(periodsPerYear, "compounding periods per year");
    return new PeriodicInterestRate(periodsPerYear * (Math.exp(getRate() / periodsPerYear) - 1),
            periodsPerYear);/*  ww  w. ja  va  2  s  .  c  om*/
}

From source file:es.udc.gii.common.eaf.benchmark.multiobjective.fon.Fon_Objective_2.java

@Override
public double evaluate(double[] values) {
    double[] x = new double[values.length];
    double sum = 0;
    double k = 1 / Math.sqrt(values.length);

    for (int i = 0; i < values.length; i++) {
        x[i] = 4 * values[i];/*from   w ww  .j  av  a 2 s .  c o  m*/
        sum += (x[i] + k) * (x[i] + k);
    }

    return 1 - Math.exp(-sum);
}

From source file:com.opengamma.analytics.financial.simpleinstruments.pricing.SimpleFXFuturePresentValueCalculator.java

@Override
public CurrencyAmount visitSimpleFXFuture(final SimpleFXFuture future, final SimpleFXFutureDataBundle data) {
    final double t = future.getExpiry();
    final double payRate = data.getPayCurve().getInterestRate(t);
    final double receiveRate = data.getReceiveCurve().getInterestRate(t);
    return CurrencyAmount.of(future.getReceiveCurrency(),
            future.getUnitAmount() * data.getSpot() * Math.exp(t * (receiveRate - payRate)));
}