UpperLimitPowerEstimate.java

  1. package org.drip.sample.gammaincomplete;

  2. import org.drip.numerical.common.FormatUtil;
  3. import org.drip.numerical.integration.NewtonCotesQuadratureGenerator;
  4. import org.drip.service.env.EnvManager;
  5. import org.drip.specialfunction.incompletegamma.UpperLimitPowerIntegrand;

  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>UpperLimitPowerEstimate</i> illustrates the Estimation of the Integral of the Product of the Limit
  68.  * Raised to an Exponent and the corresponding Upper 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 UpperLimitPowerEstimate
  107. {

  108.     private static final void QuadratureComparison (
  109.         final UpperLimitPowerIntegrand upperLimitPowerIntegrand,
  110.         final double s,
  111.         final double limitExponent,
  112.         final double[] leftArray,
  113.         final double[] rightArray,
  114.         final int intermediatePointCount)
  115.         throws Exception
  116.     {
  117.         System.out.println ("\t|--------------------------------------------------------------------------------------------------------------------------||");

  118.         System.out.println ("\t|                                         QUADRATURE COMPARISON - s => " + FormatUtil.FormatDouble (s, 1, 1, 1.) + " | Exponent => " + FormatUtil.FormatDouble (limitExponent, 1, 1, 1.));

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

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

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

  122.         System.out.println ("\t|                - [Comparison Pair]                                                                                       ||");

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

  124.         for (double left : leftArray)
  125.         {
  126.             String display = "\t|" + FormatUtil.FormatDouble (left, 1, 1, 1.) + " => ";

  127.             for (double right : rightArray)
  128.             {
  129.                 display = display + "[" + FormatUtil.FormatDouble (
  130.                     NewtonCotesQuadratureGenerator.Zero_PlusOne (
  131.                         left,
  132.                         right,
  133.                         intermediatePointCount
  134.                     ).integrate (upperLimitPowerIntegrand), 4, 2, 1.
  135.                 ) + " - " + FormatUtil.FormatDouble (
  136.                     upperLimitPowerIntegrand.integrate (
  137.                         left,
  138.                         right
  139.                     ), 4, 2, 1.
  140.                 ) + "] |";
  141.             }

  142.             System.out.println (display + "|");
  143.         }

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

  146.     public static final void main (
  147.         final String[] argumentArray)
  148.         throws Exception
  149.     {
  150.         EnvManager.InitEnv ("");

  151.         int intermediatePointCount = 100;
  152.         double[] leftArray =
  153.         {
  154.             1.,
  155.             2.,
  156.             3.,
  157.             4.,
  158.             5.,
  159.         };
  160.         double[] rightArray =
  161.         {
  162.             10.,
  163.             15.,
  164.             20.,
  165.             25.,
  166.             30.,
  167.         };
  168.         double[] sArray =
  169.         {
  170.             3.,
  171.             4.,
  172.             5.,
  173.             6.,
  174.             7.,
  175.         };
  176.         double[] limitExponentArray =
  177.         {
  178.             3.,
  179.             4.,
  180.             5.,
  181.             6.,
  182.             7.,
  183.         };

  184.         for (double s : sArray)
  185.         {
  186.             for (double limitExponent : limitExponentArray)
  187.             {
  188.                 UpperLimitPowerIntegrand upperLimitPowerIntegrand = new UpperLimitPowerIntegrand (
  189.                     null,
  190.                     s,
  191.                     limitExponent
  192.                 );

  193.                 QuadratureComparison (
  194.                     upperLimitPowerIntegrand,
  195.                     s,
  196.                     limitExponent,
  197.                     leftArray,
  198.                     rightArray,
  199.                     intermediatePointCount
  200.                 );
  201.             }
  202.         }

  203.         EnvManager.TerminateEnv();
  204.     }
  205. }