Package cern.jet.random.engine

Examples of cern.jet.random.engine.RandomEngine


    }

    @Test
    public void testGeometricDistribution() {
        ConcurrentStreamSummary<Integer> vs = new ConcurrentStreamSummary<Integer>(10);
        RandomEngine re = RandomEngine.makeDefault();

        for (int i = 0; i < NUM_ITERATIONS; i++) {
            int z = Distributions.nextGeometric(0.25, re);
            vs.offer(z);
        }
View Full Code Here


        assertTrue(tippyTop > -15 && tippyTop < 15);
    }

    @Test
    public void testZipfianDistribution() {
        RandomEngine re = RandomEngine.makeDefault();

        for (int i = 0; i < NUM_ITERATIONS; i++) {
            int z = Distributions.nextZipfInt(1.2D, re);
            vs.offer(z);
        }
View Full Code Here

        assertTrue(tippyTop < 3);
    }

    @Test
    public void testGeometricDistribution() {
        RandomEngine re = RandomEngine.makeDefault();

        for (int i = 0; i < NUM_ITERATIONS; i++) {
            int z = Distributions.nextGeometric(0.25, re);
            vs.offer(z);
        }
View Full Code Here

    @Test
    public void testRandomEngine() {
        int[] maxcounts = new int[10];
        int[] counts = new int[20];

        RandomEngine re = RandomEngine.makeDefault();

        for (int i = 0; i < NUM_ITERATIONS; i++) {
//            int z = Distributions.nextZipfInt(1.2D, re);
            int z = Distributions.nextGeometric(0.25, re);
            if (z > Integer.MAX_VALUE - 9) {
View Full Code Here

public class QDigestTest {

    @Test
    public void testComprehensiveOnMixture() {
        RandomEngine r = new MersenneTwister64(0);
        Normal[] dists = new Normal[]{
                new Normal(100, 50, r),
                new Normal(150, 20, r),
                new Normal(500, 300, r),
                new Normal(10000, 10000, r),
View Full Code Here

    super(seed, MODEL, weightingFunction);
  }

  @Override
  protected DoubleMatrix1D getGlobalStart(final double forward, final double[] strikes, final double expiry, final double[] impliedVols) {
    final RandomEngine random = getRandom();
    final DoubleMatrix1D fitP = getPolynomialFit(forward, strikes, impliedVols);

    final double a = fitP.getEntry(0);
    final double b = fitP.getEntry(1);
    final double c = fitP.getEntry(2);

    if (Math.abs(b) < 1e-3 && Math.abs(c) < 1e-3) { //almost flat smile
      final double theta = Math.PI / 2 - 0.01;
      return new DoubleMatrix1D(a, 0.01, theta, theta);
    }
    final double theta = Math.PI / 2 * random.nextDouble();
    return new DoubleMatrix1D(a * (0.8 + 0.4 * random.nextDouble()), a * 0.5 * random.nextDouble(), theta, theta);
  }
View Full Code Here

    return _externalBeta;
  }

  @Override
  protected DoubleMatrix1D getGlobalStart(final double forward, final double[] strikes, final double expiry, final double[] impliedVols) {
    final RandomEngine random = getRandom();
    final DoubleMatrix1D fitP = getPolynomialFit(forward, strikes, impliedVols);
    final double a = fitP.getEntry(0);
    final double b = fitP.getEntry(1);
    final double c = fitP.getEntry(2);

    double alpha, beta, rho, nu;
    //TODO make better use of the polynomial fit information
    if (_externalBeta) {
      beta = _beta;
    } else {
      beta = random.nextDouble();
    }

    if (a <= 0.0) { //negative ATM vol - can get this if fit points are far from ATM
      double sum = 0;
      final int n = strikes.length;
      for (int i = 0; i < n; i++) {
        sum += impliedVols[i];
      }
      final double approxAlpha = sum / n * Math.pow(forward, 1 - beta);
      alpha = (random.nextDouble() + 0.5) * approxAlpha;
      rho = random.nextDouble() - 0.5;
      nu = 0.5 * random.nextDouble() + 0.1;
      return new DoubleMatrix1D(alpha, beta, rho, nu);
    }
    if (Math.abs(b) < 1e-3 && Math.abs(c) < 1e-3) { //almost flat smile
      if (_externalBeta && _beta != 1.0) {
        s_logger.warn("Smile almost flat. Cannot use beta = ", +_beta + " so extenal value ignored, and beta = 1.0 used");
      }
      return new DoubleMatrix1D(a, 1.0, 0.0, Math.max(0.0, 4 * c));
    }
    final double approxAlpha = a * Math.pow(forward, 1 - beta);
    alpha = (random.nextDouble() + 0.5) * approxAlpha;
    rho = random.nextDouble() - 0.5;
    nu = (random.nextDouble() + 0.5) * Math.max(0.0, 4 * c);
    return new DoubleMatrix1D(alpha, beta, rho, nu);
  }
View Full Code Here

   * @param seed The seed
   */
  public VarianceSwapPureMonteCarloCalculator(final int seed) {
    _useAntithetics = true;
    _calculateVariance = true;
    final RandomEngine random = new MersenneTwister64(seed);
    _norm = new NormalDistribution(0, 1.0, random);
  }
View Full Code Here

   * @param calculateVariance true if the variance of the result is to be calculated
   */
  public VarianceSwapPureMonteCarloCalculator(final int seed, final boolean useAntithetics, final boolean calculateVariance) {
    _useAntithetics = useAntithetics;
    _calculateVariance = calculateVariance;
    final RandomEngine random = new MersenneTwister64(seed);
    _norm = new NormalDistribution(0, 1.0, random);
  }
View Full Code Here

   * @param seed The seed
   */
  public EquityVarianceSwapMonteCarloCalculator(final int seed) {
    _useAntithetics = true;
    _calculateVariance = true;
    final RandomEngine random = new MersenneTwister64(seed);
    _norm = new NormalDistribution(0, 1.0, random);
  }
View Full Code Here

TOP

Related Classes of cern.jet.random.engine.RandomEngine

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.