ComparativeEstimate.java

  1. package org.drip.sample.gamma;

  2. import org.drip.numerical.common.FormatUtil;
  3. import org.drip.service.env.EnvManager;
  4. import org.drip.specialfunction.gamma.EulerIntegralSecondKind;
  5. import org.drip.specialfunction.gamma.LogReciprocal;
  6. import org.drip.specialfunction.gamma.NemesAnalytic;
  7. import org.drip.specialfunction.gamma.RamanujanSeries;
  8. import org.drip.specialfunction.gamma.StirlingSeries;
  9. import org.drip.specialfunction.gamma.WindschitlTothAnalytic;
  10. import org.drip.specialfunction.loggamma.BinetIntegralFirstKindEstimator;
  11. import org.drip.specialfunction.loggamma.BinetIntegralSecondKindEstimator;
  12. import org.drip.specialfunction.loggamma.InfiniteSumEstimator;

  13. /*
  14.  * -*- mode: java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  15.  */

  16. /*!
  17.  * Copyright (C) 2019 Lakshmi Krishnamurthy
  18.  *
  19.  *  This file is part of DROP, an open-source library targeting risk, transaction costs, exposure, margin
  20.  *      calculations, and portfolio construction within and across fixed income, credit, commodity, equity,
  21.  *      FX, and structured products.
  22.  *  
  23.  *      https://lakshmidrip.github.io/DROP/
  24.  *  
  25.  *  DROP is composed of three main modules:
  26.  *  
  27.  *  - DROP Analytics Core - https://lakshmidrip.github.io/DROP-Analytics-Core/
  28.  *  - DROP Portfolio Core - https://lakshmidrip.github.io/DROP-Portfolio-Core/
  29.  *  - DROP Numerical Core - https://lakshmidrip.github.io/DROP-Numerical-Core/
  30.  *
  31.  *  DROP Analytics Core implements libraries for the following:
  32.  *  - Fixed Income Analytics
  33.  *  - Asset Backed Analytics
  34.  *  - XVA Analytics
  35.  *  - Exposure and Margin Analytics
  36.  *
  37.  *  DROP Portfolio Core implements libraries for the following:
  38.  *  - Asset Allocation Analytics
  39.  *  - Transaction Cost Analytics
  40.  *
  41.  *  DROP Numerical Core implements libraries for the following:
  42.  *  - Statistical Learning Library
  43.  *  - Numerical Optimizer Library
  44.  *  - Machine Learning Library
  45.  *  - Spline Builder Library
  46.  *
  47.  *  Documentation for DROP is Spread Over:
  48.  *
  49.  *  - Main                     => https://lakshmidrip.github.io/DROP/
  50.  *  - Wiki                     => https://github.com/lakshmiDRIP/DROP/wiki
  51.  *  - GitHub                   => https://github.com/lakshmiDRIP/DROP
  52.  *  - Javadoc                  => https://lakshmidrip.github.io/DROP/Javadoc/index.html
  53.  *  - Technical Specifications => https://github.com/lakshmiDRIP/DROP/tree/master/Docs/Internal
  54.  *  - Release Versions         => https://lakshmidrip.github.io/DROP/version.html
  55.  *  - Community Credits        => https://lakshmidrip.github.io/DROP/credits.html
  56.  *  - Issues Catalog           => https://github.com/lakshmiDRIP/DROP/issues
  57.  *  - JUnit                    => https://lakshmidrip.github.io/DROP/junit/index.html
  58.  *  - Jacoco                   => https://lakshmidrip.github.io/DROP/jacoco/index.html
  59.  *
  60.  *  Licensed under the Apache License, Version 2.0 (the "License");
  61.  *      you may not use this file except in compliance with the License.
  62.  *  
  63.  *  You may obtain a copy of the License at
  64.  *      http://www.apache.org/licenses/LICENSE-2.0
  65.  *  
  66.  *  Unless required by applicable law or agreed to in writing, software
  67.  *      distributed under the License is distributed on an "AS IS" BASIS,
  68.  *      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  69.  *  
  70.  *  See the License for the specific language governing permissions and
  71.  *      limitations under the License.
  72.  */

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

  110. public class ComparativeEstimate
  111. {

  112.     public static final void main (
  113.         final String[] argumentArray)
  114.         throws Exception
  115.     {
  116.         EnvManager.InitEnv ("");

  117.         int eulerTermCount = 1638400;
  118.         int weierstrassTermCount = 1638400;
  119.         double[] sArray =
  120.         {
  121.             0.01000,
  122.             0.05000,
  123.             0.10000,
  124.             0.15000,
  125.             0.20000,
  126.             0.25000,
  127.             0.30000,
  128.             0.35000,
  129.             0.40000,
  130.             0.45000,
  131.             0.50000,
  132.             0.60000,
  133.             0.70000,
  134.             0.80000,
  135.             0.90000,
  136.             1.00000,
  137.             1.10000,
  138.             1.20000,
  139.             1.30000,
  140.             1.40000,
  141.             1.46163,
  142.             1.50000,
  143.             2.00000,
  144.             2.50000,
  145.             3.00000,
  146.             3.50000,
  147.             4.00000,
  148.             4.50000,
  149.             5.00000,
  150.             5.50000,
  151.             6.00000,
  152.             6.50000,
  153.             7.00000,
  154.         };

  155.         StirlingSeries factorial = new StirlingSeries (null);

  156.         NemesAnalytic nemesGamma = new NemesAnalytic (null);

  157.         LogReciprocal logReciprocal = new LogReciprocal (null);

  158.         RamanujanSeries ramanujanGamma = new RamanujanSeries (null);

  159.         WindschitlTothAnalytic windschitlTothGamma = new WindschitlTothAnalytic (null);

  160.         InfiniteSumEstimator eulerInfiniteProduct = InfiniteSumEstimator.Euler (eulerTermCount);

  161.         BinetIntegralFirstKindEstimator binetIntegralFirstKind = new BinetIntegralFirstKindEstimator (null);

  162.         BinetIntegralSecondKindEstimator binetIntegralSecondKind = new BinetIntegralSecondKindEstimator (null);

  163.         EulerIntegralSecondKind eulerIntegralSecondKind = new EulerIntegralSecondKind (null);

  164.         InfiniteSumEstimator weierstrassInfiniteProduct = InfiniteSumEstimator.Weierstrass (weierstrassTermCount);

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

  166.         System.out.println ("\t|                                                               GAMMA FUNCTION ESTIMATE                                                                ||");

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

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

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

  170.         System.out.println ("\t|                - Windschitl-Toth                                                                                                                     ||");

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

  172.         System.out.println ("\t|                - Euler Infinite Product Series                                                                                                       ||");

  173.         System.out.println ("\t|                - Weierstrass Infinite Product Series                                                                                                 ||");

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

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

  176.         System.out.println ("\t|                - Euler Integral Second Kind                                                                                                          ||");

  177.         System.out.println ("\t|                - Log Reciprocal                                                                                                                      ||");

  178.         System.out.println ("\t|                - Binet Integral First Kind                                                                                                           ||");

  179.         System.out.println ("\t|                - Binet Integral Second Kind                                                                                                          ||");

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

  181.         for (double s : sArray)
  182.         {
  183.             System.out.println (
  184.                 "\t|" + FormatUtil.FormatDouble (s, 1, 5, 1.) + " => " +
  185.                 FormatUtil.FormatDouble (windschitlTothGamma.evaluate (s), 3, 6, 1.) + " | " +
  186.                 FormatUtil.FormatDouble (nemesGamma.evaluate (s), 3, 6, 1.) + " | " +
  187.                 FormatUtil.FormatDouble (Math.exp (eulerInfiniteProduct.evaluate (s)), 3, 6, 1.) + " | " +
  188.                 FormatUtil.FormatDouble (Math.exp (weierstrassInfiniteProduct.evaluate (s)), 3, 6, 1.) + " | " +
  189.                 FormatUtil.FormatDouble (ramanujanGamma.evaluate (s), 3, 6, 1.) + " | " +
  190.                 FormatUtil.FormatDouble (factorial.evaluate (s), 3, 6, 1.) + " | " +
  191.                 FormatUtil.FormatDouble (eulerIntegralSecondKind.evaluate (s), 3, 6, 1.) + " | " +
  192.                 FormatUtil.FormatDouble (logReciprocal.evaluate (s), 3, 6, 1.) + " | " +
  193.                 FormatUtil.FormatDouble (Math.exp (binetIntegralFirstKind.evaluate (s)), 3, 6, 1.) + " | " +
  194.                 FormatUtil.FormatDouble (Math.exp (binetIntegralSecondKind.evaluate (s)), 3, 6, 1.) + " ||"
  195.             );
  196.         }

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

  198.         EnvManager.TerminateEnv();
  199.     }
  200. }