Package org.jquantlib.math.integrals

Examples of org.jquantlib.math.integrals.TabulatedGaussLegendre


     *                Second variable
     * @return BVN
     */
    @Override
    public double op(final double x, final double y) {
        final TabulatedGaussLegendre gaussLegendreQuad = new TabulatedGaussLegendre(20);

        if (Math.abs(correlation) < 0.3) {
            gaussLegendreQuad.setOrder(6);
        } else if (Math.abs(correlation) < 0.75) {
            gaussLegendreQuad.setOrder(12);
        }

        final double h = -x;
        double k = -y;
        double hk = h * k;
        double bvn = 0.0;

        if (Math.abs(correlation) < 0.925) {
            if (Math.abs(correlation) > 0) {
                final double asr = Math.asin(correlation);
                final Eqn3 f = new Eqn3(h, k, asr);
                bvn = gaussLegendreQuad.evaluate(f);
                bvn *= asr * (0.25 / Math.PI);
            }
            bvn += cumnorm.op(-h) * cumnorm.op(-k);
        } else {
            if (correlation < 0) {
                k *= -1;
                hk *= -1;
            }
            if (Math.abs(correlation) < 1) {
                final double Ass = (1 - correlation) * (1 + correlation);
                double a = Math.sqrt(Ass);
                final double bs = (h - k) * (h - k);
                final double c = (4 - hk) / 8;
                final double d = (12 - hk) / 16;
                final double asr = -(bs / Ass + hk) / 2;
                if (asr > -100) {
                    bvn = a * Math.exp(asr) * (1 - c * (bs - Ass) * (1 - d * bs / 5) / 3 + c * d * Ass * Ass / 5);
                }
                if (-hk < 100) {
                    final double B = Math.sqrt(bs);
                    bvn -= Math.exp(-hk / 2) * Constants.M_SQRT2PI * cumnorm.op(-B / a) * B
                    * (1 - c * bs * (1 - d * bs / 5) / 3);
                }
                a /= 2;
                final Eqn6 f = new Eqn6(a, c, d, bs, hk);
                bvn += gaussLegendreQuad.evaluate(f);
                bvn /= (-2.0 * Math.PI);
            }

            if (correlation > 0) {
                bvn += cumnorm.op(-Math.max(h, k));
View Full Code Here


     *                Second variable
     * @return BVN
     */
    @Override
    public double op(final double x, final double y) {
        final TabulatedGaussLegendre gaussLegendreQuad = new TabulatedGaussLegendre(20);

        if (Math.abs(correlation) < 0.3) {
            gaussLegendreQuad.setOrder(6);
        } else if (Math.abs(correlation) < 0.75) {
            gaussLegendreQuad.setOrder(12);
        }

        final double h = -x;
        double k = -y;
        double hk = h * k;
        double bvn = 0.0;

        if (Math.abs(correlation) < 0.925) {
            if (Math.abs(correlation) > 0) {
                final double asr = Math.asin(correlation);
                final Eqn3 f = new Eqn3(h, k, asr);
                bvn = gaussLegendreQuad.evaluate(f);
                bvn *= asr * (0.25 / Math.PI);
            }
            bvn += cumnorm.op(-h) * cumnorm.op(-k);
        } else {
            if (correlation < 0) {
                k *= -1;
                hk *= -1;
            }
            if (Math.abs(correlation) < 1) {
                final double Ass = (1 - correlation) * (1 + correlation);
                double a = Math.sqrt(Ass);
                final double bs = (h - k) * (h - k);
                final double c = (4 - hk) / 8;
                final double d = (12 - hk) / 16;
                final double asr = -(bs / Ass + hk) / 2;
                if (asr > -100) {
                    bvn = a * Math.exp(asr) * (1 - c * (bs - Ass) * (1 - d * bs / 5) / 3 + c * d * Ass * Ass / 5);
                }
                if (-hk < 100) {
                    final double B = Math.sqrt(bs);
                    bvn -= Math.exp(-hk / 2) * Constants.M_SQRT2PI * cumnorm.op(-B / a) * B
                    * (1 - c * bs * (1 - d * bs / 5) / 3);
                }
                a /= 2;
                final Eqn6 f = new Eqn6(a, c, d, bs, hk);
                bvn += gaussLegendreQuad.evaluate(f);
                bvn /= (-2.0 * Math.PI);
            }

            if (correlation > 0) {
                bvn += cumnorm.op(-Math.max(h, k));
View Full Code Here

    checkSingleTabulated(new Fourth(), "f(x)=x^4", 2.0/5.0, 1.0e-13);
  }

  public void checkSingleTabulated(final Ops.DoubleOp f, final String tag, final double expected, final double tolerance) {
      final int order[] = { 6, 7, 12, 20 };
      final TabulatedGaussLegendre quad = new TabulatedGaussLegendre();
      for (final int element : order) {
          quad.setOrder(element);
          final double realised = quad.evaluate(f);
          if (Math.abs(realised-expected) > tolerance)
            fail(" integrating " + tag + "\n"
                        + "    order " + element + "\n"
                        + "    realised: " + realised + "\n"
                        + "    expected: " + expected);
View Full Code Here

TOP

Related Classes of org.jquantlib.math.integrals.TabulatedGaussLegendre

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.