StretchedExponentialMomentEstimate.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.derived.StretchedExponentialMoment;

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

  102. public class StretchedExponentialMomentEstimate
  103. {

  104.     private static final void Estimate (
  105.         final double tau,
  106.         final double beta,
  107.         final double[] momentArray)
  108.         throws Exception
  109.     {
  110.         StretchedExponentialMoment stretchedExponentialMomentIntegral = new StretchedExponentialMoment (
  111.             null,
  112.             tau,
  113.             beta
  114.         );

  115.         StretchedExponentialMoment stretchedExponentialMomentWeierstrass =
  116.             StretchedExponentialMoment.Weierstrass (
  117.                 tau,
  118.                 beta,
  119.                 1638400
  120.             );

  121.         String display = "\t|[" + FormatUtil.FormatDouble (tau, 1, 1, 1.) +
  122.             "," + FormatUtil.FormatDouble (beta, 1, 1, 1.) + "] => ";

  123.         for (double moment : momentArray)
  124.         {
  125.             display = display + "{" + FormatUtil.FormatDouble (
  126.                 stretchedExponentialMomentIntegral.evaluate (moment), 7, 2, 1.
  127.             ) + " |" + FormatUtil.FormatDouble (
  128.                 stretchedExponentialMomentWeierstrass.evaluate (moment), 7, 2, 1.
  129.             ) + "}";
  130.         }

  131.         System.out.println (display + "|");
  132.     }

  133.     public static final void main (
  134.         final String[] argumentArray)
  135.         throws Exception
  136.     {
  137.         EnvManager.InitEnv ("");

  138.         double[] tauArray =
  139.         {
  140.             0.5,
  141.             1.0,
  142.             1.5,
  143.             2.0,
  144.         };
  145.         double[] betaArray =
  146.         {
  147.             0.5,
  148.             1.0,
  149.             1.5,
  150.             2.0,
  151.         };
  152.         double[] momentArray =
  153.         {
  154.             1.,
  155.             2.,
  156.             3.,
  157.             4.,
  158.             5.,
  159.         };

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

  162.         System.out.println
  163.             ("\t|                                             STRETCHED EXPONENTIAL INTEGRAL vs. WERERSTRASS ESTIMATE                                             |");

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

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

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

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

  172.         System.out.println
  173.             ("\t|                - Integral vs. Weierstrass Moment Comparison                                                                                     |");

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

  176.         for (double tau : tauArray)
  177.         {
  178.             for (double beta : betaArray)
  179.             {
  180.                 Estimate (
  181.                     tau,
  182.                     beta,
  183.                     momentArray
  184.                 );
  185.             }
  186.         }

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

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