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:com.itemanalysis.psychometrics.irt.model.IrmGRM.java

/**
 * Compute cumulative probability of scoring at or above category.
 *
 * @param theta examinee proficiency//from  w w w  .j av  a2s.  c o m
 * @param category response category
 * @return
 */
public double cumulativeProbability(double theta, int category) {
    if (category > maxCategory || category < minCategory)
        return 0;
    if (category == minCategory)
        return 1.0;

    double Zk = D * discrimination * (theta - step[category - 1]);
    double expZk = Math.exp(Zk);
    double prob = expZk / (1 + expZk);

    return prob;
}

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

protected static Curve<Double, Double> getForwardCurve(final Double spot, final Double drift) {
    final Function1D<Double, Double> fwd = new Function1D<Double, Double>() {

        @Override//from  w w  w . jav a  2s.c  om
        public Double evaluate(final Double t) {
            return spot * Math.exp(drift * t);
        }

    };

    return new FunctionalDoublesCurve(fwd) {

        public Object writeReplace() {
            return new InvokedSerializedForm(ForwardCurve.class, "getForwardCurve", spot, drift);
        }
    };
}

From source file:es.udc.gii.common.eaf.benchmark.multiobjective.dtlz2.R_Dtlz2_Objective.java

@Override
public double evaluate(double[] x) {

    int nx = x.length;

    int i = 0, 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;
    }//from   w  w w.  j  a va 2 s. com

    for (i = 0; i < nx; i++) {
        z[i] = 0;
        for (j = 0; j < nx; j++) {
            z[i] += M[i][j] * x[j];
        }
        if (z[i] >= 0 && z[i] <= 1) {
            zz[i] = z[i];
            p[i] = 0;
        } else if (z[i] < 0) {
            zz[i] = -lambda[i] * z[i];
            p[i] = -z[i];
        } else {
            zz[i] = 1 - lambda[i] * (z[i] - 1);
            p[i] = z[i] - 1;
        }
    }

    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:com.opengamma.analytics.financial.model.option.pricing.fourier.FourierModelGreeks.java

public double[] getGreeks(final BlackFunctionData data, final EuropeanVanillaOption option,
        final MartingaleCharacteristicExponent ce, final double alpha, final double limitTolerance) {
    Validate.notNull(data, "data");
    Validate.notNull(option, "option");
    Validate.notNull(ce, "characteristic exponent");
    Validate.isTrue(limitTolerance > 0, "limit tolerance must be > 0");
    Validate.isTrue(alpha <= ce.getLargestAlpha() && alpha >= ce.getSmallestAlpha(),
            "The value of alpha is not valid for the Characteristic Exponent and will most likely lead to mispricing. Choose a value between "
                    + ce.getSmallestAlpha() + " and " + ce.getLargestAlpha());

    final EuropeanCallFourierTransform psi = new EuropeanCallFourierTransform(ce);
    final double strike = option.getStrike();
    final double t = option.getTimeToExpiry();
    final double forward = data.getForward();
    final double discountFactor = data.getDiscountFactor();
    final Function1D<ComplexNumber, ComplexNumber> characteristicFunction = psi.getFunction(t);
    final double xMax = LIMIT_CALCULATOR.solve(characteristicFunction, alpha, limitTolerance);

    double kappa = Math.log(strike / forward);
    int n = ce.getCharacteristicExponentAdjoint(MINUS_I, 1.0).length; //TODO have method like getNumberOfparameters 

    Function1D<ComplexNumber, ComplexNumber[]> adjointFuncs = ce.getAdjointFunction(t);
    double[] res = new double[n - 1];

    //TODO This is inefficient as a call to ajointFuncs.evaluate(z), will return several values (the value of the characteristic function and its derivatives), but only one
    // of these values is used by each of the the integraters - a parallel quadrature scheme would be good here 
    for (int i = 0; i < n - 1; i++) {
        final Function1D<Double, Double> func = getIntegrandFunction(adjointFuncs, alpha, kappa, i + 1);
        final double integral = Math.exp(-alpha * Math.log(strike / forward))
                * _integrator.integrate(func, 0.0, xMax) / Math.PI;
        res[i] = discountFactor * forward * integral;
    }/*w ww .  j a  va  2  s.  co  m*/
    return res;
}

