UpperSRecurrenceEstimate.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.UpperSFixed;

  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>UpperSRecurrenceEstimate</i> illustrates the Recurrence-Based Estimation of the Upper Incomplete Gamma
  67.  * Function using the NIST (2019) Series. 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 UpperSRecurrenceEstimate
  106. {

  107.     public static final void main (
  108.         final String[] argumentArray)
  109.         throws Exception
  110.     {
  111.         EnvManager.InitEnv ("");

  112.         int termCount = 20;
  113.         double[] zArray =
  114.         {
  115.             1.00,
  116.             0.80,
  117.             0.60,
  118.             0.40,
  119.             0.20,
  120.             0.01,
  121.         };
  122.         int[] nArray =
  123.         {
  124.             1,
  125.             2,
  126.             3,
  127.             4,
  128.             5,
  129.             6,
  130.             7,
  131.             8,
  132.             9,
  133.         };

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

  136.         System.out.println
  137.             ("\t|                  RECURRENCE ESTIMATION OF UPPER INCOMEPLETE GAMMA FUNCTION - NEGATIVE VALUES                   ||");

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

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

  142.         System.out.println
  143.             ("\t|                - (Negative) n                                                                                  ||");

  144.         System.out.println
  145.             ("\t|                - Upper Incomplete Gamma for for z = 0 -> 1                                                     ||");

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

  148.         for (int n : nArray)
  149.         {
  150.             String display = "\t| n ->" + FormatUtil.FormatDouble (n, 1, 0, 1.) + " => ";

  151.             UpperSFixed upperSRecursive = UpperSFixed.NIST2019 (termCount);

  152.             for (double z : zArray)
  153.             {
  154.                 display = display + " " +
  155.                     FormatUtil.FormatDouble (
  156.                         upperSRecursive.evaluateRecursive (
  157.                             n,
  158.                             z
  159.                         ), 6, 6, 1.
  160.                     )
  161.                 + " |";
  162.             }

  163.             System.out.println (display + "|");
  164.         }

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

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