UpperSHalfEstimate.java

  1. package org.drip.sample.gammaincomplete;

  2. import org.drip.function.e2erf.AbramowitzStegun;
  3. import org.drip.function.e2erf.ErrorFunctionAnalytical;
  4. import org.drip.numerical.common.FormatUtil;
  5. import org.drip.service.env.EnvManager;
  6. import org.drip.specialfunction.incompletegamma.UpperEulerIntegral;

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

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

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

  107. public class UpperSHalfEstimate
  108. {

  109.     private static final void EulerIntegralComparison (
  110.         final int termCount,
  111.         final double[] zArray)
  112.         throws Exception
  113.     {
  114.         System.out.println ("\t|---------------------------------------||");

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

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

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

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

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

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

  121.         AbramowitzStegun erfWinitzki = ErrorFunctionAnalytical.Winitzki2008b();

  122.         for (double z : zArray)
  123.         {
  124.             UpperEulerIntegral upperEulerIntegral = new UpperEulerIntegral (
  125.                 null,
  126.                 z
  127.             );

  128.             System.out.println (
  129.                 "\t|" + FormatUtil.FormatDouble (z, 1, 2, 1.) + " => " +
  130.                 FormatUtil.FormatDouble (upperEulerIntegral.evaluate (0.5), 1, 10, 1.) + " | " +
  131.                 FormatUtil.FormatDouble (Math.sqrt (Math.PI) * (1. - erfWinitzki.evaluate (Math.sqrt (z))), 1, 10, 1.) + " ||"
  132.             );
  133.         }

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

  135.         System.out.println();
  136.     }

  137.     public static final void main (
  138.         final String[] argumentArray)
  139.         throws Exception
  140.     {
  141.         EnvManager.InitEnv ("");

  142.         int termCount = 50;
  143.         double[] zArray =
  144.         {
  145.             1.00,
  146.             0.95,
  147.             0.90,
  148.             0.85,
  149.             0.80,
  150.             0.75,
  151.             0.70,
  152.             0.65,
  153.             0.60,
  154.             0.55,
  155.             0.50,
  156.             0.45,
  157.             0.40,
  158.             0.35,
  159.             0.30,
  160.             0.25,
  161.             0.20,
  162.             0.15,
  163.             0.10,
  164.             0.05,
  165.             0.01,
  166.         };

  167.         EulerIntegralComparison (
  168.             termCount,
  169.             zArray
  170.         );

  171.         EnvManager.TerminateEnv();
  172.     }
  173. }