UpperWeissteinEstimate.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.UpperEulerIntegral;
  5. import org.drip.specialfunction.incompletegamma.UpperSFixed;

  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>UpperWeissteinEstimate</i> illustrates the Estimation of the Upper Incomplete Gamma Function using the
  68.  * Weisstein 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 UpperWeissteinEstimate
  107. {

  108.     private static final void EulerIntegralComparison (
  109.         final int termCount,
  110.         final int s,
  111.         final double[] zArray)
  112.         throws Exception
  113.     {
  114.         UpperSFixed upperSZero = UpperSFixed.Weisstein (s);

  115.         String display = "\t|" + FormatUtil.FormatDouble (s, 1, 0, 1.) + " => ";

  116.         for (double z : zArray)
  117.         {
  118.             UpperEulerIntegral upperEulerIntegral = new UpperEulerIntegral (
  119.                 null,
  120.                 z
  121.             );

  122.             display = display + " [" +
  123.                 FormatUtil.FormatDouble (upperEulerIntegral.evaluate (s), 3, 4, 1.) + " -" +
  124.                 FormatUtil.FormatDouble (upperSZero.evaluate (z), 3, 4, 1.) + "] |";
  125.         }

  126.         System.out.println (display + "|");
  127.     }

  128.     public static final void main (
  129.         final String[] argumentArray)
  130.         throws Exception
  131.     {
  132.         EnvManager.InitEnv ("");

  133.         int[] sArray =
  134.         {
  135.              1,
  136.              2,
  137.              3,
  138.              4,
  139.              5,
  140.              6,
  141.              7,
  142.         };
  143.         int termCount = 50;
  144.         double[] zArray =
  145.         {
  146.             8.00,
  147.             6.00,
  148.             4.00,
  149.             2.00,
  150.             0.00,
  151.         };

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

  153.         System.out.println ("\t|                                        UPPER GAMMA INCOMPLETE FUNCTION WEINSTEIN ESTIMATE                                        ||");

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

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

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

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

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

  159.         for (int s : sArray)
  160.         {
  161.             EulerIntegralComparison (
  162.                 termCount,
  163.                 s,
  164.                 zArray
  165.             );
  166.         }

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

  168.         EnvManager.TerminateEnv();
  169.     }
  170. }