List of usage examples for java.lang Math exp
@HotSpotIntrinsicCandidate public static double exp(double a)
From source file:edu.snu.leader.spatial.calculator.CompactSigmoidSueurDecisionProbabilityCalculator.java
/** * Calculates k coefficient for the collective movement equations * * @param value/*from w ww . j a v a 2s . c om*/ * @return The k coefficient * @see edu.snu.leader.spatial.calculator.AbstractSueurDecisionProbabilityCalculator#calculateK(float) */ @Override protected float calculateK(float value, DecisionType type) { float k = 0.0f; // If it is initiation or following, use a range of [0.1,1.9] if (DecisionType.INITIATE.equals(type) || DecisionType.FOLLOW.equals(type)) { k = 0.1f + (1.8f * (1.0f / (1.0f + (float) Math.exp((0.5f - value) * _sigmoidSlopeValue)))); } // Otherwise, if it is a cancel, use a more compact range else if (DecisionType.CANCEL.equals(type)) { // k = 0.6f + ( 0.8f * ( 1.0f / (1.0f + // (float) Math.exp( (0.5f-value) * _sigmoidSlopeValue) ) ) ); k = 0.59623023f + (0.80753954f * (1.0f / (1.0f + (float) Math.exp((0.5f - value) * _sigmoidSlopeValue)))); } return k; }
From source file:es.udc.gii.common.eaf.benchmark.multiobjective.dtlz2.S_Dtlz2_Objective.java
@Override public double evaluate(double[] x) { int nx = x.length; int i = 0;/*from w w w . j a va 2s . c o m*/ int j = 0; int k = nx - numberOfObjectives + 1; double g = 0; double[] z = new double[nx]; double[] zz = new double[nx]; double[] p = new double[nx]; double[] psum = new double[numberOfObjectives]; // denormalize vector: for (i = 0; i < nx; i++) { x[i] = (bounds[1][i] - bounds[0][i]) / 2 * x[i] + (bounds[1][i] + bounds[0][i]) / 2; } for (i = 0; i < nx; i++) { z[i] = x[i] - o[i]; if (z[i] < 0) { zz[i] = -lambda[i] * z[i]; p[i] = -z[i] / d[i]; } else { zz[i] = z[i]; p[i] = 0; } } for (j = 0; j < numberOfObjectives; j++) { psum[j] = 0; } for (i = nx - k + 1; i <= nx; i++) { g += Math.pow(zz[i - 1] - 0.5, 2); for (j = 0; j < numberOfObjectives; j++) { psum[j] = Math.sqrt(Math.pow(psum[j], 2) + Math.pow(p[i - 1], 2)); } } double ff = (1 + g); for (j = numberOfObjectives - objNumber; j >= 1; j--) { ff *= Math.cos(zz[j - 1] * Math.PI / 2.0); psum[objNumber - 1] = Math.sqrt(Math.pow(psum[objNumber - 1], 2) + Math.pow(p[j - 1], 2)); } if (objNumber > 1) { ff *= Math.sin(zz[(numberOfObjectives - objNumber + 1) - 1] * Math.PI / 2.0); psum[objNumber - 1] = Math.sqrt( Math.pow(psum[objNumber - 1], 2) + Math.pow(p[(numberOfObjectives - objNumber + 1) - 1], 2)); } return 2.0 / (1 + Math.exp(-psum[objNumber - 1])) * (ff + 1); }
From source file:com.opengamma.analytics.financial.model.option.pricing.analytic.HullWhiteStochasticVolatilityModel.java
@Override public Function1D<HullWhiteStochasticVolatilityModelDataBundle, Double> getPricingFunction( final OptionDefinition definition) { Validate.notNull(definition);/*from ww w.j ava 2 s. c o m*/ final Function1D<HullWhiteStochasticVolatilityModelDataBundle, Double> pricingFunction = new Function1D<HullWhiteStochasticVolatilityModelDataBundle, Double>() { @SuppressWarnings("synthetic-access") @Override public Double evaluate(final HullWhiteStochasticVolatilityModelDataBundle 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 sigma = data.getVolatility(t, k); final double r = data.getInterestRate(t); final double b = data.getCostOfCarry(); final double lambda = data.getHalfLife(); final double sigmaLR = data.getLongRunVolatility(); final double volOfSigma = data.getVolatilityOfVolatility(); final double rho = data.getCorrelation(); final StandardOptionDataBundle bsmData = new StandardOptionDataBundle(data); final OptionDefinition call = definition.isCall() ? definition : new EuropeanVanillaOptionDefinition(k, definition.getExpiry(), true); final double beta = -Math.log(2) / lambda; final double alpha = -beta * sigmaLR * sigmaLR; final double delta = beta * t; final double eDelta = Math.exp(delta); final boolean betaIsZero = CompareUtils.closeEquals(beta, 0, ZERO); final double variance = sigma * sigma; final double meanVariance = getMeanVariance(betaIsZero, variance, alpha, t, beta, eDelta, delta); final double df = getDF(r, b, t); final double sDf = s * df; final double d1 = getD(s, k, b, meanVariance, t); final double d2 = d1 - Math.sqrt(meanVariance * t); final double nD1 = NORMAL.getPDF(d1); final double f0 = BSM.getPricingFunction(call).evaluate(bsmData.withVolatilitySurface( new VolatilitySurface(ConstantDoublesSurface.from(Math.sqrt(meanVariance))))); final double f1 = getF1(betaIsZero, variance, rho, alpha, t, beta, delta, eDelta, sDf, nD1, d2, meanVariance); final double f2 = getF2(betaIsZero, variance, rho, alpha, t, beta, delta, eDelta, sDf, nD1, d1, d2, meanVariance); final double callPrice = f0 + f1 * volOfSigma + f2 * volOfSigma * volOfSigma; if (!definition.isCall()) { return callPrice - s * df + k * Math.exp(-r * t); } return callPrice; } }; return pricingFunction; }
From source file:com.opengamma.analytics.financial.model.interestrate.BlackDermanToyYieldOnlyInterestRateModel.java
public Function1D<StandardDiscountBondModelDataBundle, RecombiningBinomialTree<Triple<Double, Double, Double>>> getTrees( final ZonedDateTime time) { Validate.notNull(time, "time"); return new Function1D<StandardDiscountBondModelDataBundle, RecombiningBinomialTree<Triple<Double, Double, Double>>>() { @SuppressWarnings({ "unchecked", "synthetic-access" }) @Override//w w w.j a va 2 s. c o m public RecombiningBinomialTree<Triple<Double, Double, Double>> evaluate( final StandardDiscountBondModelDataBundle data) { Validate.notNull(data, "data"); final double[][] r = new double[_n + 1][_j]; final double[][] q = new double[_n + 1][_j]; final double[][] d = new double[_n + 1][_j]; final double[] u = new double[_n + 1]; final double[] p = new double[_n + 2]; final double t = DateUtils.getDifferenceInYears(data.getDate(), time); final double dt = t / _n; final double dtSqrt = Math.sqrt(dt); final double r1 = data.getShortRate(dt); final double sigma = data.getShortRateVolatility(dt); p[0] = 1.0; for (int i = 1; i <= _n + 1; i++) { p[i] = 1. / Math.pow((1 + data.getShortRate(i) * dt), dt * i); } q[0][0] = 1.; u[0] = r1; r[0][0] = r1; d[0][0] = 1. / (1 + r1 * dt); for (int i = 1; i <= _n; i++) { q[i][0] = 0.5 * q[i - 1][0] * d[i - 1][0]; q[i][i] = 0.5 * q[i - 1][i - 1] * d[i - 1][i - 1]; for (int j = -i + 2, k = 1; j <= i - 2; j += 2, k++) { q[i][k] = 0.5 * (q[i - 1][k - 1] * d[i - 1][k - 1] + q[i - 1][k] * d[i - 1][k]); } u[i] = _rootFinder.getRoot(getMedian(sigma, i, dt, q, p[i + 1]), 0., 1.); for (int j = -i, k = 0; j <= i; j += 2, k++) { r[i][k] = u[i] * Math.exp(sigma * j * dtSqrt); d[i][k] = 1. / (1 + r[i][k] * dt); } } final Triple<Double, Double, Double>[][] result = new Triple[_n + 1][_j]; for (int i = 0; i <= _n; i++) { for (int j = 0; j < _j; j++) { result[i][j] = new Triple<>(r[i][j], d[i][j], q[i][j]); } } return new RecombiningBinomialTree<>(result); } }; }
From source file:FILA.Consumidor.java
private double Exponential(double y, double x) { return y * Math.exp(-y * x); //return 1 - Math.pow(Math.E, -y*x); }
From source file:beast.math.distributions.GammaDistribution.java
/** * probability density function of the Gamma distribution * * @param x argument//from www .j a v a 2 s. com * @param shape shape parameter * @param scale scale parameter * @return pdf value */ public static double pdf(double x, double shape, double scale) { // return Math.pow(scale,-shape)*Math.pow(x, shape-1.0)/ // Math.exp(x/scale + GammaFunction.lnGamma(shape)); if (x < 0) return 0; // to make BEAUti plot continue // throw new IllegalArgumentException(); if (x == 0) { if (shape == 1.0) return 1.0 / scale; else return 0.0; } final double xs = x / scale; if (shape == 1.0) { return Math.exp(-xs) / scale; } final double a = Math.exp((shape - 1.0) * Math.log(xs) - xs - GammaFunction.lnGamma(shape)); return a / scale; }
From source file:es.udc.gii.common.eaf.benchmark.multiobjective.dtlz3.S_Dtlz3_Objective.java
@Override public double evaluate(double[] x) { int nx = x.length; int i = 0;// w w w.ja v a 2 s.c om int j = 0; int k = nx - numberOfObjectives + 1; double g = 0; double[] z = new double[nx]; double[] zz = new double[nx]; double[] p = new double[nx]; double[] psum = new double[numberOfObjectives]; // denormalize vector: for (i = 0; i < nx; i++) { x[i] = (bounds[1][i] - bounds[0][i]) / 2 * x[i] + (bounds[1][i] + bounds[0][i]) / 2; } for (i = 0; i < nx; i++) { z[i] = x[i] - o[i]; if (z[i] < 0) { zz[i] = -lambda[i] * z[i]; p[i] = -z[i] / d[i]; } else { zz[i] = z[i]; p[i] = 0; } } for (j = 0; j < numberOfObjectives; j++) { psum[j] = 0; } for (i = nx - k + 1; i <= nx; i++) { g += Math.pow(zz[i - 1] - 0.5, 2) - Math.cos(20 * Math.PI * (zz[i - 1] - 0.5)); for (j = 0; j < numberOfObjectives; j++) { psum[j] = Math.sqrt(Math.pow(psum[j], 2) + Math.pow(p[i - 1], 2)); } } g = 100 * (k + g); double ff = (1 + g); for (j = numberOfObjectives - objNumber; j >= 1; j--) { ff *= Math.cos(zz[j - 1] * Math.PI / 2.0); psum[objNumber - 1] = Math.sqrt(Math.pow(psum[objNumber - 1], 2) + Math.pow(p[j - 1], 2)); } if (objNumber > 1) { ff *= Math.sin(zz[(numberOfObjectives - objNumber + 1) - 1] * Math.PI / 2.0); psum[objNumber - 1] = Math.sqrt( Math.pow(psum[objNumber - 1], 2) + Math.pow(p[(numberOfObjectives - objNumber + 1) - 1], 2)); } return 2.0 / (1 + Math.exp(-psum[objNumber - 1])) * (ff + 1); }
From source file:edu.illinois.cs.cogcomp.utils.SparseDoubleVector.java
/** * Takes the exponential of each element in the vector. * @return/*from ww w . jav a 2s. c om*/ */ public SparseDoubleVector<TKey> Exp() { SparseDoubleVector<TKey> ret = new SparseDoubleVector<>(); for (TKey k : this.keySet()) { ret.put(k, Math.exp(this.get(k))); } return ret; }
From source file:com.opengamma.analytics.financial.model.option.pricing.analytic.formula.BlackBarrierPriceFunction.java
/** * Computes the price of a barrier option in the Black world. * @param option The underlying European vanilla option. * @param barrier The barrier./*ww w. j av a2 s .c o m*/ * @param rebate The rebate. * @param spot The spot price. * @param costOfCarry The cost of carry. * @param rate The interest rate. * @param sigma The Black volatility. * @return The price. */ public double getPrice(final EuropeanVanillaOption option, final Barrier barrier, final double rebate, final double spot, final double costOfCarry, final double rate, final double sigma) { Validate.notNull(option, "option"); Validate.notNull(barrier, "barrier"); final boolean isKnockIn = (barrier.getKnockType() == KnockType.IN); final boolean isDown = (barrier.getBarrierType() == BarrierType.DOWN); final double h = barrier.getBarrierLevel(); Validate.isTrue(!(barrier.getBarrierType() == BarrierType.DOWN && spot < barrier.getBarrierLevel()), "The Data is not consistent with an alive barrier (DOWN and spot<barrier)."); Validate.isTrue(!(barrier.getBarrierType() == BarrierType.UP && spot > barrier.getBarrierLevel()), "The Data is not consistent with an alive barrier (UP and spot>barrier)."); final boolean isCall = option.isCall(); final double t = option.getTimeToExpiry(); final double strike = option.getStrike(); final int phi = isCall ? 1 : -1; final double eta = isDown ? 1 : -1; final double df1 = Math.exp(t * (costOfCarry - rate)); final double df2 = Math.exp(-rate * t); if (CompareUtils.closeEquals(sigma, 0, 1e-16)) { return df1 * rebate; } final double sigmaSq = sigma * sigma; final double sigmaT = sigma * Math.sqrt(t); final double mu = (costOfCarry - 0.5 * sigmaSq) / sigmaSq; final double lambda = Math.sqrt(mu * mu + 2 * rate / sigmaSq); final double m1 = sigmaT * (1 + mu); final double x1 = Math.log(spot / strike) / sigmaT + m1; final double x2 = Math.log(spot / h) / sigmaT + m1; final double y1 = Math.log(h * h / spot / strike) / sigmaT + m1; final double y2 = Math.log(h / spot) / sigmaT + m1; final double z = Math.log(h / spot) / sigmaT + lambda * sigmaT; final double xA = getA(spot, strike, df1, df2, x1, sigmaT, phi); final double xB = getA(spot, strike, df1, df2, x2, sigmaT, phi); final double xC = getC(spot, strike, df1, df2, y1, sigmaT, h, mu, phi, eta); final double xD = getC(spot, strike, df1, df2, y2, sigmaT, h, mu, phi, eta); final double xE = isKnockIn ? getE(spot, rebate, df2, x2, y2, sigmaT, h, mu, eta) : getF(spot, rebate, z, sigmaT, h, mu, lambda, eta); if (isKnockIn) { if (isDown) { if (isCall) { return strike > h ? xC + xE : xA - xB + xD + xE; } return strike > h ? xB - xC + xD + xE : xA + xE; } if (isCall) { return strike > h ? xA + xE : xB - xC + xD + xE; } return strike > h ? xA - xB + xD + xE : xC + xE; } if (isDown) { if (isCall) { return strike > h ? xA - xC + xE : xB - xD + xE; } return strike > h ? xA - xB + xC - xD + xE : xE; } if (isCall) { return strike > h ? xE : xA - xB + xC - xD + xE; } return strike > h ? xB - xD + xE : xA - xC + xE; }
From source file:com.opengamma.analytics.financial.model.option.pricing.tree.LogNormalBinomialTreeBuilder.java
@Override protected double getNextLowerNode(double dt, double sigma, double forward, double higherNode) { if (forward == 0.0) { return 0.0; }//from ww w . j a v a 2s .com Function1D<Double, Double> func = new LowerNodes(dt, sigma, forward, higherNode); double[] limits = s_bracketRoot.getBracketedPoints(func, forward * Math.exp(-sigma * Math.sqrt(dt)), forward); return s_root.getRoot(func, limits[0], limits[1]); }