Package com.opengamma.analytics.math.number

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


    final ComplexNumber denom = subtract(_kappa, add(c2, c1));
    return divide(num, denom);
  }

  private ComplexNumber d(final ComplexNumber u) {
    ComplexNumber c1 = subtract(multiply(u, new ComplexNumber(0, _rho * _omega)), _kappa);
    c1 = multiply(c1, c1);
    final ComplexNumber c2 = multiply(u, new ComplexNumber(0, _omega * _omega));
    ComplexNumber c3 = multiply(u, _omega);
    c3 = multiply(c3, c3);
    final ComplexNumber c4 = add(add(c1, c2), c3);
    return multiply(1, sqrt(c4));
  }
View Full Code Here


    final Function1D<ComplexNumber, ComplexNumber> function = _ce.getFunction(t);
    return new Function1D<ComplexNumber, ComplexNumber>() {

      @Override
      public ComplexNumber evaluate(final ComplexNumber z) {
        final ComplexNumber num = exp(function.evaluate(z));
        final ComplexNumber denom = multiply(z, add(z, ComplexNumber.I));
        final ComplexNumber res = multiply(-1.0, divide(num, denom));
        return res;
      }
    };
  }
View Full Code Here

    final Function1D<ComplexNumber, ComplexNumber> timeChangeFunction = _timeChange.getFunction(t);

    return new Function1D<ComplexNumber, ComplexNumber>() {
      @Override
      public ComplexNumber evaluate(final ComplexNumber u) {
        final ComplexNumber z = ComplexMathUtils.multiply(MINUS_I, baseFunction.evaluate(u));
        return timeChangeFunction.evaluate(z);
      }
    };
  }
View Full Code Here

    for (int i = n - upperPadOutSize; i < n; i++) {
      z[i] = ZERO;
    }

    ComplexNumber u = new ComplexNumber(0.0, -(1 + alpha));
    final int offset = halfN - 1;
    z[offset] = func.evaluate(u);

    for (int i = 1; i < m; i++) {
      u = new ComplexNumber(i * delta, -(1 + alpha));
      final ComplexNumber f = func.evaluate(u);
      z[offset + i] = f;
      z[offset - i] = ComplexMathUtils.conjugate(f); //TODO the FFT should take care of this
    }
    return z;
  }
