Examples of ComplexNumber


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

  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

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

    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

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

    }
    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

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

    };
  }

  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

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

  }
 
  @Override
  public ComplexNumber getValue(ComplexNumber u, double t) {
    if (u.getReal() == 0.0 && u.getImaginary() == 0.0) {
      return new ComplexNumber(0.0);
    }

    final ComplexNumber ui = multiply(I, u);

    //handle small lambda properly
    if (2 * mod(u) * _lambda * _lambda / _kappa / _kappa < 1e-6) {
      final double d = _theta * t + (1 - _theta) * (1 - Math.exp(-_kappa * t)) / _kappa;
      return multiply(d, ui);
    }

    ComplexNumber temp = subtract(_kappa * _kappa, multiply(2 * _lambda * _lambda, ui));
    final ComplexNumber gamma = sqrt(temp);
    final ComplexNumber gammaHalfT = multiply(gamma, t / 2.0);
    temp = divide(multiply(2, ui), add(_kappa, divide(gamma, TrigonometricFunctionUtils.tanh(gammaHalfT))));
    final ComplexNumber kappaOverGamma = divide(_kappa, gamma);
    final double power = 2 * _kappa * _theta / _lambda / _lambda;
    final ComplexNumber res = add(multiply(power, subtract(_kappa * t / 2, getLogCoshSinh(gammaHalfT, kappaOverGamma))), temp);
    return res;
  }
View Full Code Here

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

    return res;
  }

  // ln(cosh(a) + bsinh(a)
  private ComplexNumber getLogCoshSinh(final ComplexNumber a, final ComplexNumber b) {
    final ComplexNumber temp = add(TrigonometricFunctionUtils.cosh(a), multiply(b, TrigonometricFunctionUtils.sinh(a)));
    return log(temp);
  }
View Full Code Here

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

    return new Function1D<Double, Double>() {

      @Override
      public Double evaluate(Double x) {
        final ComplexNumber z = new ComplexNumber(x, -1 - alpha);
        ComplexNumber[] ajoint = ajointFunctions.evaluate(z);
        ComplexNumber num = exp(add(new ComplexNumber(0, -x * kappa), ajoint[0]));
        if (index > 0) {
          num = multiply(num, ajoint[index]);
        }
        final ComplexNumber denom = multiply(z, subtract(MINUS_I, z));
        final ComplexNumber res = divide(num, denom);
        return res.getReal();
      }
    };

  }
View Full Code Here

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

      return ZERO;
    }

    //non-stochastic vol limit
    if (_omega == 0.0 || mod(multiply(multiply(_omega / _kappa, u), add(I, u))) < 1e-6) {
      final ComplexNumber z = multiply(u, add(I, u));
      if (_kappa * t < 1e-6) {
        return multiply(-_vol0 / 2 * t, z);
      }
      final double var = _theta * t + (_vol0 - _theta) * (1 - Math.exp(-_kappa * t)) / _kappa;
      return multiply(-var / 2, z);
    }

    final ComplexNumber c = getC(u, t);
    final ComplexNumber dv0 = multiply(_vol0, getD(u, t));
    return add(c, dv0);
  }
View Full Code Here

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

    };
  }

  private ComplexNumber[] forwardSweep(final ComplexNumber u, final double t) {
    ComplexNumber[] w = new ComplexNumber[19];
    w[0] = new ComplexNumber(_kappa * _theta / _omega / _omega);
    w[1] = multiply(u, new ComplexNumber(0, _rho * _omega));
    w[2] = subtract(w[1], _kappa);
    w[3] = square(w[2]);
    w[4] = multiply(u, new ComplexNumber(0, _omega * _omega));
    w[5] = square(multiply(u, _omega));
    w[6] = add(w[3], w[4], w[5]);
    w[7] = sqrt(w[6]);
    w[8] = subtract(w[7], w[2]);
    w[9] = multiply(-1.0, add(w[7], w[2]));
View Full Code Here

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

  }

  private ComplexNumber[] backwardsSweep(final ComplexNumber[] w, final double t) {
    final double oneOverOmega2 = 1 / _omega / _omega;
    final ComplexNumber[] wBar = new ComplexNumber[19];
    wBar[18] = new ComplexNumber(1.0); //formal start
    wBar[17] = new ComplexNumber(_vol0); //Suppressing the multiple by wBar18
    wBar[16] = wBar[18];
    wBar[15] = multiply(oneOverOmega2, w[8], wBar[17]);
    wBar[14] = multiply(-2, w[0], wBar[16]);
    wBar[13] = divide(wBar[14], w[13]);
    ComplexNumber temp1 = subtract(1.0, w[10]);
    ComplexNumber temp2 = subtract(w[10], w[12]);
    ComplexNumber temp3 = square(temp2);
    wBar[12] = add(multiply(wBar[15], divide(temp1, temp3)), divide(wBar[13], temp1));
    wBar[11] = multiply(w[0], wBar[16]);
    wBar[10] = add(multiply(divide(subtract(w[12], 1), temp3), wBar[15]), multiply(divide(subtract(w[12], 1), square(temp1)), wBar[13]));
    wBar[9] = subtract(multiply(t, wBar[11]), multiply(divide(w[8], square(w[9])), wBar[10]));
    wBar[8] = add(multiply(oneOverOmega2, w[15], wBar[17]), divide(wBar[10], w[9]));
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.