List of usage examples for java.lang Math exp
@HotSpotIntrinsicCandidate public static double exp(double a)
From source file:org.rhwlab.ace3d.SegmentationLinePlot.java
public void setTree(BHCTree tree) { XYSeriesCollection collect = new XYSeriesCollection(); XYSeries series = new XYSeries(""); collect.addSeries(series);/*from w ww . ja va 2 s . c o m*/ TreeMap<Integer, TreeSet<NucleusLogNode>> map = tree.allTreeCuts(500); for (Integer i : map.keySet()) { TreeSet<NucleusLogNode> nodes = map.get(i); double lnP = nodes.first().getLogPosterior(); series.add((double) i, Math.exp(lnP)); } int t = tree.getTime(); int nu = tree.getNu(); JFreeChart chart = ChartFactory.createXYLineChart( String.format("Time=%d,nu=%d,alpha=%e", tree.getTime(), tree.getNu(), tree.getAlpha()), "Index", "Probability", collect, PlotOrientation.VERTICAL, false, true, true); XYPlot plot = (XYPlot) chart.getPlot(); ChartPanel panel = new ChartPanel(chart); this.add(panel); }
From source file:blackscholes.EuropeanCall.java
public double ValuationMethod() { NormalDistribution N = new NormalDistribution(); double _b = r - b; double d1 = (Math.log(S / X) + (b + 0.5 * Math.pow(sigma, 2)) * T) / (sigma * Math.sqrt(T)); double d2 = d1 - sigma * Math.sqrt(T); double Nd1 = N.cumulativeProbability(d1); double Nd2 = N.cumulativeProbability(d2); return S * Nd1 - X * Nd2 * Math.exp((b - r) * T); }
From source file:beast.math.distributions.NegativeBinomialDistribution.java
public double pdf(double x) { if (x < 0) return 0; return Math.exp(logPdf(x)); }
From source file:com.opengamma.analytics.financial.interestrate.ContinuousInterestRate.java
@Override public double getDiscountFactor(final double t) { return Math.exp(-getRate() * t); }
From source file:com.example.PJS.java
/** Otra version de la NORMSDIST (z) sacada de aca: * http://www.codeproject.com/Articles/408214/Excel-Function-NORMSDIST-z *Esta es la Cumulative Normal Ditribution Function *//*from www .ja va2 s . c om*/ private static double erf(double x) { //A&S formula 7.1.26 double a1 = 0.254829592; double a2 = -0.284496736; double a3 = 1.421413741; double a4 = -1.453152027; double a5 = 1.061405429; double p = 0.3275911; x = Math.abs(x); double t = 1 / (1 + p * x); //Direct calculation using formula 7.1.26 is absolutely correct //But calculation of nth order polynomial takes O(n^2) operations //return 1 - (a1 * t + a2 * t * t + a3 * t * t * t + a4 * t * t * t * t + a5 * t * t * t * t * t) * Math.Exp(-1 * x * x); //Horner's method, takes O(n) operations for nth order polynomial return 1 - ((((((a5 * t + a4) * t) + a3) * t + a2) * t) + a1) * t * Math.exp(-1 * x * x); }
From source file:com.opengamma.analytics.financial.model.option.pricing.tree.LeisenReimerLatticeSpecification.java
@Override public double[] getParameters(final double spot, final double strike, final double timeToExpiry, final double volatility, final double interestRate, final int nSteps, final double dt) { Validate.isTrue((nSteps % 2 == 1), "The number of steps should be odd"); final double sigmaRootT = volatility * Math.sqrt(timeToExpiry); final double d1 = (Math.log(spot / strike) + interestRate * timeToExpiry) / sigmaRootT + 0.5 * sigmaRootT; final double d2 = d1 - sigmaRootT; final double sig1 = d1 >= 0. ? 1. : -1.; final double sig2 = d2 >= 0. ? 1. : -1.; final double coef1 = d1 / (nSteps + 1. / 3. + 0.1 / (nSteps + 1.)); final double coef2 = d2 / (nSteps + 1. / 3. + 0.1 / (nSteps + 1.)); final double p1 = 0.5 + sig1 * 0.5 * Math.sqrt(1. - Math.exp(-coef1 * coef1 * (nSteps + 1. / 6.))); final double p2 = 0.5 + sig2 * 0.5 * Math.sqrt(1. - Math.exp(-coef2 * coef2 * (nSteps + 1. / 6.))); final double rr = Math.exp(interestRate * dt); final double upFactor = rr * p1 / p2; final double downFactor = (rr - p2 * upFactor) / (1 - p2); return new double[] { upFactor, downFactor, p2, 1 - p2 }; }
From source file:com.opengamma.analytics.financial.interestrate.NelsonSiegelBondCurveModel.java
public ParameterizedFunction<Double, DoubleMatrix1D, Double> getParameterizedFunction() { return new ParameterizedFunction<Double, DoubleMatrix1D, Double>() { @Override//from w ww . j a v a2 s .c o m public Double evaluate(final Double t, final DoubleMatrix1D parameters) { Validate.notNull(t, "t"); Validate.notNull(parameters, "parameters"); Validate.isTrue(parameters.getNumberOfElements() == 4); final double beta0 = parameters.getEntry(0); final double beta1 = parameters.getEntry(1); final double beta2 = parameters.getEntry(2); final double lambda = parameters.getEntry(3); final double x1 = t / lambda; final double x2 = Epsilon.epsilon(-x1); return beta0 + beta1 * x2 + beta2 * (x2 - Math.exp(-x1)); } public Object writeReplace() { return new InvokedSerializedForm(NelsonSiegelBondCurveModel.class, "getParameterizedFunction"); } }; }
From source file:com.opengamma.analytics.financial.interestrate.PeriodicInterestRate.java
@Override public double fromContinuousDerivative(final ContinuousInterestRate continuous) { Validate.notNull(continuous);// w ww.j av a 2 s .c o m return Math.exp(continuous.getRate() / getCompoundingPeriodsPerYear()); }
From source file:com.opengamma.analytics.financial.interestrate.NelsonSiegelSvennsonBondCurveModel.java
public ParameterizedFunction<Double, DoubleMatrix1D, Double> getParameterizedFunction() { return new ParameterizedFunction<Double, DoubleMatrix1D, Double>() { @Override/*w ww . jav a 2s .co m*/ public Double evaluate(final Double t, final DoubleMatrix1D parameters) { Validate.notNull(t, "t"); Validate.notNull(parameters, "parameters"); Validate.isTrue(parameters.getNumberOfElements() == 6); final double beta0 = parameters.getEntry(0); final double beta1 = parameters.getEntry(1); final double beta2 = parameters.getEntry(2); final double lambda1 = parameters.getEntry(3); final double beta3 = parameters.getEntry(4); final double lambda2 = parameters.getEntry(5); final double x1 = t / lambda1; final double x2 = (1 - Math.exp(-x1)) / x1; final double x3 = t / lambda2; final double x4 = (1 - Math.exp(-x3)) / x3; return beta0 + beta1 * x2 + beta2 * (x2 - Math.exp(-x1)) + beta3 * (x4 - Math.exp(-x3)); } public Object writeReplace() { return new InvokedSerializedForm(NelsonSiegelSvennsonBondCurveModel.class, "getParameterizedFunction"); } }; }
From source file:com.cloudera.science.mgps.NFunction.java
public double eval(int n, double e) { double x = -n * Math.log(1 + beta / e); double y = -alpha * Math.log(1 + e / beta); double z = Gamma.logGamma(alpha + n); double d = Gamma.logGamma(alpha) + MathUtils.factorialLog(n); return Math.exp(x + y + z - d); }