UpperAsymptoteProperty.java

  1. package org.drip.sample.gamma;

  2. import org.drip.function.definition.R1ToR1Property;
  3. import org.drip.function.definition.R1PropertyVerification;
  4. import org.drip.numerical.common.FormatUtil;
  5. import org.drip.service.env.EnvManager;
  6. import org.drip.specialfunction.property.GammaInequalityLemma;

  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>UpperAsymptoteProperty</i> demonstrates the Verification of the Upper Asymptote Property of the Gamma
  69.  * Function. The References are:
  70.  *
  71.  * <br><br>
  72.  *  <ul>
  73.  *      <li>
  74.  *          Blagouchine, I. V. (2014): Re-discovery of Malmsten's Integrals, their Evaluation by Contour
  75.  *              Integration Methods, and some Related Results <i>Ramanujan Journal</i> <b>35 (1)</b> 21-110
  76.  *      </li>
  77.  *      <li>
  78.  *          Borwein, J. M., and R. M. Corless (2017): Gamma Function and the Factorial in the Monthly
  79.  *              https://arxiv.org/abs/1703.05349 <b>arXiv</b>
  80.  *      </li>
  81.  *      <li>
  82.  *          Davis, P. J. (1959): Leonhard Euler's Integral: A Historical Profile of the Gamma Function
  83.  *              <i>American Mathematical Monthly</i> <b>66 (10)</b> 849-869
  84.  *      </li>
  85.  *      <li>
  86.  *          Whitaker, E. T., and G. N. Watson (1996): <i>A Course on Modern Analysis</i> <b>Cambridge
  87.  *              University Press</b> New York
  88.  *      </li>
  89.  *      <li>
  90.  *          Wikipedia (2019): Gamma Function https://en.wikipedia.org/wiki/Gamma_function
  91.  *      </li>
  92.  *  </ul>
  93.  *
  94.  *  <br><br>
  95.  *  <ul>
  96.  *      <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/NumericalCore.md">Numerical Core Module</a></li>
  97.  *      <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/NumericalOptimizerLibrary.md">Numerical Optimizer</a></li>
  98.  *      <li><b>Project</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/sample/README.md">Function</a></li>
  99.  *      <li><b>Package</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/sample/gamma/README.md">Integrand Estimates of Gamma Functions</a></li>
  100.  *  </ul>
  101.  *
  102.  * @author Lakshmi Krishnamurthy
  103.  */

  104. public class UpperAsymptoteProperty
  105. {

  106.     private static final void AsymptoticUpperApproximate (
  107.         final double alpha,
  108.         final double[] sArray)
  109.         throws Exception
  110.     {
  111.         R1ToR1Property asymptoticUpperApproximateProperty =
  112.             GammaInequalityLemma.AsymptoticUpperApproximate (alpha);

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

  114.         System.out.println ("\t|      GAMMA FUNCTION UPPER ASYMPTOTE PROPERTY      ||");

  115.         System.out.println ("\t|                  ALPHA = " + FormatUtil.FormatDouble (alpha, 1, 2, 1.));

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

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

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

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

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

  121.         System.out.println ("\t|                - Verification Success?            ||");

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

  123.         for (double s : sArray)
  124.         {
  125.             R1PropertyVerification propertyVerification = asymptoticUpperApproximateProperty.verify (s);

  126.             System.out.println (
  127.                 "\t|" + FormatUtil.FormatDouble (s, 2, 2, 1.) + " => " +
  128.                     FormatUtil.FormatDouble (propertyVerification.lValue(), 3, 10, 1.) + " | " +
  129.                     FormatUtil.FormatDouble (propertyVerification.rValue(), 3, 10, 1.) + " | " +
  130.                     propertyVerification.verified() + " ||"
  131.             );
  132.         }

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

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

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

  141.         double[] alphaArray =
  142.         {
  143.             0.5,
  144.             1.0,
  145.             1.5,
  146.             2.0,
  147.             2.5,
  148.         };
  149.         double[] sArray =
  150.         {
  151.              5,
  152.             10,
  153.             15,
  154.             20,
  155.             25,
  156.             30,
  157.             35,
  158.             40,
  159.             45,
  160.             50,
  161.             60,
  162.             70,
  163.             80,
  164.             90,
  165.         };

  166.         for (double alpha : alphaArray)
  167.         {
  168.             AsymptoticUpperApproximate (
  169.                 alpha,
  170.                 sArray
  171.             );
  172.         }

  173.         EnvManager.TerminateEnv();
  174.     }
  175. }