ZeroToOneEstimate.java

  1. package org.drip.sample.digamma;

  2. import org.drip.numerical.common.FormatUtil;
  3. import org.drip.service.env.EnvManager;
  4. import org.drip.specialfunction.digamma.CumulativeSeriesEstimator;
  5. import org.drip.specialfunction.digamma.SaddlePoints;
  6. import org.drip.specialfunction.loggamma.InfiniteSumEstimator;

  7. /*
  8.  * -*- mode: java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  9.  */

  10. /*!
  11.  * Copyright (C) 2020 Lakshmi Krishnamurthy
  12.  * Copyright (C) 2019 Lakshmi Krishnamurthy
  13.  *
  14.  *  This file is part of DROP, an open-source library targeting analytics/risk, transaction cost analytics,
  15.  *      asset liability management analytics, capital, exposure, and margin analytics, valuation adjustment
  16.  *      analytics, and portfolio construction analytics within and across fixed income, credit, commodity,
  17.  *      equity, FX, and structured products. It also includes auxiliary libraries for algorithm support,
  18.  *      numerical analysis, numerical optimization, spline builder, model validation, statistical learning,
  19.  *      and computational support.
  20.  *  
  21.  *      https://lakshmidrip.github.io/DROP/
  22.  *  
  23.  *  DROP is composed of three modules:
  24.  *  
  25.  *  - DROP Product Core - https://lakshmidrip.github.io/DROP-Product-Core/
  26.  *  - DROP Portfolio Core - https://lakshmidrip.github.io/DROP-Portfolio-Core/
  27.  *  - DROP Computational Core - https://lakshmidrip.github.io/DROP-Computational-Core/
  28.  *
  29.  *  DROP Product Core implements libraries for the following:
  30.  *  - Fixed Income Analytics
  31.  *  - Loan Analytics
  32.  *  - Transaction Cost Analytics
  33.  *
  34.  *  DROP Portfolio Core implements libraries for the following:
  35.  *  - Asset Allocation Analytics
  36.  *  - Asset Liability Management Analytics
  37.  *  - Capital Estimation Analytics
  38.  *  - Exposure Analytics
  39.  *  - Margin Analytics
  40.  *  - XVA Analytics
  41.  *
  42.  *  DROP Computational Core implements libraries for the following:
  43.  *  - Algorithm Support
  44.  *  - Computation Support
  45.  *  - Function Analysis
  46.  *  - Model Validation
  47.  *  - Numerical Analysis
  48.  *  - Numerical Optimizer
  49.  *  - Spline Builder
  50.  *  - Statistical Learning
  51.  *
  52.  *  Documentation for DROP is Spread Over:
  53.  *
  54.  *  - Main                     => https://lakshmidrip.github.io/DROP/
  55.  *  - Wiki                     => https://github.com/lakshmiDRIP/DROP/wiki
  56.  *  - GitHub                   => https://github.com/lakshmiDRIP/DROP
  57.  *  - Repo Layout Taxonomy     => https://github.com/lakshmiDRIP/DROP/blob/master/Taxonomy.md
  58.  *  - Javadoc                  => https://lakshmidrip.github.io/DROP/Javadoc/index.html
  59.  *  - Technical Specifications => https://github.com/lakshmiDRIP/DROP/tree/master/Docs/Internal
  60.  *  - Release Versions         => https://lakshmidrip.github.io/DROP/version.html
  61.  *  - Community Credits        => https://lakshmidrip.github.io/DROP/credits.html
  62.  *  - Issues Catalog           => https://github.com/lakshmiDRIP/DROP/issues
  63.  *  - JUnit                    => https://lakshmidrip.github.io/DROP/junit/index.html
  64.  *  - Jacoco                   => https://lakshmidrip.github.io/DROP/jacoco/index.html
  65.  *
  66.  *  Licensed under the Apache License, Version 2.0 (the "License");
  67.  *      you may not use this file except in compliance with the License.
  68.  *  
  69.  *  You may obtain a copy of the License at
  70.  *      http://www.apache.org/licenses/LICENSE-2.0
  71.  *  
  72.  *  Unless required by applicable law or agreed to in writing, software
  73.  *      distributed under the License is distributed on an "AS IS" BASIS,
  74.  *      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  75.  *  
  76.  *  See the License for the specific language governing permissions and
  77.  *      limitations under the License.
  78.  */

  79. /**
  80.  * <i>ZeroToOneEstimate</i> demonstrates the Estimation of the Digamma Function using the Mezo-Hoffman (2017)
  81.  * Series. The References are:
  82.  *
  83.  * <br><br>
  84.  *  <ul>
  85.  *      <li>
  86.  *          Abramowitz, M., and I. A. Stegun (2007): Handbook of Mathematics Functions <b>Dover Book on
  87.  *              Mathematics</b>
  88.  *      </li>
  89.  *      <li>
  90.  *          Blagouchine, I. V. (2018): Three Notes on Ser's and Hasse's Representations for the
  91.  *              Zeta-Functions https://arxiv.org/abs/1606.02044 <b>arXiv</b>
  92.  *      </li>
  93.  *      <li>
  94.  *          Mezo, I., and M. E. Hoffman (2017): Zeros of the Digamma Function and its Barnes G-function
  95.  *              Analogue <i>Integral Transforms and Special Functions</i> <b>28 (28)</b> 846-858
  96.  *      </li>
  97.  *      <li>
  98.  *          Whitaker, E. T., and G. N. Watson (1996): <i>A Course on Modern Analysis</i> <b>Cambridge
  99.  *              University Press</b> New York
  100.  *      </li>
  101.  *      <li>
  102.  *          Wikipedia (2019): Digamma Function https://en.wikipedia.org/wiki/Digamma_function
  103.  *      </li>
  104.  *  </ul>
  105.  *
  106.  *  <br><br>
  107.  *  <ul>
  108.  *      <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/ComputationalCore.md">Computational Core Module</a></li>
  109.  *      <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/FunctionAnalysisLibrary.md">Function Analysis Library</a></li>
  110.  *      <li><b>Project</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/sample/README.md">DROP API Construction and Usage</a></li>
  111.  *      <li><b>Package</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/sample/digamma/README.md">Estimates of the Digamma Function</a></li>
  112.  *  </ul>
  113.  *
  114.  * @author Lakshmi Krishnamurthy
  115.  */

  116. public class ZeroToOneEstimate
  117. {

  118.     public static final void main (
  119.         final String[] argumentArray)
  120.         throws Exception
  121.     {
  122.         EnvManager.InitEnv ("");

  123.         int termCount = 1000000;
  124.         int gaussTermCount = 100;
  125.         int saddlePointCount = 100000;
  126.         int logGammaTermCount = 1000000;
  127.         double[] zArray =
  128.         {
  129.             0.05,
  130.             0.10,
  131.             0.15,
  132.             0.20,
  133.             0.25,
  134.             0.30,
  135.             0.35,
  136.             0.40,
  137.             0.45,
  138.             0.50,
  139.             0.55,
  140.             0.60,
  141.             0.65,
  142.             0.70,
  143.             0.75,
  144.             0.80,
  145.             0.85,
  146.             0.90,
  147.             0.95,
  148.         };

  149.         CumulativeSeriesEstimator abramowitzStegunSeries =
  150.             CumulativeSeriesEstimator.AbramowitzStegun2007 (termCount);

  151.         CumulativeSeriesEstimator mezoHoffmanSeries = CumulativeSeriesEstimator.MezoHoffman2017 (
  152.             InfiniteSumEstimator.Weierstrass (logGammaTermCount),
  153.             SaddlePoints.HermiteEnhancement(),
  154.             saddlePointCount
  155.         );

  156.         CumulativeSeriesEstimator gaussSeries = CumulativeSeriesEstimator.Gauss (gaussTermCount);

  157.         CumulativeSeriesEstimator exponentialAsymptoticSeries =
  158.             CumulativeSeriesEstimator.ExponentialAsymptote();

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

  160.         System.out.println ("\t|                         0 -> 1 DIGAMMA ESTIMATE                           ||");

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

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

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

  164.         System.out.println ("\t|        - Abramowitz-Stegun (2007)                                         ||");

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

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

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

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

  169.         for (double z : zArray)
  170.         {
  171.             System.out.println (
  172.                 "\t|" + FormatUtil.FormatDouble (z, 1, 2, 1.) + " => " +
  173.                 FormatUtil.FormatDouble (
  174.                     abramowitzStegunSeries.evaluate (z),
  175.                     2, 10, 1.
  176.                 ) + " | " + FormatUtil.FormatDouble (
  177.                     gaussSeries.evaluate (z),
  178.                     2, 10, 1.
  179.                 ) + " | " + FormatUtil.FormatDouble (
  180.                     -1. * Math.log (exponentialAsymptoticSeries.evaluate (z)),
  181.                     2, 10, 1.
  182.                 ) + " | " + FormatUtil.FormatDouble (
  183.                     mezoHoffmanSeries.evaluate (z),
  184.                     2, 10, 1.
  185.                 ) + " ||"
  186.             );
  187.         }

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

  189.         EnvManager.TerminateEnv();
  190.     }
  191. }