View Full Code Here

    }
    return z;
  }

  private double getReducedPrice(final ComplexNumber x, final double alpha, final double delta, final double k, final double a, final boolean isCall) {
    final ComplexNumber temp = ComplexMathUtils.multiply(ComplexMathUtils.exp(new ComplexNumber(-alpha * k, -k * a)), x);
    final double y = delta * temp.getReal() / 2 / Math.PI;
    if (isCall) {
      if (alpha > 0.0) {
        return y;
      } else if (alpha < -1.0) {
        return y + 1 - Math.exp(k);
View Full Code Here

    final Function1D<ComplexNumber, ComplexNumber> callFunction = callFT.getFunction(T);
    final Function1D<Double, Double> f = new Function1D<Double, Double>() {

      @Override
      public Double evaluate(final Double x) {
        final ComplexNumber z = new ComplexNumber(x, -1.0 - alpha);
        final ComplexNumber u = callFunction.evaluate(z);
        return u.getReal();
      }
    };

    final RungeKuttaIntegrator1D integrator = new RungeKuttaIntegrator1D();
    final double integral = integrator.integrate(f, 0.0, 1000.0) / Math.PI;
View Full Code Here

  public void testEuropeanCallFT() {

    final Function1D<ComplexNumber, ComplexNumber> callFT = new EuropeanCallFourierTransform(CEF).getFunction(T);
    for (int i = 0; i < 101; i++) {
      final double x = -10.0 + 20.0 * i / 100;
      final ComplexNumber z = new ComplexNumber(x, -1.5);
      @SuppressWarnings("unused")
      final ComplexNumber u = callFT.evaluate(z);
      //System.out.println(x + "\t" + u.getReal() + "\t" + u.getImaginary());
    }

  }
View Full Code Here

    testSensitivitiesAtRandomPoints(EXPONENT.withRho(1));
  }

  private void testSensitivitiesAtRandomPoints(final HestonCharacteristicExponent ce) {
    double t;
    ComplexNumber z;
    for (int i = 0; i < 100; i++) {
      t = 10 * RANDOM.nextDouble();
      z = new ComplexNumber(8 * RANDOM.nextDouble() - 4, 4 * RANDOM.nextDouble() - 2);
      testSensitivities(ce, z, t);
    }
  }
View Full Code Here

  }

  @Test
  public void testSensitivities2() {
    double t = 2.5;
    ComplexNumber z = new ComplexNumber(2.3, -0.6);
    ComplexNumber[] fdSense = finiteDifferenceSensitivity(EXPONENT, z, t);
    ComplexNumber[] sense = EXPONENT.getCharacteristicExponentAdjointDebug(z, t);
    ComplexNumber[] senseConj = EXPONENT.getCharacteristicExponentAdjointDebug(multiply(-1.0, conjugate(z)), t);
    for (int i = 0; i < 6; i++) {
      //      System.out.println(fdSense[i] + "\t" + sense[i] + "\t"+senseConj[i]);
View Full Code Here

    ComplexNumber[] res = new ComplexNumber[6];
    res[0] = heston.getFunction(t).evaluate(z);
    //bump kappa
    final double kappa = heston.getKappa();
    HestonCharacteristicExponent hestonT = heston.withKappa(kappa + eps);
    ComplexNumber up = hestonT.getFunction(t).evaluate(z);
    if (kappa > eps) {
      hestonT = heston.withKappa(kappa - eps);
      ComplexNumber down = hestonT.getFunction(t).evaluate(z);
      res[1] = divide(subtract(up, down), 2 * eps);
    } else {
      hestonT = heston.withKappa(kappa + 2 * eps);
      ComplexNumber up2 = hestonT.getFunction(t).evaluate(z);
      res[1] = add(multiply(-1.5 / eps, res[0]), multiply(2 / eps, up), multiply(-0.5 / eps, up2));
    }
    //bump theta
    final double theta = heston.getTheta();
    hestonT = heston.withTheta(theta + eps);
    up = hestonT.getFunction(t).evaluate(z);
    if (theta > eps) {
      hestonT = heston.withTheta(theta - eps);
      ComplexNumber down = hestonT.getFunction(t).evaluate(z);
      res[2] = divide(subtract(up, down), 2 * eps);
    } else {
      hestonT = heston.withTheta(theta + 2 * eps);
      ComplexNumber up2 = hestonT.getFunction(t).evaluate(z);
      res[2] = add(multiply(-1.5 / eps, res[0]), multiply(2 / eps, up), multiply(-0.5 / eps, up2));
    }
    //bump vol0
    final double vol0 = heston.getVol0();
    hestonT = heston.withVol0(vol0 + eps);
    up = hestonT.getFunction(t).evaluate(z);
    if (vol0 > eps) {
      hestonT = heston.withVol0(vol0 - eps);
      ComplexNumber down = hestonT.getFunction(t).evaluate(z);
      res[3] = divide(subtract(up, down), 2 * eps);
    } else {
      hestonT = heston.withVol0(vol0 + 2 * eps);
      ComplexNumber up2 = hestonT.getFunction(t).evaluate(z);
      res[3] = add(multiply(-1.5 / eps, res[0]), multiply(2 / eps, up), multiply(-0.5 / eps, up2));
    }
    //bump omega
    final double omega = heston.getOmega();
    hestonT = heston.withOmega(omega + eps);
    up = hestonT.getFunction(t).evaluate(z);
    if (omega > eps) {
      hestonT = heston.withOmega(omega - eps);
      ComplexNumber down = hestonT.getFunction(t).evaluate(z);
      res[4] = divide(subtract(up, down), 2 * eps);
    } else {
      hestonT = heston.withOmega(omega + 2 * eps);
      ComplexNumber up2 = hestonT.getFunction(t).evaluate(z);
      res[4] = add(multiply(-1.5 / eps, res[0]), multiply(2 / eps, up), multiply(-0.5 / eps, up2));
    }
    //bump rho
    final double rho = heston.getRho();
    if (rho + 1 < eps) {
      hestonT = heston.withRho(rho + eps);
      up = hestonT.getFunction(t).evaluate(z);
      hestonT = heston.withRho(rho + 2 * eps);
      ComplexNumber up2 = hestonT.getFunction(t).evaluate(z);
      res[5] = add(multiply(-1.5 / eps, res[0]), multiply(2 / eps, up), multiply(-0.5 / eps, up2));
    } else if (1 - rho < eps) {
      hestonT = heston.withRho(rho - eps);
      ComplexNumber down = hestonT.getFunction(t).evaluate(z);
      hestonT = heston.withRho(rho - 2 * eps);
      ComplexNumber down2 = hestonT.getFunction(t).evaluate(z);
      res[5] = add(multiply(0.5 / eps, down2), multiply(-2 / eps, down), multiply(1.5 / eps, res[0]));
    } else {
      hestonT = heston.withRho(rho + eps);
      up = hestonT.getFunction(t).evaluate(z);
      hestonT = heston.withRho(rho - eps);
      ComplexNumber down = hestonT.getFunction(t).evaluate(z);
      res[5] = divide(subtract(up, down), 2 * eps);
    }
    return res;
  }
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.