List of usage examples for java.lang Math exp
@HotSpotIntrinsicCandidate public static double exp(double a)
From source file:com.opengamma.strata.math.impl.statistics.distribution.NonCentralChiSquaredDistribution.java
/** * @param degrees The number of degrees of freedom, not negative or zero * @param nonCentrality The non-centrality parameter, not negative */// w w w . j a va 2 s. c om public NonCentralChiSquaredDistribution(double degrees, double nonCentrality) { ArgChecker.isTrue(degrees > 0, "degrees of freedom must be > 0, have " + degrees); ArgChecker.isTrue(nonCentrality >= 0, "non-centrality must be >= 0, have " + nonCentrality); _dofOverTwo = degrees / 2.0; _lambdaOverTwo = nonCentrality / 2.0; _k = (int) Math.round(_lambdaOverTwo); if (_lambdaOverTwo == 0) { _pStart = 0.0; } else { double logP = -_lambdaOverTwo + _k * Math.log(_lambdaOverTwo) - Gamma.logGamma(_k + 1); _pStart = Math.exp(logP); } }
From source file:com.opengamma.analytics.math.minimization.SingleRangeLimitTransform.java
/** * {@inheritDoc}//ww w .j a v a2s .com * @throws IllegalArgumentException If the value of $x$ is not consistent with the limit (e.g. the limit is $x > a$ and $x$ is * less than $a$ */ @Override public double transform(final double x) { Validate.isTrue(_sign * x >= _sign * _limit, "x not in limit"); if (x == _limit) { return -EXP_MAX; } final double r = _sign * (x - _limit); if (r > EXP_MAX) { return r; } return Math.log(Math.exp(r) - 1); }
From source file:edu.scripps.fl.curves.CurveFit.java
public static void fit(Curve curve) { log.debug("Fitting Curve: " + curve); double y[] = (double[]) ConvertUtils.convert(curve.getResponses(), double[].class); double x[] = (double[]) ConvertUtils.convert(curve.getConcentrations(), double[].class); for (int ii = 0; ii < x.length; ii++) x[ii] = Math.log10(x[ii]); // max, min and range double minY = Double.MAX_VALUE; double maxY = -Double.MAX_VALUE; double maxResp = y[y.length - 1]; for (int i = 0; i < y.length; i++) { minY = Math.min(minY, y[i]); maxY = Math.max(maxY, y[i]); }/*from w ww .j a va 2s. c o m*/ curve.setResponseMin(minY); curve.setResponseMax(maxY); curve.setResponseRange(maxY - minY); curve.setMaxResponse(maxResp); // fit boolean flags[] = null; Map maps[] = null; double fitValues[] = null; Object fitResults[] = HillFit.doHill(x, y, null, HillConstants.FIT_ITER_NO, HillConstants.P4_FIT); if (fitResults != null) { flags = (boolean[]) fitResults[0]; fitValues = (double[]) fitResults[1]; maps = (Map[]) fitResults[2]; } if (fitValues != null) { curve.setYZero(fitValues[6]); curve.setLogEC50(fitValues[0]); curve.setYInflection(fitValues[1]); curve.setHillSlope(fitValues[2]); curve.setR2(fitValues[3]); double ec50 = 1000000D * Math.exp(Math.log(10D) * curve.getLogEC50()); double testEC50 = Math.pow(10, curve.getLogEC50()); Double ic50 = null; double logIC50 = BatchHill.iccalc(curve.getYZero(), curve.getYInflection(), curve.getLogEC50(), curve.getHillSlope(), 50D); if (logIC50 < 0.0D) ic50 = 1000000D * Math.exp(Math.log(10D) * logIC50); int dn = Math.max(1, x.length - 4); double df = dn; double p = HillStat.calcPValue(curve.getYZero(), curve.getYInflection(), curve.getLogEC50(), curve.getHillSlope(), x, y, flags); int mask = 0; for (int i = 0; i < x.length; i++) if (!flags[i]) mask++; double ss = HillStat.calcHillDeviation(curve.getLogEC50(), curve.getYZero(), curve.getYInflection(), curve.getHillSlope(), flags, null, x, y); curve.setEC50(ec50); curve.setIC50(ic50); curve.setPHill(p); curve.setSYX(ss / df); for (int ii = 0; ii < flags.length; ii++) { if (flags[ii] == true) { curve.setMasked(true); break; } } } else { curve.setLogEC50(null); curve.setHillSlope(null); curve.setR2(null); curve.setYInflection(null); curve.setYZero(null); curve.setEC50(null); curve.setIC50(null); curve.setPHill(null); curve.setSYX(null); curve.setMasked(false); flags = new boolean[x.length]; } // masks List<Boolean> masks = new ArrayList<Boolean>(flags.length); CollectionUtils.addAll(masks, (Boolean[]) ConvertUtils.convert(flags, Boolean[].class)); curve.setMask(masks); // classify curveClassification(curve, y, x, flags); // rank double rank = -BatchHill.calcRank(curve.getCurveClass(), curve.getMaxResponse(), curve.getResponseRange()); curve.setRank(rank); }
From source file:com.opengamma.analytics.financial.model.interestrate.HullWhiteTwoFactorInterestRateModel.java
protected Double getC(final Double dt, final Double a, final Double b) { return Math.exp(-a * dt) / (a * (a - b)) - Math.exp(-b * dt) / (b * (a - b)) + 1. / (a * b); }
From source file:com.opengamma.analytics.math.ComplexMathUtils.java
public static ComplexNumber exp(final ComplexNumber z) { ArgumentChecker.notNull(z, "z"); final double mult = Math.exp(z.getReal()); return new ComplexNumber(mult * Math.cos(z.getImaginary()), mult * Math.sin(z.getImaginary())); }
From source file:com.gordoni.opal.UtilityJoinAra.java
public double slope(double c) { assert (c >= 0); if (c < c1) return utility1.slope(c); else if (c >= c2) return utility2.slope(c); else//from w w w.j ava 2s. c o m return scale * Math.sqrt(a / 2) * Math.exp(-Math.pow(a * c + b, 2) / (2 * a)); }
From source file:com.opengamma.analytics.financial.model.option.pricing.analytic.ExtremeSpreadOptionModel.java
@Override public Function1D<StandardOptionWithSpotTimeSeriesDataBundle, Double> getPricingFunction( final ExtremeSpreadOptionDefinition definition) { Validate.notNull(definition, "definition"); return new Function1D<StandardOptionWithSpotTimeSeriesDataBundle, Double>() { @SuppressWarnings("synthetic-access") @Override/* w w w . ja va2s.c om*/ public Double evaluate(final StandardOptionWithSpotTimeSeriesDataBundle data) { Validate.notNull(data, "data"); final double s = data.getSpot(); final double b = data.getCostOfCarry(); final ZonedDateTime date = data.getDate(); final double t1 = -definition.getTimeFromPeriodEnd(date); final double t2 = definition.getTimeToExpiry(date); final double r = data.getInterestRate(t2); final DoubleTimeSeries<?> ts = data.getSpotTimeSeries(); final int eta = definition.isCall() ? 1 : -1; final int phi = definition.isReverse() ? -1 : 1; final double x = eta * phi == 1 ? ts.maxValue() : ts.minValue(); final double sigma = data.getVolatility(t2, x); //REVIEW emcleod 21-7-10 works for flat vol surfaces final double m = Math.log(x / s); final double mu1 = b - sigma * sigma / 2; final double mu2 = b + sigma * sigma / 2; final double df1 = Math.exp(t2 * (b - r)); final double df2 = Math.exp(b * (t1 - t2)); final double df3 = Math.exp(-r * t2); final double sigmaT2 = sigma * Math.sqrt(t2); final double sigmaT1 = sigma * Math.sqrt(t1); final double sigmaSq = sigma * sigma; final double y = sigmaSq / 2 / b; if (definition.isReverse()) { final double dt = t2 - t1; final double sigmaDT = sigma * Math.sqrt(dt); final double z1 = s * df1 * (1 + y) * NORMAL.getCDF(eta * (m - mu2 * t2) / sigmaT2); final double z2 = df3 * x * NORMAL.getCDF(eta * (mu1 * t2 - m) / sigmaT2); final double z3 = -df3 * x * y * Math.exp(2 * mu1 * m / sigmaSq) * NORMAL.getCDF(eta * (m + mu1 * t2) / sigmaT2); final double z4 = -s * df1 * (1 + y) * NORMAL.getCDF(-eta * mu2 * dt / sigmaDT); final double z5 = -df2 * df1 * s * (1 - y) * NORMAL.getCDF(eta * mu1 * dt / sigmaDT); return -eta * (z1 + z2 + z3 + z4 + z5); } final double z1 = s * df1 * (1 + y) * NORMAL.getCDF(eta * (mu2 * t2 - m) / sigmaT2); final double z2 = -df2 * df1 * s * (1 + y) * NORMAL.getCDF(eta * (mu2 * t1 - m) / sigmaT1); final double z3 = df3 * x * NORMAL.getCDF(eta * (m - mu1 * t2) / sigmaT2); final double z4 = -df3 * x * y * Math.exp(2 * mu1 * m / sigmaSq) * NORMAL.getCDF(-eta * (m + mu1 * t2) / sigmaT2); final double z5 = -df3 * x * NORMAL.getCDF(eta * (m - mu1 * t1) / sigmaT1); final double z6 = df3 * x * y * Math.exp(2 * mu1 * m / sigmaSq) * NORMAL.getCDF(-eta * (m + mu1 * t1) / sigmaT1); return eta * (z1 + z2 + z3 + z4 + z5 + z6); } }; }
From source file:com.opengamma.analytics.financial.model.option.pricing.analytic.GapOptionModel.java
/** * {@inheritDoc}//from ww w . j a v a 2 s . c o m */ @Override public Function1D<StandardOptionDataBundle, Double> getPricingFunction(final GapOptionDefinition 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 payoffStrike = definition.getPayoffStrike(); final int sign = definition.isCall() ? 1 : -1; final double d1 = getD1(s, k, t, sigma, b); final double d2 = getD2(d1, sigma, t); return sign * (s * Math.exp(t * (b - r)) * NORMAL.getCDF(sign * d1) - payoffStrike * Math.exp(-r * t) * NORMAL.getCDF(sign * d2)); } }; }
From source file:it.unibo.alchemist.modelchecker.AlchemistASMC.java
/** * Given the approximation and the number of runs to execute, computes a * lower bound for confidence (see manual). * /*from w w w . j a v a 2s. c o m*/ * @param delta * approximation * @param n * number of runs * @return confidence */ public static double computeAlphaUB(final double delta, final int n) { return 2 * Math.exp(-delta * delta * n / LOG_MUL); }
From source file:com.opengamma.analytics.math.minimization.DoubleRangeLimitTransform.java
/** * If $|y| > 25$, this returns 0.//from ww w .j ava2 s.com * {@inheritDoc} */ @Override public double inverseTransformGradient(final double y) { if (y > TANH_MAX || y < -TANH_MAX) { return 0.0; } final double p = 2 * y; final double ep = Math.exp(p); final double epp1 = ep + 1; return _scale * 4 * ep / (epp1 * epp1); }