NumericalEstimate.java

  1. package org.drip.sample.beta;

  2. import org.drip.numerical.common.FormatUtil;
  3. import org.drip.service.env.EnvManager;
  4. import org.drip.specialfunction.beta.IntegrandEstimator;
  5. import org.drip.specialfunction.beta.LogGammaEstimator;
  6. import org.drip.specialfunction.beta.SummationSeriesEstimator;

  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>NumericalEstimate</i> illustrates the Beta Function Estimation using Integrand Schemes. The References
  81.  * are:
  82.  *
  83.  * <br><br>
  84.  *  <ul>
  85.  *      <li>
  86.  *          Abramowitz, M., and I. A. Stegun (2007): <i>Handbook of Mathematics Functions</i> <b>Dover Book
  87.  *              on Mathematics</b>
  88.  *      </li>
  89.  *      <li>
  90.  *          Davis, P. J. (1959): Leonhard Euler's Integral: A Historical Profile of the Gamma Function
  91.  *              <i>American Mathematical Monthly</i> <b>66 (10)</b> 849-869
  92.  *      </li>
  93.  *      <li>
  94.  *          Whitaker, E. T., and G. N. Watson (1996): <i>A Course on Modern Analysis</i> <b>Cambridge
  95.  *              University Press</b> New York
  96.  *      </li>
  97.  *      <li>
  98.  *          Wikipedia (2019): Beta Function https://en.wikipedia.org/wiki/Beta_function
  99.  *      </li>
  100.  *      <li>
  101.  *          Wikipedia (2019): Gamma Function https://en.wikipedia.org/wiki/Gamma_function
  102.  *      </li>
  103.  *  </ul>
  104.  *
  105.  *  <br><br>
  106.  *  <ul>
  107.  *      <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/ComputationalCore.md">Computational Core Module</a></li>
  108.  *      <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/FunctionAnalysisLibrary.md">Function Analysis Library</a></li>
  109.  *      <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>
  110.  *      <li><b>Package</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/sample/beta/README.md">Estimates of the Beta Functions</a></li>
  111.  *  </ul>
  112.  *
  113.  * @author Lakshmi Krishnamurthy
  114.  */

  115. public class NumericalEstimate
  116. {

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

  122.         int eulerIntegrandRightHalfPlaneTermCount = 1000;
  123.         int trigonometricIntegrandTermCount = 1000;
  124.         int eulerIntegrandTermCount = 1000;
  125.         int summationTermCount = 1000000;
  126.         int logGammaTermCount = 1000000;
  127.         double[] xArray =
  128.         {
  129.             1.,
  130.             2.,
  131.             3.,
  132.             4.,
  133.             5.,
  134.             6.,
  135.         };
  136.         double[] yArray =
  137.         {
  138.             1.,
  139.             2.,
  140.             3.,
  141.             4.,
  142.             5.,
  143.             6.,
  144.         };

  145.         LogGammaEstimator logGammaEstimator = LogGammaEstimator.Weierstrass (logGammaTermCount);

  146.         IntegrandEstimator eulerFirstIntegrandEstimator = IntegrandEstimator.EulerFirst
  147.             (eulerIntegrandTermCount);

  148.         IntegrandEstimator eulerFirstRightHalfPlane = IntegrandEstimator.EulerFirstRightPlane
  149.             (eulerIntegrandRightHalfPlaneTermCount);

  150.         IntegrandEstimator trigonometricIntegrandEstimator = IntegrandEstimator.Trigonometric
  151.             (trigonometricIntegrandTermCount);

  152.         SummationSeriesEstimator summationSeriesEstimator = SummationSeriesEstimator.AbramowitzStegun2007
  153.             (summationTermCount);

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

  155.         System.out.println ("\t|                                 BETA FUNCTION ESTIMATION                                ||");

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

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

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

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

  160.         System.out.println ("\t|                - Gamma Based Estimate                                                   ||");

  161.         System.out.println ("\t|                - Euler Integral First Kind Estimate                                     ||");

  162.         System.out.println ("\t|                - Euler Integral First Right Half Plane Estimate                         ||");

  163.         System.out.println ("\t|                - Trigonometric Integral Estimate                                        ||");

  164.         System.out.println ("\t|                - Summation Series Estimate                                              ||");

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

  166.         for (double x : xArray)
  167.         {
  168.             for (double y : yArray)
  169.             {
  170.                 System.out.println (
  171.                     "\t| [" +
  172.                     FormatUtil.FormatDouble (x, 1, 1, 1.) + "," +
  173.                     FormatUtil.FormatDouble (y, 1, 1, 1.) + "] =>" +
  174.                     FormatUtil.FormatDouble (
  175.                         Math.exp (
  176.                             logGammaEstimator.evaluate (
  177.                                 x,
  178.                                 y
  179.                             )
  180.                         ), 1, 10, 1.
  181.                     ) + " |" +
  182.                     FormatUtil.FormatDouble (
  183.                         eulerFirstIntegrandEstimator.evaluate (
  184.                             x,
  185.                             y
  186.                         ), 1, 10, 1.
  187.                     ) + " |" +
  188.                     FormatUtil.FormatDouble (
  189.                         eulerFirstRightHalfPlane.evaluate (
  190.                             x,
  191.                             y
  192.                         ), 1, 10, 1.
  193.                     ) + " |" +
  194.                     FormatUtil.FormatDouble (
  195.                         trigonometricIntegrandEstimator.evaluate (
  196.                             x,
  197.                             y
  198.                         ), 1, 10, 1.
  199.                     ) + " |" +
  200.                     FormatUtil.FormatDouble (
  201.                         summationSeriesEstimator.evaluate (
  202.                             x,
  203.                             y
  204.                         ), 1, 10, 1.
  205.                     ) + " ||"
  206.                 );
  207.             }
  208.         }

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

  210.         EnvManager.TerminateEnv();
  211.     }
  212. }