List of usage examples for org.apache.commons.math3.distribution NormalDistribution NormalDistribution
public NormalDistribution()
From source file:cz.cuni.mff.d3s.spl.interpretation.WelchTestWithEnlargedVariancesInterpretation.java
/** {@inheritDoc} */ @Override//from ww w .jav a 2s . co m public ComparisonResult compare(DataSnapshot left, DataSnapshot right) { NeededStatistics leftStat = NeededStatistics.create(left, getHistoricalIfAvailable(left)); NeededStatistics rightStat = NeededStatistics.create(right, getHistoricalIfAvailable(right)); double stat = getStatistic(leftStat, rightStat); RealDistribution distribution = new NormalDistribution(); return new DistributionBasedComparisonResult(stat, distribution); }
From source file:iad.stat.distribution.DistributionCalc.java
private void calculateNorm(boolean twoTailed) { norm = new NormalDistribution(); if (twoTailed) { normalPValue = (1 - norm.cumulativeProbability(Math.abs(zScore))) * 2; } else {//w w w . j a va 2s. com normalPValue = 1 - norm.cumulativeProbability(Math.abs(zScore)); } }
From source file:com.example.PJS.java
public static double PDF(double z) { NormalDistribution nD = new NormalDistribution(); double pdf;//from w ww.j a v a 2 s . c o m pdf = nD.density(z); return pdf; }
From source file:com.itemanalysis.psychometrics.polycor.PolychoricLogLikelihoodTwoStep.java
public PolychoricLogLikelihoodTwoStep(double[][] data) { this.data = data; nrow = data.length;// w w w .j a va2 s. c o m ncol = data[0].length; alpha = new double[nrow]; beta = new double[ncol]; Pd = new double[nrow][ncol]; Pc = new double[nrow][ncol]; normal = new NormalDistribution(); bvnorm = new BivariateNormalDistributionImpl(); computeThresholds(); }
From source file:com.qaant.optionModels.QBlackScholes.java
@Override //public void runModel(){ public void run() { pModelName = "Black-Scholes QAANT"; modelNumber = 1;//from w w w. java 2 s.c o m 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.qaant.threadModels.TBlackScholes.java
private void opcionConVida() { tipoEjercicio = EUROPEAN;//ww w . j av a 2s. c o 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:com.itemanalysis.psychometrics.scaling.NormalizedScore.java
/** * For r number of score levels between min and max (as defined in PercentileRank), * inclusive, this method returns a r x 2 array with integer based scores in first * column and normalized scores in the second column. This method is useful when * only the raw scores and corresponding normalized scores are needed. * * @return two-way array of raw scores and normalized scores. *//*from w w w.j av a2s. c o m*/ public double[][] evaluate(PercentileRank prank, DefaultLinearTransformation linear) { this.prank = prank; NormalDistribution normal = new NormalDistribution(); double[][] pr = prank.evaluate(); double p = 0.0; double q = 0.0; for (int i = 0; i < pr.length; i++) { p = pr[i][1] / 100; q = normal.inverseCumulativeProbability(p); pr[i][1] = linear.transform(q); } return pr; }
From source file:io.druid.query.aggregation.teststats.PvaluefromZscorePostAggregator.java
private double cumulativeProbability(double x) { try {/*from w w w. jav a2 s . co m*/ NormalDistribution normDist = new NormalDistribution(); return normDist.cumulativeProbability(x); } catch (IllegalArgumentException ex) { return Double.NaN; } }
From source file:com.mapr.synth.samplers.RandomWalkSamplerTest.java
@Test public void testBasics() throws IOException { // this sampler has four variables // g1 is gamma distributed with alpha = 0.2, beta = 0.2 // v1 is unit normal // v2 is normal with mean = 0, sd = 2 // v3 is gamma-normal with dof=2, mean = 0. SchemaSampler s = new SchemaSampler( Resources.asCharSource(Resources.getResource("schema015.json"), Charsets.UTF_8).read()); TDigest tdG1 = new AVLTreeDigest(500); TDigest tdG2 = new AVLTreeDigest(500); TDigest td1 = new AVLTreeDigest(500); TDigest td2 = new AVLTreeDigest(500); TDigest td3 = new AVLTreeDigest(500); double x1 = 0; double x2 = 0; double x3 = 0; for (int i = 0; i < 1000000; i++) { JsonNode r = s.sample();/* www . j av a2 s.c om*/ tdG1.add(r.get("g1").asDouble()); tdG2.add(r.get("g2").asDouble()); double step1 = r.get("v1").get("step").asDouble(); td1.add(step1); x1 += step1; assertEquals(x1, r.get("v1").get("value").asDouble(), 0); assertEquals(x1, r.get("v1-bare").asDouble(), 0); double step2 = r.get("v2").get("step").asDouble(); td2.add(step2); x2 += step2; assertEquals(x2, r.get("v2").get("value").asDouble(), 0); double step3 = r.get("v3").get("step").asDouble(); td3.add(step3); x3 += step3; assertEquals(x3, r.get("v3").get("value").asDouble(), 0); } // now compare against reference distributions to test accuracy of the observed step distributions NormalDistribution normalDistribution = new NormalDistribution(); GammaDistribution gd1 = new GammaDistribution(0.2, 5); GammaDistribution gd2 = new GammaDistribution(1, 1); TDistribution tDistribution = new TDistribution(2); for (double q : new double[] { 0.001, 0.01, 0.1, 0.2, 0.5, 0.8, 0.9, 0.99, 0.99 }) { double uG1 = gd1.cumulativeProbability(tdG1.quantile(q)); assertEquals(q, uG1, (1 - q) * q * 10e-2); double uG2 = gd2.cumulativeProbability(tdG2.quantile(q)); assertEquals(q, uG2, (1 - q) * q * 10e-2); double u1 = normalDistribution.cumulativeProbability(td1.quantile(q)); assertEquals(q, u1, (1 - q) * q * 10e-2); double u2 = normalDistribution.cumulativeProbability(td2.quantile(q) / 2); assertEquals(q, u2, (1 - q) * q * 10e-2); double u3 = tDistribution.cumulativeProbability(td3.quantile(q)); assertEquals(q, u3, (1 - q) * q * 10e-2); } }
From source file:com.qaant.optionModels.QWhaley.java
private void wWhaley() { pModelName = "Whaley QAANT"; modelNumber = 2;//from w w w.ja v a 2 s . c om tipoEjercicio = AMERICAN; // 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 double xx; switch (tipoContrato) { case STOCK: q = dividendRate; b = rate; break; case FUTURES: q = rate; b = 0; break; } double vlt2 = volatModel * volatModel; double VltSqrDayYear = volatModel * sqrDayYear; double h = 1 - z; //descuento para valor presente double alfa = 2 * rate / vlt2; double beta = 2 * (b - q) / vlt2; double lambda = (-(beta - 1) + cpFlag * Math.sqrt((beta - 1) * (beta - 1) + 4 * alfa / h)) / 2; double eex = Math.exp(-q * dayYear);//descuento por dividendos double s1 = strike; double zz = 1 / Math.sqrt(2 * Math.PI); double zerror = 1; do { double d1 = (Math.log(s1 / strike) + ((rate - q) + vlt2 / 2) * dayYear) / VltSqrDayYear; xx = (1 - eex * new NormalDistribution().cumulativeProbability(cpFlag * d1)); double corr = s1 / lambda * xx; QBlackScholes option = new QBlackScholes(tipoContrato, s1, volatModel, dividendRate, callPut, strike, daysToExpiration, rate, 0); double mBlackScholes = option.getPrima(); double rhs = mBlackScholes + cpFlag * corr; double lhs = cpFlag * (s1 - strike); zerror = lhs - rhs; double nd1 = zz * Math.exp(-0.5 * d1 * d1); //standard normal prob? double slope = cpFlag * (1 - 1 / lambda) * xx + 1 / lambda * (eex * nd1) * 1 / VltSqrDayYear; s1 = s1 - zerror / slope; } while (Math.abs(zerror) > 0.000001); double a = cpFlag * s1 / lambda * xx; switch (callPut) { case CALL: //Call if (underlyingValue >= s1) { prima = underlyingValue - strike; } else { prima += a * Math.pow((underlyingValue / s1), lambda); } break; case PUT: //Put if (underlyingValue <= s1) { prima = strike - underlyingValue; } else { prima += a * Math.pow((underlyingValue / s1), lambda); } //prima=10.1; break; } }