Examples of ComplexNumber


Examples of com.barrybecker4.common.math.ComplexNumber

    /**
     * @return the fractal value that was set into the model.
     */
    private double computeFractalValueForPosition(int x, int y) {
        ComplexNumber z = algorithm.getComplexPosition(x, y);
        double value = algorithm.getFractalValue(z);
        model.setValue(x, y, value);
        return value;
    }
View Full Code Here

Examples of com.barrybecker4.common.math.ComplexNumber

    }

    @Override
    public double getFractalValue(ComplexNumber initialValue) {

        ComplexNumber z = initialValue;
        int numIterations = 0;

        while (z.getMagnitude() < 2.0 && numIterations <  getMaxIterations()) {
            z = z.power(2).add(initialValue);
            numIterations++;
        }

        return (double) numIterations / getMaxIterations();
    }
View Full Code Here

Examples of com.barrybecker4.common.math.ComplexNumber

    public ComplexNumber getComplexPosition(IntLocation loc) {
        return getComplexPosition(loc.getX(), loc.getY());
    }

    public ComplexNumberRange getRange(Box box)  {
        ComplexNumber firstCorner = getComplexPosition(box.getTopLeftCorner());
        ComplexNumber secondCorner =getComplexPosition(box.getBottomRightCorner());
        return new ComplexNumberRange(firstCorner, secondCorner);
    }
View Full Code Here

Examples of com.barrybecker4.common.math.ComplexNumber

    }

    @Override
    public double getFractalValue(ComplexNumber initialValue) {

        ComplexNumber z = initialValue;
        int numIterations = 0;

        while (z.getMagnitude() < 2.0 && numIterations < getMaxIterations()) {
            z = z.power(2).add(initialValue);
            numIterations++;
        }
        return (double) numIterations / getMaxIterations();
    }
View Full Code Here

Examples of com.opengamma.analytics.math.number.ComplexNumber

  @Test
  public void testCE() {
    for (int i = 0; i < 101; i++) {
      final double x = 10.0 * i / 100.0;
      final ComplexNumber z = new ComplexNumber(x, -(1 + ALPHA));
      final ComplexNumber res1 = NORMAL_CIR.getFunction(T).evaluate(z);
      final ComplexNumber res2 = NORMAL.getFunction(1).evaluate(z);
      final ComplexNumber res3 = HESTON.getFunction(T).evaluate(z);
      assertTrue(Math.abs(res1.getImaginary()) < EPS);
      assertTrue(Math.abs(res2.getImaginary()) < EPS);
      assertTrue(Math.abs(res3.getImaginary()) < EPS);
      assertEquals(res1.getReal(), res3.getReal(), EPS);
    }

  }
View Full Code Here

Examples of com.opengamma.analytics.math.number.ComplexNumber

  private static final MartingaleCharacteristicExponent CEF = new GaussianMartingaleCharacteristicExponent(SIGMA);
  private static final EuropeanCallFourierTransform PSI = new EuropeanCallFourierTransform(CEF);

  @Test
  public void test() {
    ComplexNumber z = new ComplexNumber(0.0, -(1 + ALPHA));
    final Function1D<ComplexNumber, ComplexNumber> f = PSI.getFunction(T);
    final double mod0 = ComplexMathUtils.mod(f.evaluate(z));
    double previous = 0;
    for (int i = 1; i < 101; i++) {
      final double x = 0.0 + 100.0 * i / 100;
      z = new ComplexNumber(x, -(1 + ALPHA));
      final ComplexNumber u = f.evaluate(z);
      assertEquals(u.getImaginary(), 0, 1e-16);
      final double res = Math.log10(ComplexMathUtils.mod(u) / mod0);
      assertTrue(res < previous);
      previous = res;
    }
  }
View Full Code Here

Examples of com.opengamma.analytics.math.number.ComplexNumber

  @Test
  public void testHeston() {
    final MartingaleCharacteristicExponent heston = new HestonCharacteristicExponent(KAPPA, THETA, VOL0, OMEGA, RHO);
    final EuropeanCallFourierTransform psi = new EuropeanCallFourierTransform(heston);
    final Function1D<ComplexNumber, ComplexNumber> f = psi.getFunction(T);
    ComplexNumber z = new ComplexNumber(0.0, -(1 + ALPHA));
    final double mod0 = ComplexMathUtils.mod(f.evaluate(z));
    double previous = 0;
    for (int i = 1; i < 101; i++) {
      final double x = 0.0 + 100.0 * i / 100;
      z = new ComplexNumber(x, -(1 + ALPHA));
      final ComplexNumber u = f.evaluate(z);
      final double res = Math.log10(ComplexMathUtils.mod(u) / mod0);
      assertTrue(res < previous);
      previous = res;
    }
  }
View Full Code Here

Examples of com.opengamma.analytics.math.number.ComplexNumber

    for (int i = 0; i < 101; i++) {
      final double x = -3. + i * 6. / 100.0;
      System.out.print(x + "\t");
      for (int j = 0; j < 101; j++) {
        final double y = -3. + j * 6. / 100.0;
        final ComplexNumber res = heston.getValue(new ComplexNumber(x, y), 0.25);
        System.out.print(res.getReal() + "\t");
      }
      System.out.print("\n");
    }
  }
View Full Code Here

Examples of com.opengamma.analytics.math.number.ComplexNumber

    final EuropeanCallFourierTransform integrand = new EuropeanCallFourierTransform(heston);
    final Function1D<ComplexNumber, ComplexNumber> func = integrand.getFunction(t);

    for (int i = 0; i < 201; i++) {
      final double x = -0. + i * 20. / 200.0;
      final ComplexNumber res = func.evaluate((new ComplexNumber(x, alpha)));
      System.out.println(x + "\t" + res.getReal() + "\t" + res.getImaginary());
    }
  }
View Full Code Here

Examples of com.opengamma.analytics.math.number.ComplexNumber

    final CharacteristicExponent heston = new HestonCharacteristicExponent(kappa, theta, vol0, omega, rho);

    for (int i = 0; i < 201; i++) {
      final double x = 0.0 + 250.0 * i / 200;
      final ComplexNumber z = new ComplexNumber(x, -(1 + alpha));
      final ComplexNumber[] res = heston.getCharacteristicExponentAdjoint(z, t);
      System.out.print(x);
      for (final ComplexNumber re : res) {
        final double value = exp(re).getReal();
        System.out.print("\t" + value);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.