LowerEulerIntegralEstimate.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.LowerEulerIntegral;

  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>LowerEulerIntegralEstimate</i> illustrates the Estimation using the Euler's Second Kind Integral of the
  68.  * Lower Incomplete Gamma Function. 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 LowerEulerIntegralEstimate
  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.         double[] sArray =
  115.         {
  116.             2.0,
  117.             2.5,
  118.             3.0,
  119.             3.5,
  120.             4.0,
  121.             4.5,
  122.             5.0,
  123.             5.5,
  124.             6.0,
  125.             6.5,
  126.             7.0,
  127.         };
  128.         double[] limitArray =
  129.         {
  130.             20.0,
  131.             18.0,
  132.             16.0,
  133.             14.0,
  134.             12.0,
  135.             10.0,
  136.              8.0,
  137.              6.0,
  138.              4.0,
  139.              2.0
  140.         };

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

  143.         System.out.println
  144.             ("\t|                                       LOWER EULER INTEGRAL ESTIMATE                                        ||");

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

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

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

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

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

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

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

  162.             for (double limit : limitArray)
  163.             {
  164.                 LowerEulerIntegral lowerEulerIntegral = new LowerEulerIntegral (
  165.                     null,
  166.                     limit
  167.                 );

  168.                 display = display + FormatUtil.FormatDouble (
  169.                     lowerEulerIntegral.evaluate (s), 3, 2, 1.
  170.                 ) + " |";
  171.             }

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

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

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