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.opengamma.analytics.math.statistics.distribution.GeneralizedExtremeValueDistribution.java

/**
 * {@inheritDoc}//from   w w  w. j a v  a  2 s .  co  m
 * @throws IllegalArgumentException If $x \not\in$ support
 */
@Override
public double getCDF(final Double x) {
    Validate.notNull(x);
    return Math.exp(-getT(x));
}

From source file:edu.oregonstate.eecs.mcplan.util.GibbsDistribution.java

public void add(final double x) {
    final double e = Math.exp(-beta * x);
    xs_.add(e);/*from  w  w  w  .ja  v  a  2s  .  c om*/
    Z_tminus1 = Z_;
    Z_ += e;
    mv_dirty_ = true;
}

From source file:com.qaant.optionModels.QBlackScholes.java

@Override
//public void runModel(){
public void run() {

    pModelName = "Black-Scholes QAANT";
    modelNumber = 1;//from w  ww  .  ja v  a 2  s. c om
    tipoEjercicio = EUROPEAN;
    //

    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:com.opengamma.analytics.financial.equity.future.pricing.EquityFutureDividendYield.java

/**
 * @param future EquityFuture derivative
 * @param dataBundle Contains funding curve, spot value and continuous dividend yield 
 * @return The change in the present value given a unit value change in the underlying's spot value
 *//*from   w ww.ja  va2 s  . c om*/
@Override
public double spotDelta(final EquityFuture future, final EquityFutureDataBundle dataBundle) {
    Validate.notNull(future, "Future");
    Validate.notNull(dataBundle);
    Validate.notNull(dataBundle.getFundingCurve());
    Validate.notNull(dataBundle.getDividendYield());

    double timeToExpiry = future.getTimeToSettlement();
    double discountRate = dataBundle.getFundingCurve().getInterestRate(timeToExpiry);
    double costOfCarry = Math.exp(timeToExpiry * (discountRate - dataBundle.getDividendYield()));
    return costOfCarry * future.getUnitAmount();
}

From source file:edu.cmu.tetrad.search.Test.java

private double logOfSum(List<Double> logs) {

    Collections.sort(logs, new Comparator<Double>() {
        @Override//from  ww w.  j a v  a 2 s  .  co m
        public int compare(Double o1, Double o2) {
            return -Double.compare(o1, o2);
        }
    });

    double sum = 0.0;
    int N = logs.size() - 1;
    double loga0 = logs.get(0);

    for (int i = 1; i <= N; i++) {
        sum += Math.exp(logs.get(i) - loga0);
    }

    sum += 1;

    return loga0 + Math.log(sum);
}

From source file:dsp.unige.figures.ChannelHelper.java

/**
 * Returns the rain attenuation in dB given the state s, using procedure
 * from [1]. [1]. A prediction model that combines Rain Attenuation and
 * Other Propagation Impairments Along Earth- Satellinte Paths
 * /*  w w  w .  java2 s  .c  o m*/
 * @param s
 * @return rain attenuation in dB.
 */
public static double getRainAttenuation(Station s) {

    // ==================== step 1 ===========================
    // calculate freezing height (in km) from the absolute value of station
    // latitude
    double hFr;
    if (s.stationLatitude >= 0 && s.stationLatitude < 23)
        hFr = 5.0d;
    else
        hFr = 5.0 - 0.075 * (s.stationLatitude - 23);

    // ==================== step 2 ===========================
    // calculate slant-path length Ls below the freezing height
    double Ls = (hFr - s.stationAltitude) / Math.sin(s.elevationAngle * Math.PI / 180);

    // ==================== step 3 ===========================
    // calculate horizontal projection Lg of the slant path length
    double Lg = Ls * Math.cos(s.elevationAngle * Math.PI / 180);

    // ==================== step 4 ===========================
    // obtain rain attenuation
    double gamma = s.getRainK() * Math.pow(s.R001, s.getRainAlpha());

    // ==================== step 5 ===========================
    // calculate horizontal path adjustment
    double rh001 = 1 / (1 + 0.78 * Math.sqrt(Lg * gamma / s.frequency) - 0.38 * (1 - Math.exp(-2 * Lg)));

    // ==================== step 6 ===========================
    // calculate the adjusted rainy path length
    double ZETA = Math.atan((hFr - s.stationAltitude) / (Lg * rh001));
    double Lr;

    if (ZETA > s.elevationAngle) {
        Lr = (Lg * rh001) / (Math.cos(s.elevationAngle * Math.PI / 180));
    } else {
        Lr = (hFr - s.stationAltitude) / (Math.sin(s.elevationAngle * Math.PI / 180));
    }

    // ==================== step 7 ===========================
    // calculate vertical path adjustment
    double CHI;
    if (Math.abs(s.elevationAngle) < 36) {
        CHI = 36 - s.elevationAngle;
    } else {
        CHI = 0;
    }
    double rv001 = 1 / (1 + Math.sqrt(Math.sin(s.elevationAngle * Math.PI / 180))
            * (31 * (1 - Math.exp(-s.elevationAngle / (1 + CHI)))
                    * (Math.sqrt(Lr * gamma) / Math.pow(s.frequency, 2)) - 0.45));

    // ==================== step 8 ===========================
    // effective path length through rain
    double Le = Lr * rv001;

    // ==================== step 9 ===========================
    // get the attenuation exceded in 0.01% of average year time
    double A001 = gamma * Le;

    return A001;
}

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

@Override
public Function1D<StandardOptionDataBundle, Double> getPricingFunction(
        final ComplexChooserOptionDefinition definition) {
    Validate.notNull(definition, "definition");
    return new Function1D<StandardOptionDataBundle, Double>() {

        @SuppressWarnings("synthetic-access")
        @Override// w w  w  .  ja  v a2 s .co  m
        public Double evaluate(final StandardOptionDataBundle data) {
            Validate.notNull(data, "data");
            final double s = data.getSpot();
            final double kCall = definition.getCallStrike();
            final double kPut = definition.getPutStrike();
            final ZonedDateTime date = data.getDate();
            final double tCall = definition.getTimeToCallExpiry(date);
            final double tPut = definition.getTimeToPutExpiry(date);
            final double tChoose = definition.getTimeToExpiry(date);
            final double sigma = data.getVolatility(tChoose, kCall);
            final double r = data.getInterestRate(tChoose);
            final double b = data.getCostOfCarry();
            final double deltaTCall = tCall - tChoose;
            final double deltaTPut = tPut - tChoose;
            final double criticalValue = getCriticalValue(Math.exp(deltaTCall * (b - r)),
                    Math.exp(-deltaTCall * r), Math.exp(deltaTPut * (b - r)), Math.exp(-deltaTPut * r), sigma,
                    b, kCall, kPut, deltaTCall, deltaTPut);
            final double d1 = getD1(s, criticalValue, tChoose, sigma, b);
            final double d2 = getD2(d1, sigma, tChoose);
            final double d3 = getD1(s, kCall, tCall, sigma, b);
            final double d4 = getD2(d3, sigma, tCall);
            final double d5 = getD1(s, kPut, tPut, sigma, b);
            final double d6 = getD2(d5, sigma, tPut);
            final double rho1 = Math.sqrt(tChoose / tCall);
            final double rho2 = Math.sqrt(tChoose / tPut);
            return s * Math.exp(tCall * (b - r)) * BIVARIATE_NORMAL.getCDF(new double[] { d1, d3, rho1 })
                    - kCall * Math.exp(-r * tCall) * BIVARIATE_NORMAL.getCDF(new double[] { d2, d4, rho1 })
                    - s * Math.exp(tPut * (b - r)) * BIVARIATE_NORMAL.getCDF(new double[] { -d1, -d5, rho2 })
                    + kPut * Math.exp(-r * tPut) * BIVARIATE_NORMAL.getCDF(new double[] { -d2, -d6, rho2 });
        }

    };
}

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

@Override
public Function1D<StandardOptionDataBundle, Double> getPricingFunction(
        final EuropeanStandardBarrierOptionDefinition definition) {
    Validate.notNull(definition, "definition");
    final Barrier barrier = definition.getBarrier();
    final boolean isKnockIn = barrier.getKnockType() == KnockType.IN;
    final boolean isDown = barrier.getBarrierType() == BarrierType.DOWN;
    final double h = barrier.getBarrierLevel();
    final int phi = definition.isCall() ? 1 : -1;
    final double eta = isDown ? 1 : -1;
    return new Function1D<StandardOptionDataBundle, Double>() {

        @SuppressWarnings("synthetic-access")
        @Override// w w w.j  av a2s.  c o  m
        public Double evaluate(final StandardOptionDataBundle data) {
            Validate.notNull(data, "data");
            final boolean isCall = definition.isCall();
            final double s = data.getSpot();
            final double b = data.getCostOfCarry();
            final double t = definition.getTimeToExpiry(data.getDate());
            final double rebate = definition.getRebate();
            final double k = definition.getStrike();
            final double r = data.getInterestRate(t);
            final double sigma = data.getVolatility(t, h); //REVIEW emcleod 19-7-10 will only work if volatility is constant
            final double df1 = Math.exp(t * (b - r));
            final double df2 = Math.exp(-r * t);
            if (CompareUtils.closeEquals(sigma, 0, 1e-16)) {
                return df1 * definition.getPayoffFunction().getPayoff(data, null);
            }
            final double sigmaSq = sigma * sigma;
            final double sigmaT = sigma * Math.sqrt(t);
            final double mu = (b - 0.5 * sigmaSq) / sigmaSq;
            final double lambda = Math.sqrt(mu * mu + 2 * r / sigmaSq);
            final double m1 = sigmaT * (1 + mu);
            final double x1 = Math.log(s / k) / sigmaT + m1;
            final double x2 = Math.log(s / h) / sigmaT + m1;
            final double y1 = Math.log(h * h / s / k) / sigmaT + m1;
            final double y2 = Math.log(h / s) / sigmaT + m1;
            final double z = Math.log(h / s) / sigmaT + lambda * sigmaT;
            final double xA = getA(s, k, df1, df2, x1, sigmaT, phi);
            final double xB = getA(s, k, df1, df2, x2, sigmaT, phi);
            final double xC = getC(s, k, df1, df2, y1, sigmaT, h, mu, phi, eta);
            final double xD = getC(s, k, df1, df2, y2, sigmaT, h, mu, phi, eta);
            final double xE = isKnockIn ? getE(s, rebate, df2, x2, y2, sigmaT, h, mu, eta)
                    : getF(s, rebate, z, sigmaT, h, mu, lambda, eta);
            if (isKnockIn) {
                if (isDown) {
                    if (isCall) {
                        return k > h ? xC + xE : xA - xB + xD + xE;
                    }
                    return k > h ? xB - xC + xD + xE : xA + xE;
                }
                if (isCall) {
                    return k > h ? xA + xE : xB - xC + xD + xE;
                }
                return k > h ? xA - xB + xD + xE : xC + xE;
            }
            if (isDown) {
                if (isCall) {
                    return k > h ? xA - xC + xE : xB - xD + xE;
                }
                return k > h ? xA - xB + xC - xD + xE : xE;
            }
            if (isCall) {
                return k > h ? xE : xA - xB + xC - xD + xE;
            }
            return k > h ? xB - xD + xE : xA - xC + xE;
        }

    };
}

From source file:com.opengamma.analytics.math.minimization.SingleRangeLimitTransform.java

/**
 * {@inheritDoc}//from   ww w .ja  v a  2 s.  c  om
 */
@Override
public double inverseTransformGradient(final double y) {
    if (y > EXP_MAX) {
        return _sign;
    }
    final double temp = Math.exp(y);
    return _sign * temp / (temp + 1);
}

From source file:com.opengamma.analytics.financial.interestrate.payments.method.CapFloorIborLMMDDMethod.java

/**
 * Computes the present value of the cap/floor in the LMM. It is computed using a Black formula (on the shifted rate). The volatility is the LMM volatilities for the
 * relevant period multiplied by the time dependent factor square mean.
 * The method is used mainly for calibration purposes.
 * @param cap The cap. Should have the same underlying index as the model (same payment frequency).
 * @param lmmData The Model parameters./* w ww  .ja  v  a  2s.  c om*/
 * @return The present value.
 */
public CurrencyAmount presentValue(final CapFloorIbor cap,
        final LiborMarketModelDisplacedDiffusionDataBundle lmmData) {
    final int index = lmmData.getLmmParameter().getTimeIndex(cap.getFixingPeriodStartTime());
    double volatility = 0;
    for (int loopfact = 0; loopfact < lmmData.getLmmParameter().getNbFactor(); loopfact++) {
        volatility += lmmData.getLmmParameter().getVolatility()[index][loopfact]
                * lmmData.getLmmParameter().getVolatility()[index][loopfact];
    }
    volatility = Math.sqrt(volatility);
    final double timeDependentFactor = Math
            .sqrt((Math.exp(2 * lmmData.getLmmParameter().getMeanReversion() * cap.getFixingTime()) - 1.0)
                    / (2.0 * lmmData.getLmmParameter().getMeanReversion()));
    volatility *= timeDependentFactor;
    final double displacement = lmmData.getLmmParameter().getDisplacement()[index];
    final double beta = lmmData.getCurve(cap.getForwardCurveName())
            .getDiscountFactor(cap.getFixingPeriodStartTime())
            / lmmData.getCurve(cap.getForwardCurveName()).getDiscountFactor(cap.getFixingPeriodEndTime())
            * lmmData.getCurve(cap.getFundingCurveName()).getDiscountFactor(cap.getFixingPeriodEndTime())
            / lmmData.getCurve(cap.getFundingCurveName()).getDiscountFactor(cap.getFixingPeriodStartTime());
    final double strikeAdjusted = (cap.getStrike() - (beta - 1) / cap.getFixingAccrualFactor()) / beta;
    final EuropeanVanillaOption option = new EuropeanVanillaOption(strikeAdjusted + displacement, 1.0,
            cap.isCap()); // Time is in timeDependentFactor
    final double forwardDsc = (lmmData.getCurve(cap.getFundingCurveName())
            .getDiscountFactor(cap.getFixingPeriodStartTime())
            / lmmData.getCurve(cap.getFundingCurveName()).getDiscountFactor(cap.getFixingPeriodEndTime()) - 1.0)
            / cap.getFixingAccrualFactor();
    final double df = lmmData.getCurve(cap.getFundingCurveName()).getDiscountFactor(cap.getPaymentTime());
    final BlackFunctionData dataBlack = new BlackFunctionData(forwardDsc + displacement, df, volatility);
    final Function1D<BlackFunctionData, Double> func = BLACK_FUNCTION.getPriceFunction(option);
    final double price = beta * func.evaluate(dataBlack) * cap.getNotional() * cap.getPaymentYearFraction();
    return CurrencyAmount.of(cap.getCurrency(), price);
}