Package com.opengamma.analytics.math.number

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


    return new Function1D<ComplexNumber, ComplexNumber[]>() {

      @Override
      public ComplexNumber[] evaluate(ComplexNumber u) {
        ComplexNumber[] uncorrected = func.evaluate(u);
        ComplexNumber minusUi = multiply(MINUS_I, u);
        ComplexNumber[] res = new ComplexNumber[temp.length];
        for (int i = 0; i < temp.length; i++) {
          res[i] = add(uncorrected[i], multiply(minusUi, temp[i]));
        }
        return res;
View Full Code Here


  @Override
  public ComplexNumber[] getCharacteristicExponentAdjoint(ComplexNumber u, double t) {
    ComplexNumber[] temp = _base.getCharacteristicExponentAdjoint(MINUS_I, t);
    ComplexNumber[] uncorrected = _base.getCharacteristicExponentAdjoint(u, t);
    ComplexNumber minusUi = multiply(MINUS_I, u);
    ComplexNumber[] res = new ComplexNumber[temp.length];
    for (int i = 0; i < temp.length; i++) {
      res[i] = add(uncorrected[i], multiply(minusUi, temp[i]));
    }
    return res;
View Full Code Here

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

    ComplexNumber u = new ComplexNumber(0.0, -(1 + alpha));
    final int offset = halfN - 1;
    ComplexNumber[] f = ajointFunc.evaluate(u);
    ComplexNumber num = exp(f[0]);
    ComplexNumber denom = multiply(u, subtract(MINUS_I, u));
    ComplexNumber v = divide(num, denom);
    z[0][offset] = v;
    for (int j = 1; j < size; j++) {
      ComplexNumber temp = multiply(v, f[j]);
      z[j][offset] = temp;
    }
    for (int i = 1; i < m; i++) {
      u = new ComplexNumber(i * delta, -(1 + alpha));
      f = ajointFunc.evaluate(u);
      num = exp(f[0]);
      denom = multiply(u, subtract(MINUS_I, u));
      v = divide(num, denom);
      z[0][offset + i] = v;
      z[0][offset - i] = ComplexMathUtils.conjugate(v);
      for (int j = 1; j < size; j++) {
        ComplexNumber temp = multiply(v, f[j]);
        z[j][offset + i] = temp;
        z[j][offset - i] = ComplexMathUtils.conjugate(temp); //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

    }
    return y + Math.exp(k);
  }

  private double getReducedGreek(final ComplexNumber x, final double alpha, final double delta, final double k, final double a) {
    final ComplexNumber temp = ComplexMathUtils.multiply(ComplexMathUtils.exp(new ComplexNumber(-alpha * k, -k * a)), x);
    final double y = delta * temp.getReal() / 2 / Math.PI;
    return y;
  }
View Full Code Here

  }

  @Override
  public ComplexNumber getValue(ComplexNumber u, double t) {
    final double r2 = t * _r2;
    final ComplexNumber complexR3 = new ComplexNumber(r2 * _r3);
    if (u.getReal() == 0.0) {
      if (u.getImaginary() == 0.0) {
        return ZERO;
      }
      if (u.getImaginary() == -1.0) {
        return complexR3;
      }
    }
    final ComplexNumber iu = multiply(I, u);
    final ComplexNumber c1 = pow(subtract(_m, iu), _y);
    final ComplexNumber c2 = pow(add(_g, iu), _y);
    final ComplexNumber c3 = add(c1, c2);
    final ComplexNumber c4 = subtract(c3, _r1);
    final ComplexNumber res = multiply(r2, c4);
    return res;
  }
View Full Code Here

  public double solve(final Function1D<ComplexNumber, ComplexNumber> psi, final double alpha, final double tol) {
    Validate.notNull(psi, "psi null");
    Validate.isTrue(alpha != 0.0 && alpha != -1.0, "alpha cannot be -1 or 0");
    Validate.isTrue(tol > 0.0, "need tol > 0");

    final double k = Math.log(tol) + Math.log(ComplexMathUtils.mod(psi.evaluate(new ComplexNumber(0.0, -(1 + alpha)))));
    final Function1D<Double, Double> f = new Function1D<Double, Double>() {
      @Override
      public Double evaluate(final Double x) {
        final ComplexNumber z = new ComplexNumber(x, -(1 + alpha));
        return Math.log(ComplexMathUtils.mod(psi.evaluate(z))) - k;
      }
    };
    double[] range = null;
    try {
View Full Code Here

    return new Function1D<ComplexNumber, ComplexNumber>() {

      @Override
      public ComplexNumber evaluate(final ComplexNumber u) {
        Validate.notNull(u, "u");
        final ComplexNumber psi = baseFunc.evaluate(u);
        final ComplexNumber temp = divFunc.evaluate(u);
        final ComplexNumber temp2 = log(temp); //don't like taking logs - bad things happen
        final ComplexNumber res = add(psi, temp2);
        return res;

      }

    };
View Full Code Here

    }
    return new Function1D<Double, Double>() {

      @Override
      public Double evaluate(final Double x) {
        @SuppressWarnings("synthetic-access")
        final ComplexNumber res = getIntegrand(x, characteristicFunction, gaussianFunction, k);
        return res.getReal();
      }
    };
  }
View Full Code Here

    };
  }

  private ComplexNumber getIntegrand(final double x, final Function1D<ComplexNumber, ComplexNumber> ce, final Function1D<ComplexNumber, ComplexNumber> gaussian,
      final double k) {
    final ComplexNumber z = new ComplexNumber(x, -1 - _alpha);
    final ComplexNumber num1 = exp(add(new ComplexNumber(0, -x * k), ce.evaluate(z)));
    final ComplexNumber num2 = gaussian == null ? new ComplexNumber(0.0) : exp(add(new ComplexNumber(0, -x * k), gaussian.evaluate(z)));
    final ComplexNumber denom = multiply(z, subtract(MINUS_I, z));
    final ComplexNumber res = divide(subtract(num1, num2), denom);
    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.