FourierBlagouchineSeriesEstimate.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.loggamma.InfiniteSumEstimator;

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

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

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

  103. public class FourierBlagouchineSeriesEstimate
  104. {

  105.     public static final void main (
  106.         final String[] argumentArray)
  107.         throws Exception
  108.     {
  109.         EnvManager.InitEnv ("");

  110.         int fourierTermCount = 1000000;
  111.         int blagouchineTermCount = 10000;
  112.         double[] sArray =
  113.         {
  114.             0.05,
  115.             0.10,
  116.             0.15,
  117.             0.20,
  118.             0.25,
  119.             0.30,
  120.             0.35,
  121.             0.40,
  122.             0.45,
  123.             // 0.50,
  124.             0.55,
  125.             0.60,
  126.             0.65,
  127.             0.70,
  128.             0.75,
  129.             0.80,
  130.             0.85,
  131.             0.90,
  132.             0.95,
  133.         };

  134.         InfiniteSumEstimator fourier = InfiniteSumEstimator.Fourier (fourierTermCount);

  135.         InfiniteSumEstimator blagouchine = InfiniteSumEstimator.Blagouchine2015 (blagouchineTermCount);

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

  137.         System.out.println ("\t|            MALMSTEN-BLAGOUCHINE FOURIER SERIES GAMMA ESTIMATE             ||");

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

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

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

  141.         System.out.println ("\t|            - Malmsten-Blagouchine Fourier Series Log Gamma                ||");

  142.         System.out.println ("\t|            - Blagouchine (2015) Fourier Series Log Gamma                  ||");

  143.         System.out.println ("\t|            - Malmsten-Blagouchine Fourier Series Gamma                    ||");

  144.         System.out.println ("\t|            - Blagouchine (2015) Fourier Series Gamma                      ||");

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

  146.         for (double s : sArray)
  147.         {
  148.             double fourierLogGamma = fourier.evaluate (s);

  149.             double blagouchineLogGamma = blagouchine.evaluate (s);

  150.             System.out.println (
  151.                 "\t|" + FormatUtil.FormatDouble (s, 1, 2, 1.) + " => {" +
  152.                 FormatUtil.FormatDouble (fourierLogGamma, 1, 10, 1.) + " | " +
  153.                 FormatUtil.FormatDouble (blagouchineLogGamma, 1, 10, 1.) + "} {" +
  154.                 FormatUtil.FormatDouble (Math.exp (fourierLogGamma), 2, 10, 1.) + " | " +
  155.                 FormatUtil.FormatDouble (Math.exp (blagouchineLogGamma), 2, 10, 1.) + "} ||"
  156.             );
  157.         }

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

  159.         EnvManager.TerminateEnv();
  160.     }
  161. }