LowerRegularizedEstimate.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.LowerRegularized;

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

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

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

  105. public class LowerRegularizedEstimate
  106. {

  107.     private static final void PrintSequence (
  108.         final double s,
  109.         final double[] zArray,
  110.         final LowerRegularized gaussContinuedFraction,
  111.         final LowerRegularized weierstrassLimit,
  112.         final LowerRegularized eulerIntegral,
  113.         final LowerRegularized nist2019)
  114.         throws Exception
  115.     {
  116.         System.out.println ("\t|-------------------------------------------------------------||");

  117.         System.out.println ("\t|    REGULARIZED LOWER INCOMPLETE GAMMA FUNCTION ESTIMATES    ||");

  118.         System.out.println ("\t|                        s => " + FormatUtil.FormatDouble (s, 1, 1, 1.));

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

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

  121.         System.out.println ("\t|                - Gauss Continued Fraction                   ||");

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

  123.         System.out.println ("\t|                - Euler Integral                             ||");

  124.         System.out.println ("\t|                - NIST (2019)                                ||");

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

  126.         for (double z : zArray)
  127.         {
  128.             System.out.println (
  129.                 "\t|" + FormatUtil.FormatDouble (z, 2, 2, 1.) + " => " +
  130.                 FormatUtil.FormatDouble (
  131.                     gaussContinuedFraction.p (
  132.                         s,
  133.                         z
  134.                     ), 1, 8, 1.
  135.                 ) + " |" +
  136.                 FormatUtil.FormatDouble (
  137.                     weierstrassLimit.p (
  138.                         s,
  139.                         z
  140.                     ), 1, 8, 1.
  141.                 ) + " |" +
  142.                 FormatUtil.FormatDouble (
  143.                     eulerIntegral.p (
  144.                         s,
  145.                         z
  146.                     ), 1, 8, 1.
  147.                 ) + " |" +
  148.                 FormatUtil.FormatDouble (
  149.                     nist2019.p (
  150.                         s,
  151.                         z
  152.                     ), 1, 8, 1.
  153.                 ) + " ||"
  154.             );
  155.         }

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

  158.     public static final void main (
  159.         final String[] argumentArray)
  160.         throws Exception
  161.     {
  162.         EnvManager.InitEnv ("");

  163.         int n = 30;
  164.         double[] sArray =
  165.         {
  166.             2.0,
  167.             3.0,
  168.             4.0,
  169.             5.0,
  170.             6.0,
  171.             7.0,
  172.             8.0,
  173.             9.0,
  174.         };
  175.         double[] zArray =
  176.         {
  177.              0.01,
  178.              0.05,
  179.              0.10,
  180.              0.25,
  181.              0.50,
  182.              0.75,
  183.              1.00,
  184.              1.25,
  185.              1.50,
  186.              1.75,
  187.              2.00,
  188.              3.00,
  189.              4.00,
  190.              5.00,
  191.              6.00,
  192.              8.00,
  193.             10.00,
  194.             12.00,
  195.             15.00,
  196.             20.00,
  197.         };

  198.         LowerRegularized nist2019 = LowerRegularized.NIST2019 (n);

  199.         LowerRegularized eulerIntegral = LowerRegularized.EulerIntegral();

  200.         LowerRegularized weierstrassLimit = LowerRegularized.WeierstrassLimit (n);

  201.         LowerRegularized gaussContinuedFraction = LowerRegularized.GaussContinuedFraction (n);

  202.         for (double s : sArray)
  203.         {
  204.             PrintSequence (
  205.                 s,
  206.                 zArray,
  207.                 gaussContinuedFraction,
  208.                 weierstrassLimit,
  209.                 eulerIntegral,
  210.                 nist2019
  211.             );
  212.         }

  213.         EnvManager.TerminateEnv();
  214.     }
  215. }