List of usage examples for java.lang Math exp
@HotSpotIntrinsicCandidate public static double exp(double a)
From source file:com.opengamma.analytics.financial.model.interestrate.HullWhiteOneFactorInterestRateModel.java
@Override public Function1D<HullWhiteOneFactorDataBundle, Double> getDiscountBondFunction(final ZonedDateTime time, final ZonedDateTime maturity) { Validate.notNull(time);//from w ww. j a v a2 s.co m Validate.notNull(maturity); return new Function1D<HullWhiteOneFactorDataBundle, Double>() { @Override public Double evaluate(final HullWhiteOneFactorDataBundle data) { Validate.notNull(data); final double t = DateUtils.getDifferenceInYears(data.getDate(), time); final double s = DateUtils.getDifferenceInYears(data.getDate(), maturity); final double rT = data.getShortRate(t); final double rs = data.getShortRate(s); final double pT = Math.exp(-rT * t); final double ps = Math.exp(-rs * s); final Double sigma = data.getShortRateVolatility(t); final double dt = s - t; final double speed = data.getReversionSpeed(); final double b = (1 - Math.exp(-speed * dt)) / speed; final double upT = t + _delta; final double downT = t - _delta; final double dlnPdt = (-data.getShortRate(upT) * upT + data.getShortRate(downT) * downT) / (2 * _delta); final double lnA = Math.log(ps / pT) - b * dlnPdt - sigma * sigma * Math.pow(Math.exp(-speed * s) - Math.exp(-speed * t), 2) * (Math.exp(2 * speed * t) - 1) / (4 * speed * speed * speed); return Math.exp(lnA - b * rT); } }; }
From source file:com.opengamma.analytics.financial.simpleinstruments.pricing.SimpleFuturePresentValueCalculatorDeprecated.java
@Override public CurrencyAmount visitSimpleFuture(final SimpleFuture future, final SimpleFutureDataBundleDeprecated data) { final double t = future.getExpiry(); return CurrencyAmount.of(future.getCurrency(), future.getUnitAmount() * data.getSpotValue() * Math.exp(t * (data.getFundingCurve().getInterestRate(t) - data.getCostOfCarry()))); }
From source file:com.opengamma.analytics.financial.model.interestrate.HullWhiteTwoFactorInterestRateModel.java
@Override public Function1D<HullWhiteTwoFactorDataBundle, Double> getDiscountBondFunction(final ZonedDateTime time, final ZonedDateTime maturity) { Validate.notNull(time, "time"); Validate.notNull(maturity, "maturity"); return new Function1D<HullWhiteTwoFactorDataBundle, Double>() { @Override/*from w ww .j av a 2 s. co m*/ public Double evaluate(final HullWhiteTwoFactorDataBundle data) { Validate.notNull(data, "data"); final double t1 = 0; final double t2 = DateUtils.getDifferenceInYears(data.getDate(), time); final double t3 = DateUtils.getDifferenceInYears(data.getDate(), maturity); final double r2 = data.getShortRate(t2); final double r3 = data.getShortRate(t3); final double p2 = Math.exp(-r2 * t2); final double p3 = Math.exp(-r3 * t3); final double alpha = data.getFirstSpeed(); final double beta = data.getSecondSpeed(); final double sigma1 = data.getShortRateVolatility(t1); final double sigma2 = data.getSecondVolatility(t1); final double rho = data.getCorrelation(); final double eta = getEta(t1, t2, t3, alpha, beta, sigma1, sigma2, rho); final double b = getB(t3 - t2, alpha); final double c = getC(t3 - t2, alpha, beta); final double u = data.getMeanReversionLevel(); final double f = data.getForwardRate(t1); final double lnA = Math.log(p3 / p2) + b * f - eta; return Math.exp(lnA - r2 * b - u * c); } }; }
From source file:com.opengamma.analytics.financial.model.interestrate.HoLeeInterestRateModel.java
@Override public Function1D<StandardDiscountBondModelDataBundle, Double> getDiscountBondFunction(final ZonedDateTime time, final ZonedDateTime maturity) { Validate.notNull(time);//w w w. j a va 2 s . c om Validate.notNull(maturity); return new Function1D<StandardDiscountBondModelDataBundle, Double>() { @Override public Double evaluate(final StandardDiscountBondModelDataBundle data) { Validate.notNull(data); final double t = DateUtils.getDifferenceInYears(data.getDate(), time); final double s = DateUtils.getDifferenceInYears(data.getDate(), maturity); final double b = s - t; final double sigma = data.getShortRateVolatility(t); final double rT = data.getShortRate(t); final double rS = data.getShortRate(s); final double pT = Math.exp(-rT * t); final double pS = Math.exp(-rS * s); final double dlnPdt = -rT; final double lnA = Math.log(pS / pT) - b * dlnPdt - 0.5 * sigma * sigma * b * b; return Math.exp(lnA - b * rT); } }; }
From source file:com.cloudera.hts.utils.math.MyFunc2.java
public double value(double t, double... parameters) { return parameters[0] * Math.pow(t, parameters[1]) * Math.exp(-parameters[2] * t); }
From source file:edu.illinois.cs.cogcomp.utils.Utils.java
/** * This reads a file in the ngram-format * http://www.speech.sri.com/projects/srilm/manpages/ngram-format.5.html * * and populates the languagemodel datastructure. * * @param fname/* w ww . ja va 2 s . c o m*/ * @return * @throws FileNotFoundException */ public static HashMap<String, Double> readSRILM(String fname) throws FileNotFoundException { List<String> lines = LineIO.read(fname); HashMap<String, Double> out = new HashMap<>(); for (String line : lines) { if (line.trim().length() == 0 || line.startsWith("\\") || line.contains("ngram")) { // do nothing. } else { String[] sline = line.trim().split("\t"); // important because of the log probabilities Double v = Math.exp(Double.parseDouble(sline[0])); String ngram = sline[1]; String[] chars = ngram.split(" "); out.put(StringUtils.join(chars, ""), v); } } return out; }
From source file:edu.gsgp.utils.Utils.java
public static double sigmoid(double x) { return 1 / (1 + Math.exp(-x)); }
From source file:com.opengamma.analytics.financial.interestrate.market.MarketDiscountingTimeDecorated.java
@Override public double getDiscountingFactor(Currency ccy, Double time) { if ((ccy == _ccy) && (_time == time)) { double rate = -Math.log(super.getDiscountingFactor(ccy, time)) / time; return Math.exp(-(rate + _shift) * time); }//from w w w. j a v a 2 s. c om return super.getDiscountingFactor(ccy, time); }
From source file:com.opengamma.analytics.financial.model.stochastic.BlackScholesArithmeticBrownianMotionProcess.java
@Override public Function1D<Double, Double> getPathGeneratingFunction(final T t, final U u, final int steps) { Validate.notNull(t);//from w w w . j a va 2s. c o m Validate.notNull(u); if (steps < 1) { throw new IllegalArgumentException("Number of steps must be greater than zero"); } final double k = t.getStrike(); final double m = t.getTimeToExpiry(u.getDate()); final double sigma = u.getVolatility(m, k); final double b = u.getCostOfCarry(); final double dt = m / steps; final double sigmaSq = sigma * sigma; final double nu = dt * (b - 0.5 * sigmaSq); final double sigmaDt = sigma * Math.sqrt(dt); return new Function1D<Double, Double>() { @Override public Double evaluate(final Double e) { return Math.exp(nu + sigmaDt * e); } }; }
From source file:com.opengamma.analytics.financial.model.volatility.surface.SABRBlackEquivalentVolatilitySurfaceModel.java
@Override public VolatilitySurface getSurface(final OptionDefinition option, final SABRDataBundle data) { Validate.notNull(option, "option definition"); Validate.notNull(data);/*w w w . j a va2 s .co m*/ final double k = option.getStrike(); final double t = option.getTimeToExpiry(data.getDate()); final double alpha = data.getAlpha(); final double beta = data.getBeta(); final double rho = data.getRho(); final double ksi = data.getVolOfVol(); final double b = data.getCostOfCarry(); final double f = data.getSpot() * Math.exp(b * t); return new VolatilitySurface(ConstantDoublesSurface .from(SABR_FUNCTION.getVolatilityFunction(new EuropeanVanillaOption(k, t, true), f) .evaluate(new SABRFormulaData(alpha, beta, rho, ksi)))); }