From source file:com.opengamma.analytics.financial.model.option.pricing.analytic.CappedPowerOptionModel.java

/**
 * {@inheritDoc}/*from   w w w. j a  v  a2s .  c  o  m*/
 */
@Override
public Function1D<StandardOptionDataBundle, Double> getPricingFunction(
        final CappedPowerOptionDefinition definition) {
    Validate.notNull(definition);
    final Function1D<StandardOptionDataBundle, Double> pricingFunction = new Function1D<StandardOptionDataBundle, Double>() {

        @SuppressWarnings("synthetic-access")
        @Override
        public Double evaluate(final StandardOptionDataBundle 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 power = definition.getPower();
            final double inv = 1. / power;
            final double cap = definition.getCap();
            final boolean isCall = definition.isCall();
            final double sigmaT = sigma * Math.sqrt(t);
            final double x = t * (b + sigma * sigma * (power - 0.5));
            final double d1 = getD(s / Math.pow(k, 1. / power), x, sigmaT);
            final double d2 = d1 - power * sigmaT;
            final double d3 = getD(isCall ? s / Math.pow(k + cap, inv) : s / Math.pow(k - cap, inv), x, sigmaT);
            final double d4 = d3 - power * sigmaT;
            final int sign = isCall ? 1 : -1;
            final double df1 = Math.exp(-r * t);
            final double df2 = Math
                    .exp(t * ((power - 1) * (r + power * sigma * sigma * 0.5) - power * (r - b)));
            final double term1 = Math.pow(s, power) * df2
                    * (NORMAL.getCDF(sign * d1) - NORMAL.getCDF(sign * d3));
            final double term2 = df1
                    * (k * NORMAL.getCDF(sign * d2) - (k + sign * cap) * NORMAL.getCDF(sign * d4));
            return sign * (term1 - term2);
        }

    };
    return pricingFunction;
}

From source file:com.opengamma.analytics.financial.forex.method.ForexOptionSingleBarrierBlackMethod.java

/**
 * Computes the present value for single barrier Forex option in Black model (log-normal spot rate).
 * @param optionForex The Forex option./*from   w  w  w.j  a v a2s.co m*/
 * @param smile The volatility and curves description.
 * @return The present value (in domestic currency).
 */
public MultipleCurrencyAmount presentValue(final ForexOptionSingleBarrier optionForex,
        final SmileDeltaTermStructureDataBundle smile) {
    Validate.notNull(optionForex, "Forex option");
    Validate.notNull(smile, "Smile");
    final double payTime = optionForex.getUnderlyingOption().getUnderlyingForex().getPaymentTime();
    final double rateDomestic = smile.getCurve(
            optionForex.getUnderlyingOption().getUnderlyingForex().getPaymentCurrency2().getFundingCurveName())
            .getInterestRate(payTime);
    final double rateForeign = smile.getCurve(
            optionForex.getUnderlyingOption().getUnderlyingForex().getPaymentCurrency1().getFundingCurveName())
            .getInterestRate(payTime);
    final double spot = smile.getFxRates().getFxRate(optionForex.getCurrency1(), optionForex.getCurrency2());
    final double forward = spot * Math.exp(-rateForeign * payTime) / Math.exp(-rateDomestic * payTime);
    final double foreignAmount = optionForex.getUnderlyingOption().getUnderlyingForex().getPaymentCurrency1()
            .getAmount();
    final double rebateByForeignUnit = optionForex.getRebate() / Math.abs(foreignAmount);
    final double sign = (optionForex.getUnderlyingOption().isLong() ? 1.0 : -1.0);
    final double volatility = FXVolatilityUtils.getVolatility(smile, optionForex.getCurrency1(),
            optionForex.getCurrency2(), optionForex.getUnderlyingOption().getTimeToExpiry(),
            optionForex.getUnderlyingOption().getStrike(), forward);
    double price = BLACK_FUNCTION.getPrice(optionForex.getUnderlyingOption(), optionForex.getBarrier(),
            rebateByForeignUnit, spot, rateForeign, rateDomestic, volatility);
    price *= Math.abs(foreignAmount) * sign;
    final CurrencyAmount priceCurrency = CurrencyAmount
            .of(optionForex.getUnderlyingOption().getUnderlyingForex().getCurrency2(), price);
    return MultipleCurrencyAmount.of(priceCurrency);
}

