LowerZInfinityAsymptote.java

  1. package org.drip.sample.gammaincomplete;

  2. import org.drip.function.definition.R1ToR1;
  3. import org.drip.numerical.common.FormatUtil;
  4. import org.drip.service.env.EnvManager;
  5. import org.drip.specialfunction.incompletegamma.LimitAsymptote;
  6. import org.drip.specialfunction.incompletegamma.LowerSFixed;

  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>LowerZInfinityAsymptote</i> illustrates the Asymptotic Behavior of the Lower Incomplete Gamma Function
  69.  * in the Neighborhood of z = Infinity using the Weierstrass Limit Series. 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 LowerZInfinityAsymptote
  108. {

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

  119.         R1ToR1 zInfinityLimitAsymptote = LimitAsymptote.Lower().zInfinity (s);

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

  121.         for (double z : zArray)
  122.         {
  123.             display = display + " [" +
  124.                 FormatUtil.FormatDouble (lowerSFixed.evaluate (z), 1, 5, 1.) + " -" +
  125.                 FormatUtil.FormatDouble (zInfinityLimitAsymptote.evaluate (z), 1, 5, 1.) + "] |";
  126.         }

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

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

  134.         int termCount = 50;
  135.         double[] sArray =
  136.         {
  137.             0.10,
  138.             0.20,
  139.             0.30,
  140.             0.40,
  141.             0.50,
  142.             0.60,
  143.             0.70,
  144.             0.80,
  145.             0.90,
  146.             1.00,
  147.             1.20,
  148.             1.40,
  149.             1.60,
  150.             1.80,
  151.             2.00,
  152.         };
  153.         double[] zArray =
  154.         {
  155.             10.,
  156.             20.,
  157.             30.
  158.         };

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

  160.         System.out.println ("\t|                    LOWER INCOMPLETE ASYMPTOTE BEHAVIOR                     ||");

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

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

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

  164.         System.out.println ("\t|            - Weierstrass vs. Asymptote Lower Incomplete Gamma              ||");

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

  166.         for (double s : sArray)
  167.         {
  168.             WeierstrassAsymptoteComparison (
  169.                 termCount,
  170.                 s,
  171.                 zArray
  172.             );
  173.         }

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

  175.         System.out.println();

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