LowerNIST2019Estimate.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.incompletegamma.LowerEulerIntegral;
  5. import org.drip.specialfunction.incompletegamma.LowerSFixed;

  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>LowerNIST2019Estimate</i> illustrates the Estimation of the Lower Incomplete Gamma Function using the
  68.  * NIST (2019) Series. 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 LowerNIST2019Estimate
  107. {

  108.     private static final void EulerIntegralComparison (
  109.         final int termCount,
  110.         final double s,
  111.         final double[] zArray)
  112.         throws Exception
  113.     {
  114.         LowerSFixed lowerSFixed = LowerSFixed.NIST2019 (
  115.             s,
  116.             termCount
  117.         );

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

  119.         System.out.println ("\t|                      TERM COUNT => " + FormatUtil.FormatDouble (termCount, 2, 0, 1.));

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

  121.         System.out.println ("\t|    L - R:                                                             ||");

  122.         System.out.println ("\t|            - Weierstrass Limit                                        ||");

  123.         System.out.println ("\t|            - Scaled Lower Incomplete Gamma                            ||");

  124.         System.out.println ("\t|            - Unscaled Lower Incomplete Gamma                          ||");

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

  126.         for (double z : zArray)
  127.         {
  128.             LowerEulerIntegral lowerEulerIntegral = new LowerEulerIntegral (
  129.                 null,
  130.                 z
  131.             );

  132.             System.out.println (
  133.                 "\t|" + FormatUtil.FormatDouble (z, 1, 2, 1.) + " => " +
  134.                 FormatUtil.FormatDouble (lowerSFixed.weierstrassLimit (z), 1, 10, 1.) + " | " +
  135.                 FormatUtil.FormatDouble (lowerSFixed.nonDimensional (z), 1, 10, 1.) + " | " +
  136.                 FormatUtil.FormatDouble (lowerSFixed.evaluate (z), 1, 10, 1.) + " | " +
  137.                 FormatUtil.FormatDouble (lowerEulerIntegral.evaluate (s), 1, 10, 1.) + " ||"
  138.             );
  139.         }

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

  141.         System.out.println();
  142.     }

  143.     public static final void main (
  144.         final String[] argumentArray)
  145.         throws Exception
  146.     {
  147.         EnvManager.InitEnv ("");

  148.         double s = 6.;
  149.         int[] termCountArray =
  150.         {
  151.              39,
  152.              79,
  153.             119
  154.         };
  155.         double[] zArray =
  156.         {
  157.             1.00,
  158.             0.95,
  159.             0.90,
  160.             0.85,
  161.             0.80,
  162.             0.75,
  163.             0.70,
  164.             0.65,
  165.             0.60,
  166.             0.55,
  167.             0.50,
  168.             0.45,
  169.             0.40,
  170.             0.35,
  171.             0.30,
  172.             0.25,
  173.             0.20,
  174.             0.15,
  175.             0.10,
  176.             0.05,
  177.             0.01,
  178.         };

  179.         for (int termCount : termCountArray)
  180.         {
  181.             EulerIntegralComparison (
  182.                 termCount,
  183.                 s,
  184.                 zArray
  185.             );
  186.         }

  187.         EnvManager.TerminateEnv();
  188.     }
  189. }