From source file:com.opengamma.analytics.financial.interestrate.annuity.ZSpreadCalculator.java

public double calculatePriceSensitivityToZSpread(final Annuity<? extends Payment> annuity,
        final YieldCurveBundle curves, final double zSpread) {
    Validate.notNull(annuity, "annuity");
    Validate.notNull(curves, "curves");

    double sum = 0;

    final int n = annuity.getNumberOfPayments();
    Payment payment;/*from   w ww  .ja  v a2s  . c  o m*/
    for (int i = 0; i < n; i++) {
        payment = annuity.getNthPayment(i);
        final double temp = PRESENT_VALUE_CALCULATOR.visit(payment, curves);
        final double time = payment.getPaymentTime();
        sum -= time * temp * Math.exp(-zSpread * time);
    }
    return sum;
}

From source file:de.uni_erlangen.lstm.modelaccess.Model.java

public void init(double start, double end) {
    this.events = new ArrayList<DiscreteEvent>();
    this.start = start;
    this.end = end;
    this.progress = start;

    // Flow rate is set by influent
    x[35] = u[35]; // Effluent flow rate = Influent flow rate

    // Initialise the S_H_ion
    double factor = (1.0 / param[0] - 1.0 / param[1]) / (100.0 * 0.083145);
    double K_w = Math.pow(10, -param[2]) * Math.exp(55900.0 * factor); // T adjustment for K_w 
    double phi = x[24] + (x[10] - x[31]) - x[30] - (x[29] / 64.0) - (x[28] / 112.0) - (x[27] / 160.0)
            - (x[26] / 208.0) - x[25];/*from   w  w  w.java 2  s. c  o m*/
    S_H_ion = (-phi * 0.5) + 0.5 * Math.sqrt(phi * phi + (4.0 * K_w)); // SH+   
}

From source file:com.opengamma.analytics.math.interpolation.LogNaturalCubicMonotonicityPreservingInterpolator1D.java

@Override
public double[] getNodeSensitivitiesForValue(final Interpolator1DDataBundle data, final Double value) {
    Validate.notNull(value, "value");
    Validate.notNull(data, "data bundle");
    Validate.isTrue(data instanceof Interpolator1DLogPiecewisePoynomialDataBundle);
    final Interpolator1DLogPiecewisePoynomialDataBundle polyData = (Interpolator1DLogPiecewisePoynomialDataBundle) data;
    final double[] resSense = FUNC
            .nodeSensitivity(polyData.getPiecewisePolynomialResultsWithSensitivity(), value).getData();
    final double resValue = Math
            .exp(FUNC.evaluate(polyData.getPiecewisePolynomialResultsWithSensitivity(), value).getEntry(0));
    final double[] knotValues = data.getValues();
    final int nKnots = knotValues.length;
    final double[] res = new double[nKnots];
    for (int i = 0; i < nKnots; ++i) {
        res[i] = resSense[i] * resValue / knotValues[i];
    }/*from w ww  . j  a  va 2s .co m*/
    return res;
}

From source file:edu.umn.cs.spatialHadoop.visualization.FrequencyMap.java

/**
 * Initialize a frequency map with the given radius and kernel type
 * @param radius/*from   w  w  w . j a v a2s. c  om*/
 * @param smoothType
 */
protected void initKernel(int radius, SmoothType smoothType) {
    this.radius = radius;
    // initialize the kernel according to the radius and kernel type
    kernel = new float[radius * 2][radius * 2];
    switch (smoothType) {
    case Flat:
        for (int dx = -radius; dx < radius; dx++) {
            for (int dy = -radius; dy < radius; dy++) {
                if (dx * dx + dy * dy < radius * radius) {
                    kernel[dx + radius][dy + radius] = 1.0f;
                }
            }
        }
        break;
    case Gaussian:
        int stdev = 8;
        // Apply two-dimensional Gaussian function
        // http://en.wikipedia.org/wiki/Gaussian_function#Two-dimensional_Gaussian_function
        for (int dx = -radius; dx < radius; dx++) {
            for (int dy = -radius; dy < radius; dy++) {
                kernel[dx + radius][dy + radius] = (float) Math
                        .exp(-(dx * dx + dy * dy) / (2.0 * stdev * stdev));
            }
        }
    }
}