Package com.opengamma.analytics.math.number

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


  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

  @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

    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

    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

    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

  @Override
  public ComplexNumber getValue(ComplexNumber u, double t) {
    Validate.isTrue(t > 0.0, "t > 0");
    Validate.notNull(u, "u");
    final ComplexNumber temp = multiply(_sigma, u);
    final ComplexNumber res = add(multiply(u, new ComplexNumber(0, _mu)), multiply(-0.5, multiply(temp, temp)));
    return multiply(t, res);
  }
View Full Code Here

  @Override
  public ComplexNumber[] getCharacteristicExponentAdjoint(final ComplexNumber u, final double t) {
    final ComplexNumber[] res = new ComplexNumber[3];
    res[0] = getValue(u, t);
    res[1] = multiply(u, new ComplexNumber(0.0, t));
    res[2] = multiply(-_sigma * t, square(u));
    return res;
  }
View Full Code Here

   */
  @Override
  public Function1D<ComplexNumber, ComplexNumber> getFunction(final double t) {

    final Function1D<ComplexNumber, ComplexNumber> func = _base.getFunction(t);
    final ComplexNumber temp = func.evaluate(MINUS_I);
    Validate.isTrue(Math.abs(temp.getImaginary()) < 1e-12, "problem with CharacteristicExponent");
    final ComplexNumber w = new ComplexNumber(0, -temp.getReal());

    return new Function1D<ComplexNumber, ComplexNumber>() {
      @Override
      public ComplexNumber evaluate(final ComplexNumber u) {
        return add(func.evaluate(u), multiply(w, u));
View Full Code Here

    };
  }

  @Override
  public ComplexNumber getValue(ComplexNumber u, double t) {
    final ComplexNumber temp = _base.getValue(MINUS_I, t);
    Validate.isTrue(Math.abs(temp.getImaginary()) < 1e-12, "problem with CharacteristicExponent");
    final ComplexNumber w = new ComplexNumber(0, -temp.getReal());
    return add(_base.getValue(u, t), multiply(w, u));
  }
View Full Code Here

TOP

Related Classes of com.opengamma.analytics.math.number.ComplexNumber

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.