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.tree.LogNormalBinomialTreeBuilder.java
@Override protected double getNextHigherNode(double dt, double sigma, double forward, double lowerNode) { Function1D<Double, Double> func = new UpperNodes(dt, sigma, forward, lowerNode); double fTry = forward * Math.exp(sigma * Math.sqrt(dt)); //ensure we do not get p = 1 and thus a divide by zero double[] limits = s_bracketRoot.getBracketedPoints(func, (forward - lowerNode) / 0.6 + lowerNode, (forward - lowerNode) / 0.4 + lowerNode, forward * (1 + EPS), 10 * fTry); return s_root.getRoot(func, limits[0], limits[1]); }
From source file:com.qaant.threadModels.TBlackScholes.java
private void opcionConVida() { tipoEjercicio = EUROPEAN;/*from ww w. j a va 2s . co m*/ double q = (tipoContrato == STOCK) ? dividendRate : rate; //q: si es una accion q es el dividendo, si es un futuro q se toma la rate para descontar el valor futr a presente //Se hace este reemplazo para poder usar la misma form en STOCK y FUTURO //drift=Math.exp((q-rate)*dayYear); double drift = (tipoContrato == 'F') ? z : 1; double x = (tipoContrato == 'F') ? 1 : 0; double d1 = (Math.log(underlyingNPV / strike) + dayYear * (rate - q + volatModel * volatModel / 2)) / (volatModel * sqrDayYear); double d2 = d1 - volatModel * sqrDayYear; double CNDFd1 = new NormalDistribution().cumulativeProbability(d1); double CNDFd2 = new NormalDistribution().cumulativeProbability(d2); double PDFd1 = new NormalDistribution().density(d1); //gamma y vega son iguales para call y put gamma = PDFd1 * drift / (underlyingNPV * volatModel * sqrDayYear); vega = underlyingNPV * drift * sqrDayYear * PDFd1 / 100; switch (callPut) { case CALL: prima = underlyingValue * Math.exp(-q * dayYear) * CNDFd1 - z * strike * CNDFd2; delta = Math.exp(-q * dayYear) * CNDFd1; theta = (-(underlyingNPV * drift * volatModel * PDFd1 / (2 * sqrDayYear)) - strike * 1 * rate * CNDFd2) / (365); rho = z * dayYear * (strike * CNDFd2 - x * underlyingNPV * CNDFd1) / 100; break; case PUT: double CNDF_d1 = new NormalDistribution().cumulativeProbability(-d1); double CNDF_d2 = new NormalDistribution().cumulativeProbability(-d2); prima = -underlyingValue * Math.exp(-q * dayYear) * CNDF_d1 + z * strike * CNDF_d2; delta = Math.exp(-q * dayYear) * (CNDFd1 - 1); theta = (-(underlyingNPV * drift * volatModel * PDFd1 / (2 * sqrDayYear)) + strike * 1 * rate * CNDF_d2) / 365; rho = -z * dayYear * (strike * CNDF_d2 - x * underlyingNPV * CNDF_d1) / 100; break; default: prima = delta = gamma = theta = rho = 0; break; }//end switch }
From source file:edu.jhu.hlt.parma.inference.transducers.UnigramLM.java
private double katzEstimate(Counter<Integer> cnt, double c, double[] coeffs) { double nC = cnt.getCount((int) c); double nC1 = cnt.getCount(((int) c) + 1); if (nC1 == 0.0) nC1 = Math.exp(coeffs[0] + (coeffs[1] * (c + 1.0))); double n1 = cnt.getCount(1); double nK1 = cnt.getCount(((int) kCutoff) + 1); if (nK1 == 0.0) nK1 = Math.exp(coeffs[0] + (coeffs[1] * (kCutoff + 1.0))); double kTerm = (kCutoff + 1.0) * (nK1 / n1); double cTerm = (c + 1.0) * (nC1 / nC); double cSmooth = (cTerm - (c * kTerm)) / (1.0 - kTerm); return cSmooth; }
From source file:net.sf.jdmf.util.MathCalculator.java
/** * Calculates the normal distribution for the attribute value of the * instance being classified. Uses all known values of this attribute * to calculate the mean and standard deviation. The probability density * function used:/* w ww .ja v a2 s.c o m*/ * <pre> * 1 ( -(x-m)^2 ) * f(x) = ------------- * exp( -------- ) * sd*sqrt(2*PI) ( 2*(sd)^2 ) * </pre> * * <code>m</code> - mean, <code>sd</code> - standard deviation * * @param attributeValues all values of the attribute (for m and sd) * @param x the attribute value of the instance being classified * @return the normal distribution for x */ public Double calculateNormalDistribution(Comparable[] attributeValues, Double x) { Double mean = calculateMean(attributeValues); Double standardDeviation = calculateStandardDeviation(attributeValues, mean); Double normalDistribution = 1 / (Math.sqrt(2 * Math.PI) * standardDeviation); normalDistribution *= Math.exp(-Math.pow((x - mean) / standardDeviation, 2) / 2); log.debug("normalDistribution( " + x + " ) = " + normalDistribution); return normalDistribution; }
From source file:dr.math.distributions.NegativeBinomialDistribution.java
public static double pdf(double x, double mean, double alpha) { if (x < 0) return 0; return Math.exp(logPdf(x, mean, alpha)); }
From source file:com.opengamma.analytics.financial.credit.creditdefaultswap.pricing.vanilla.isdanew.ISDACompliantCurve.java
/** * /*from w w w . j a va2s .co m*/ * @param t Set of times that form the knots of the curve. Must be ascending with the first value >= 0. * @param r Set of zero rates */ public ISDACompliantCurve(final double[] t, final double[] r) { ArgumentChecker.notEmpty(t, "t empty"); ArgumentChecker.notEmpty(r, "r empty"); _n = t.length; ArgumentChecker.isTrue(_n == r.length, "r and t different lengths"); ArgumentChecker.isTrue(t[0] >= 0, "first t must be >= 0.0"); for (int i = 1; i < _n; i++) { ArgumentChecker.isTrue(t[i] > t[i - 1], "Times must be ascending"); } _t = new double[_n]; _r = new double[_n]; _rt = new double[_n]; _df = new double[_n]; System.arraycopy(t, 0, _t, 0, _n); System.arraycopy(r, 0, _r, 0, _n); for (int i = 0; i < _n; i++) { _rt[i] = _r[i] * _t[i]; // We make no check that rt is ascending (i.e. we allow negative forward rates) _df[i] = Math.exp(-_rt[i]); } _offsetTime = 0.0; _offsetRT = 0.0; }
From source file:com.opengamma.analytics.math.interpolation.ExponentialExtrapolator1D.java
private Double leftExtrapolate(final Interpolator1DDataBundle data, final Double value) { Validate.notNull(data, "data"); Validate.notNull(value, "value"); final double x = data.firstKey(); final double y = data.firstValue(); final double m = Math.log(y) / x; return Math.exp(m * value); }
From source file:com.opengamma.analytics.math.statistics.distribution.LaplaceDistribution.java
/** * {@inheritDoc}/*w w w . j a va 2 s .com*/ */ @Override public double getPDF(final Double x) { Validate.notNull(x); return Math.exp(-Math.abs(x - _mu) / _b) / (2 * _b); }
From source file:com.opengamma.analytics.financial.model.option.pricing.montecarlo.EuropeanMonteCarloOptionModel.java
@Override public Function1D<StandardOptionDataBundle, Double> getPricingFunction(final OptionDefinition definition) { Validate.notNull(definition, "definition"); final OptionPayoffFunction<StandardOptionDataBundle> payoffFunction = definition.getPayoffFunction(); final int steps = getSteps(); final int n = getN(); final RandomNumberGenerator randomNumbers = getGenerator(); final StochasticProcess<OptionDefinition, StandardOptionDataBundle> process = getProcess(); final Function2D<Double, Double> accumulator = process.getPathAccumulationFunction(); return new Function1D<StandardOptionDataBundle, Double>() { @Override/*w w w .j a va2 s . com*/ public Double evaluate(final StandardOptionDataBundle data) { Validate.notNull(data, "data"); final Function1D<Double, Double> generator = process.getPathGeneratingFunction(definition, data, steps); double[] e; final double s0 = process.getInitialValue(definition, data); double st; double sum = 0; for (int i = 0; i < n; i++) { e = randomNumbers.getVector(steps); st = s0; for (int j = 0; j < steps; j++) { st = accumulator.evaluate(generator.evaluate(e[j]), st); } sum += payoffFunction.getPayoff(data.withSpot(process.getFinalValue(st)), 0.); } final double t = definition.getTimeToExpiry(data.getDate()); final double r = data.getInterestRate(t); return Math.exp(-r * t) * sum / n; } }; }
From source file:etomica.math.SpecialFunctions.java
public static double gamma(double x) { if (x == 0) { return 1; }// ww w . j av a2 s . c o m if (x < 0.5) { return Math.PI / (Math.sin(Math.PI * x) * gamma(1 - x)); } double y = Math.exp(lnGamma(x)); return y; }