List of usage examples for java.lang Math exp
@HotSpotIntrinsicCandidate public static double exp(double a)
From source file:com.opengamma.analytics.financial.model.option.pricing.analytic.ModifiedCorradoSuSkewnessKurtosisModel.java
@Override public Function1D<SkewKurtosisOptionDataBundle, Double> getPricingFunction(final OptionDefinition definition) { Validate.notNull(definition);/*w ww . j av a2 s .c om*/ final Function1D<SkewKurtosisOptionDataBundle, Double> pricingFunction = new Function1D<SkewKurtosisOptionDataBundle, Double>() { @SuppressWarnings("synthetic-access") @Override public Double evaluate(final SkewKurtosisOptionDataBundle data) { Validate.notNull(data); final double s = data.getSpot(); final double k = definition.getStrike(); final double t = definition.getTimeToExpiry(data.getDate()); final double sigma = data.getVolatility(t, k); final double r = data.getInterestRate(t); final double b = data.getCostOfCarry(); final double skew = data.getAnnualizedSkew(); final double kurtosis = data.getAnnualizedFisherKurtosis(); final double sigmaT = sigma * Math.sqrt(t); OptionDefinition callDefinition = definition; if (!definition.isCall()) { callDefinition = new EuropeanVanillaOptionDefinition(callDefinition.getStrike(), callDefinition.getExpiry(), true); } final Function1D<StandardOptionDataBundle, Double> bsm = BSM.getPricingFunction(callDefinition); final double bsmCall = bsm.evaluate(data); final double w = getW(sigma, t, skew, kurtosis); final double d = getD(s, k, sigma, t, b, w, sigmaT); final double call = bsmCall + skew * getQ3(s, d, w, sigmaT) + kurtosis * getQ4(s, d, w, sigmaT); if (!definition.isCall()) { return call - s * Math.exp((b - r) * t) + k * Math.exp(-r * t); } return call; } }; return pricingFunction; }
From source file:com.opengamma.analytics.financial.model.option.pricing.analytic.BatesGeneralizedJumpDiffusionModel.java
/** * {@inheritDoc}//from ww w .j av a2 s .c om */ @Override public Function1D<BatesGeneralizedJumpDiffusionModelDataBundle, Double> getPricingFunction( final OptionDefinition definition) { Validate.notNull(definition); final Function1D<BatesGeneralizedJumpDiffusionModelDataBundle, Double> pricingFunction = new Function1D<BatesGeneralizedJumpDiffusionModelDataBundle, Double>() { @SuppressWarnings("synthetic-access") @Override public Double evaluate(final BatesGeneralizedJumpDiffusionModelDataBundle data) { Validate.notNull(data); final double s = data.getSpot(); final YieldAndDiscountCurve discountCurve = data.getInterestRateCurve(); final VolatilitySurface volSurface = data.getVolatilitySurface(); final ZonedDateTime date = data.getDate(); final double t = definition.getTimeToExpiry(date); final double k = definition.getStrike(); final double sigma = data.getVolatility(t, k); double b = data.getCostOfCarry(); final double lambda = data.getLambda(); final double expectedJumpSize = data.getExpectedJumpSize(); final double delta = data.getDelta(); final double gamma = Math.log(1 + expectedJumpSize); final double sigmaSq = sigma * sigma; double z; final double lambdaT = lambda * t; double mult = Math.exp(-lambdaT); b -= lambda * expectedJumpSize; StandardOptionDataBundle bsmData = new StandardOptionDataBundle(discountCurve, b, volSurface, s, date); final Function1D<StandardOptionDataBundle, Double> bsmFunction = BSM.getPricingFunction(definition); double price = mult * bsmFunction.evaluate(bsmData); for (int i = 1; i < N; i++) { z = Math.sqrt(sigmaSq + delta * delta * i / t); b += gamma / t; bsmData = bsmData.withVolatilitySurface(new VolatilitySurface(ConstantDoublesSurface.from(z))) .withCostOfCarry(b); mult *= lambdaT / i; price += mult * bsmFunction.evaluate(bsmData); } return price; } }; return pricingFunction; }
From source file:com.itemanalysis.psychometrics.irt.model.Irm4PL.java
private double probRight(double theta, double[] iparam, double D) { if (iparam[0] < 0) return 0; double z = Math.exp(D * iparam[0] * (theta - iparam[1])); return iparam[2] + (iparam[3] - iparam[2]) * z / (1 + z); }
From source file:hivemall.utils.math.StatsUtils.java
/** * pdf(x, x_hat) = exp(-0.5 * (x-x_hat) * inv() * (x-x_hat)T) / ( 2^0.5d * det()^0.5) * //from w ww. j a v a 2 s . com * @return value of probabilistic density function * @link https://en.wikipedia.org/wiki/Multivariate_normal_distribution#Density_function */ public static double pdf(@Nonnull final RealVector x, @Nonnull final RealVector x_hat, @Nonnull final RealMatrix sigma) { final int dim = x.getDimension(); Preconditions.checkArgument(x_hat.getDimension() == dim, "|x| != |x_hat|, |x|=" + dim + ", |x_hat|=" + x_hat.getDimension()); Preconditions.checkArgument(sigma.getRowDimension() == dim, "|x| != |sigma|, |x|=" + dim + ", |sigma|=" + sigma.getRowDimension()); Preconditions.checkArgument(sigma.isSquare(), "Sigma is not square matrix"); LUDecomposition LU = new LUDecomposition(sigma); final double detSigma = LU.getDeterminant(); double denominator = Math.pow(2.d * Math.PI, 0.5d * dim) * Math.pow(detSigma, 0.5d); if (denominator == 0.d) { // avoid divide by zero return 0.d; } final RealMatrix invSigma; DecompositionSolver solver = LU.getSolver(); if (solver.isNonSingular() == false) { SingularValueDecomposition svd = new SingularValueDecomposition(sigma); invSigma = svd.getSolver().getInverse(); // least square solution } else { invSigma = solver.getInverse(); } //EigenDecomposition eigen = new EigenDecomposition(sigma); //double detSigma = eigen.getDeterminant(); //RealMatrix invSigma = eigen.getSolver().getInverse(); RealVector diff = x.subtract(x_hat); RealVector premultiplied = invSigma.preMultiply(diff); double sum = premultiplied.dotProduct(diff); double numerator = Math.exp(-0.5d * sum); return numerator / denominator; }
From source file:com.opengamma.analytics.financial.interestrate.inflation.method.InflationMarketModelConvexityAdjustmentForCapFloor.java
/** * Computes the convexity adjustment for year on year inflation swap with a monthly index. * @param coupon The year on year coupon. * @param inflationConvexity The inflation provider. * @return The convexity adjustment./*from ww w.j a v a 2s . c o m*/ */ public double getYearOnYearConvexityAdjustment(final CapFloorInflationYearOnYearMonthly coupon, final BlackSmileCapInflationYearOnYearWithConvexityProviderInterface inflationConvexity) { Validate.notNull(coupon, "Coupon"); Validate.notNull(inflationConvexity, "Inflation"); final double firstFixingTime = coupon.getReferenceStartTime(); final double secondFixingTime = coupon.getReferenceEndTime(); final double firstNaturalPaymentTime = coupon.getNaturalPaymentStartTime(); final double secondNaturalPaymentTime = coupon.getNaturalPaymentEndTime(); final double paymentTime = coupon.getPaymentTime(); final double volatilityStart = inflationConvexity.getInflationConvexityAdjustmentParameters() .getPriceIndexAtmVolatility()[0]; final double volatilityEnd = inflationConvexity.getInflationConvexityAdjustmentParameters() .getPriceIndexAtmVolatility()[1]; final double correlationInflation = inflationConvexity.getInflationConvexityAdjustmentParameters() .getPriceIndexCorrelation().getZValue(firstFixingTime, secondFixingTime); final double correlationInflationRateStart = inflationConvexity.getInflationConvexityAdjustmentParameters() .getPriceIndexRateCorrelation().getYValue(firstFixingTime); final double correlationInflationRateEnd = inflationConvexity.getInflationConvexityAdjustmentParameters() .getPriceIndexRateCorrelation().getYValue(secondFixingTime); final double volBondForwardStart = getVolBondForward(firstNaturalPaymentTime, paymentTime, inflationConvexity); final double volBondForwardEnd = getVolBondForward(secondNaturalPaymentTime, paymentTime, inflationConvexity); final double adjustment = volatilityStart * (volatilityStart - volatilityEnd * correlationInflation - volBondForwardStart * correlationInflationRateStart) * firstNaturalPaymentTime + volatilityEnd * volBondForwardEnd * correlationInflationRateEnd * secondNaturalPaymentTime; return Math.exp(adjustment); }
From source file:com.opengamma.strata.math.impl.statistics.distribution.NonCentralChiSquaredDistribution.java
/** * {@inheritDoc}// w w w .j a va 2 s . c o m */ @Override public double getCDF(Double x) { ArgChecker.notNull(x, "x"); if (x < 0) { return 0.0; } if ((_dofOverTwo + _lambdaOverTwo) > 1000) { return getFraserApproxCDF(x); } double regGammaStart = 0; double halfX = x / 2.0; double logX = Math.log(halfX); try { regGammaStart = Gamma.regularizedGammaP(_dofOverTwo + _k, halfX); } catch (MaxCountExceededException ex) { throw new MathException(ex); } double sum = _pStart * regGammaStart; double oldSum = Double.NEGATIVE_INFINITY; double p = _pStart; double regGamma = regGammaStart; double temp; int i = _k; // first add terms below _k while (i > 0 && Math.abs(sum - oldSum) / sum > _eps) { i--; p *= (i + 1) / _lambdaOverTwo; temp = (_dofOverTwo + i) * logX - halfX - Gamma.logGamma(_dofOverTwo + i + 1); regGamma += Math.exp(temp); oldSum = sum; sum += p * regGamma; } p = _pStart; regGamma = regGammaStart; oldSum = Double.NEGATIVE_INFINITY; i = _k; while (Math.abs(sum - oldSum) / sum > _eps) { i++; p *= _lambdaOverTwo / i; temp = (_dofOverTwo + i - 1) * logX - halfX - Gamma.logGamma(_dofOverTwo + i); regGamma -= Math.exp(temp); oldSum = sum; sum += p * regGamma; } return sum; }
From source file:edu.stanford.cfuller.imageanalysistools.fitting.GaussianFitter3DWithCovariance.java
private static double gaussian(double x, double y, double z, double[] parameters) { double xmx0 = x - parameters[7]; double ymy0 = y - parameters[8]; double zmz0 = z - parameters[9]; double v1 = parameters[1]; double v2 = parameters[2]; double v3 = parameters[3]; double r12 = parameters[4]; double r13 = parameters[5]; double r23 = parameters[6]; double A = parameters[0]; double b = parameters[10]; double denom = 2 * r12 * r13 * r23 - r23 * r23 * v1 - r13 * r13 * v2 - r12 * r12 * v3 + v1 * v2 * v3; double term0 = -0.5 * (zmz0) * (ymy0 * (r12 * r13 - r23 * v1) / denom + xmx0 * (r12 * r23 - r13 * v2) / denom + zmz0 * (-r12 * r12 + v1 * v2) / denom); double term1 = -0.5 * (ymy0) * (zmz0 * (r12 * r13 - r23 * v1) / denom + xmx0 * (r13 * r23 - r12 * v3) / denom + ymy0 * (-r13 * r13 + v1 * v3) / denom); double term2 = -0.5 * (xmx0) * (zmz0 * (r12 * r23 - r13 * v2) / denom + ymy0 * (r13 * r23 - r12 * v3) / denom + xmx0 * (-r23 * r23 + v2 * v3) / denom); return (A * Math.exp(term0 + term1 + term2) + b); }
From source file:com.opengamma.analytics.math.statistics.distribution.NonCentralChiSquaredDistribution.java
/** * {@inheritDoc}//from w w w . j a v a2 s. co m */ @Override public double getCDF(final Double x) { Validate.notNull(x, "x"); if (x < 0) { return 0.0; } if ((_dofOverTwo + _lambdaOverTwo) > 1000) { return getFraserApproxCDF(x); } double regGammaStart = 0; final double halfX = x / 2.0; final double logX = Math.log(halfX); try { regGammaStart = Gamma.regularizedGammaP(_dofOverTwo + _k, halfX); } catch (final org.apache.commons.math.MathException ex) { throw new MathException(ex); } double sum = _pStart * regGammaStart; double oldSum = Double.NEGATIVE_INFINITY; double p = _pStart; double regGamma = regGammaStart; double temp; int i = _k; // first add terms below _k while (i > 0 && Math.abs(sum - oldSum) / sum > _eps) { i--; p *= (i + 1) / _lambdaOverTwo; temp = (_dofOverTwo + i) * logX - halfX - Gamma.logGamma(_dofOverTwo + i + 1); regGamma += Math.exp(temp); oldSum = sum; sum += p * regGamma; } p = _pStart; regGamma = regGammaStart; oldSum = Double.NEGATIVE_INFINITY; i = _k; while (Math.abs(sum - oldSum) / sum > _eps) { i++; p *= _lambdaOverTwo / i; temp = (_dofOverTwo + i - 1) * logX - halfX - Gamma.logGamma(_dofOverTwo + i); regGamma -= Math.exp(temp); oldSum = sum; sum += p * regGamma; } return sum; }
From source file:com.nextbreakpoint.nextfractal.mandelbrot.core.Expression.java
public static double funcExp(double x) { return Math.exp(x); }
From source file:com.opengamma.analytics.financial.model.option.pricing.analytic.JarrowRuddSkewnessKurtosisModel.java
/** * {@inheritDoc}//from w ww . ja v a 2 s . com */ @Override public Function1D<SkewKurtosisOptionDataBundle, Double> getPricingFunction(final OptionDefinition definition) { Validate.notNull(definition); final Function1D<SkewKurtosisOptionDataBundle, Double> pricingFunction = new Function1D<SkewKurtosisOptionDataBundle, Double>() { @SuppressWarnings("synthetic-access") @Override public Double evaluate(final SkewKurtosisOptionDataBundle data) { Validate.notNull(data); final double s = data.getSpot(); final double k = definition.getStrike(); final double t = definition.getTimeToExpiry(data.getDate()); final double sigma = data.getVolatility(t, k); final double r = data.getInterestRate(t); final double b = data.getCostOfCarry(); final double skew = data.getAnnualizedSkew(); final double kurtosis = data.getAnnualizedPearsonKurtosis(); final OptionDefinition callDefinition = definition.isCall() ? definition : new EuropeanVanillaOptionDefinition(k, definition.getExpiry(), true); final Function1D<StandardOptionDataBundle, Double> bsm = BSM.getPricingFunction(callDefinition); final double bsmCall = bsm.evaluate(data); final double d2 = getD2(getD1(s, k, t, sigma, b), sigma, t); final double sigmaT = sigma * Math.sqrt(t); final double a = getA(d2, k, sigmaT); final double call = bsmCall + getLambda1(sigma, t, skew) * getQ3(s, k, sigmaT, t, r, a, d2) + getLambda2(sigma, t, kurtosis) * getQ4(s, k, sigmaT, t, r, a, d2); if (!definition.isCall()) { return call - s * Math.exp((b - r) * t) + k * Math.exp(-r * t); } return call; } }; return pricingFunction; }