AsymptoticEstimate.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. /*
  6.  * -*- mode: java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  7.  */

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

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

  114. public class AsymptoticEstimate
  115. {

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

  121.         int termCount = 1000000;
  122.         double[] zArray =
  123.         {
  124.             0.5,
  125.             1.0,
  126.             1.5,
  127.             2.0,
  128.             2.5,
  129.             3.0,
  130.             3.5,
  131.             4.0,
  132.             4.5,
  133.             5.0,
  134.             5.5,
  135.             6.0,
  136.             6.5,
  137.             7.0,
  138.             7.5,
  139.             8.0,
  140.             8.5,
  141.             9.0,
  142.             9.5,
  143.         };

  144.         CumulativeSeriesEstimator asymptoticSeries = CumulativeSeriesEstimator.Asymptotic();

  145.         CumulativeSeriesEstimator abramowitzStegun2007 =
  146.             CumulativeSeriesEstimator.AbramowitzStegun2007 (termCount);

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

  148.         System.out.println ("\t|  ASYMPTOTIC SERIES DIGAMMA ESTIMATE  ||");

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

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

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

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

  153.         System.out.println ("\t|        - Asymptotic Series           ||");

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

  155.         for (double z : zArray)
  156.         {
  157.             System.out.println (
  158.                 "\t|" + FormatUtil.FormatDouble (z, 1, 1, 1.) + " => " +
  159.                 FormatUtil.FormatDouble (
  160.                     abramowitzStegun2007.evaluate (z),
  161.                     1, 10, 1.
  162.                 ) + " | " + FormatUtil.FormatDouble (
  163.                     asymptoticSeries.evaluate (z),
  164.                     1, 10, 1.
  165.                 ) + " ||"
  166.             );
  167.         }

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

  169.         EnvManager.TerminateEnv();
  170.     }
  171. }