UpperAbramowitzStegun.java

  1. package org.drip.sample.gammaincomplete;

  2. import org.drip.numerical.common.FormatUtil;
  3. import org.drip.service.env.EnvManager;
  4. import org.drip.specialfunction.gamma.EulerIntegralSecondKind;
  5. import org.drip.specialfunction.incompletegamma.GaussContinuedFraction;

  6. /*
  7.  * -*- mode: java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  8.  */

  9. /*!
  10.  * Copyright (C) 2019 Lakshmi Krishnamurthy
  11.  *
  12.  *  This file is part of DROP, an open-source library targeting risk, transaction costs, exposure, margin
  13.  *      calculations, and portfolio construction within and across fixed income, credit, commodity, equity,
  14.  *      FX, and structured products.
  15.  *  
  16.  *      https://lakshmidrip.github.io/DROP/
  17.  *  
  18.  *  DROP is composed of three main modules:
  19.  *  
  20.  *  - DROP Analytics Core - https://lakshmidrip.github.io/DROP-Analytics-Core/
  21.  *  - DROP Portfolio Core - https://lakshmidrip.github.io/DROP-Portfolio-Core/
  22.  *  - DROP Numerical Core - https://lakshmidrip.github.io/DROP-Numerical-Core/
  23.  *
  24.  *  DROP Analytics Core implements libraries for the following:
  25.  *  - Fixed Income Analytics
  26.  *  - Asset Backed Analytics
  27.  *  - XVA Analytics
  28.  *  - Exposure and Margin Analytics
  29.  *
  30.  *  DROP Portfolio Core implements libraries for the following:
  31.  *  - Asset Allocation Analytics
  32.  *  - Transaction Cost Analytics
  33.  *
  34.  *  DROP Numerical Core implements libraries for the following:
  35.  *  - Statistical Learning Library
  36.  *  - Numerical Optimizer Library
  37.  *  - Machine Learning Library
  38.  *  - Spline Builder Library
  39.  *
  40.  *  Documentation for DROP is Spread Over:
  41.  *
  42.  *  - Main                     => https://lakshmidrip.github.io/DROP/
  43.  *  - Wiki                     => https://github.com/lakshmiDRIP/DROP/wiki
  44.  *  - GitHub                   => https://github.com/lakshmiDRIP/DROP
  45.  *  - Javadoc                  => https://lakshmidrip.github.io/DROP/Javadoc/index.html
  46.  *  - Technical Specifications => https://github.com/lakshmiDRIP/DROP/tree/master/Docs/Internal
  47.  *  - Release Versions         => https://lakshmidrip.github.io/DROP/version.html
  48.  *  - Community Credits        => https://lakshmidrip.github.io/DROP/credits.html
  49.  *  - Issues Catalog           => https://github.com/lakshmiDRIP/DROP/issues
  50.  *  - JUnit                    => https://lakshmidrip.github.io/DROP/junit/index.html
  51.  *  - Jacoco                   => https://lakshmidrip.github.io/DROP/jacoco/index.html
  52.  *
  53.  *  Licensed under the Apache License, Version 2.0 (the "License");
  54.  *      you may not use this file except in compliance with the License.
  55.  *  
  56.  *  You may obtain a copy of the License at
  57.  *      http://www.apache.org/licenses/LICENSE-2.0
  58.  *  
  59.  *  Unless required by applicable law or agreed to in writing, software
  60.  *      distributed under the License is distributed on an "AS IS" BASIS,
  61.  *      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  62.  *  
  63.  *  See the License for the specific language governing permissions and
  64.  *      limitations under the License.
  65.  */

  66. /**
  67.  * <i>UpperAbramowitzStegun</i> illustrates the Estimation of the Upper Incomplete Gamma Function using the
  68.  * Abramowitz-Stegun (2007) Version of Gauss Continued Fraction. The References are:
  69.  *
  70.  * <br><br>
  71.  *  <ul>
  72.  *      <li>
  73.  *          Geddes, K. O., M. L. Glasser, R. A. Moore, and T. C. Scott (1990): Evaluation of Classes of
  74.  *              Definite Integrals involving Elementary Functions via Differentiation of Special Functions
  75.  *              <i>Applicable Algebra in Engineering, Communications, and </i> <b>1 (2)</b> 149-165
  76.  *      </li>
  77.  *      <li>
  78.  *          Gradshteyn, I. S., I. M. Ryzhik, Y. V. Geronimus, M. Y. Tseytlin, and A. Jeffrey (2015):
  79.  *              <i>Tables of Integrals, Series, and Products</i> <b>Academic Press</b>
  80.  *      </li>
  81.  *      <li>
  82.  *          Mathar, R. J. (2010): Numerical Evaluation of the Oscillatory Integral over
  83.  *              e<sup>iÏ€x</sup> x<sup>(1/x)</sup> between 1 and ∞
  84.  *              https://arxiv.org/pdf/0912.3844.pdf <b>arXiV</b>
  85.  *      </li>
  86.  *      <li>
  87.  *          National Institute of Standards and Technology (2019a): Incomplete Gamma and Related Functions
  88.  *              https://dlmf.nist.gov/8
  89.  *      </li>
  90.  *      <li>
  91.  *          Wikipedia (2019): Incomplete Gamma Function
  92.  *              https://en.wikipedia.org/wiki/Incomplete_gamma_function
  93.  *      </li>
  94.  *  </ul>
  95.  *
  96.  *  <br><br>
  97.  *  <ul>
  98.  *      <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/NumericalCore.md">Numerical Core Module</a></li>
  99.  *      <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/NumericalOptimizerLibrary.md">Numerical Optimizer</a></li>
  100.  *      <li><b>Project</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/sample/README.md">Function</a></li>
  101.  *      <li><b>Package</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/sample/gammaincomplete/README.md">Estimates of Incomplete Gamma Functions</a></li>
  102.  *  </ul>
  103.  *
  104.  * @author Lakshmi Krishnamurthy
  105.  */

  106. public class UpperAbramowitzStegun
  107. {

  108.     public static final void main (
  109.         final String[] argumentArray)
  110.         throws Exception
  111.     {
  112.         EnvManager.InitEnv ("");

  113.         EulerIntegralSecondKind gammaFunction = new EulerIntegralSecondKind (null);

  114.         int n = 30;
  115.         double[] sArray =
  116.         {
  117.             2.0,
  118.             2.5,
  119.             3.0,
  120.             3.5,
  121.             4.0,
  122.             4.5,
  123.             5.0,
  124.             5.5,
  125.             6.0,
  126.             6.5,
  127.             7.0,
  128.         };

  129.         double[] zArray =
  130.         {
  131.              1.0,
  132.              2.0,
  133.              3.0,
  134.              4.0,
  135.              5.0,
  136.              6.0,
  137.              7.0,
  138.              8.0,
  139.              9.0,
  140.             10.0
  141.         };

  142.         System.out.println
  143.             ("\t|------------------------------------------------------------------------------------------------------------||");

  144.         System.out.println
  145.             ("\t|                                UPPER GAUSSIAN CONTINUED FRACTION ESTIMATE                                  ||");

  146.         System.out.println
  147.             ("\t|------------------------------------------------------------------------------------------------------------||");

  148.         System.out.println
  149.             ("\t|        L -> R:                                                                                             ||");

  150.         System.out.println
  151.             ("\t|                - s                                                                                         ||");

  152.         System.out.println
  153.             ("\t|                - Gamma Estimate                                                                            ||");

  154.         System.out.println
  155.             ("\t|                - Multi-Limit Upper Incomplete Gamma Estimate                                               ||");

  156.         System.out.println
  157.             ("\t|------------------------------------------------------------------------------------------------------------||");

  158.         for (double s : sArray)
  159.         {
  160.             String display =
  161.                 "\t|" + FormatUtil.FormatDouble (s, 1, 2, 1.) + " => " +
  162.                 FormatUtil.FormatDouble (gammaFunction.evaluate (s), 3, 2, 1.) + " ||";

  163.             for (double z : zArray)
  164.             {
  165.                 display = display + FormatUtil.FormatDouble (
  166.                     GaussContinuedFraction.UpperAbramowitzStegun2007 (
  167.                         z,
  168.                         s,
  169.                         n
  170.                     ), 3, 2, 1.
  171.                 ) + " |";
  172.             }

  173.             System.out.println (display + "|");
  174.         }

  175.         System.out.println
  176.             ("\t|------------------------------------------------------------------------------------------------------------||");

  177.         EnvManager.TerminateEnv();
  178.     }
  179. }