EulerQuadratureEstimate.java

  1. package org.drip.sample.hypergeometric;

  2. import org.drip.function.definition.R2ToR1;
  3. import org.drip.numerical.common.FormatUtil;
  4. import org.drip.service.env.EnvManager;
  5. import org.drip.specialfunction.beta.LogGammaEstimator;
  6. import org.drip.specialfunction.definition.HypergeometricParameters;
  7. import org.drip.specialfunction.hypergeometric.EulerQuadratureEstimator;

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

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

  68. /**
  69.  * <i>EulerQuadratureEstimate</i> estimates the Hyper-geometric Function using the Euler Integral
  70.  * Representation. The References are:
  71.  *
  72.  * <br><br>
  73.  *  <ul>
  74.  *      <li>
  75.  *          Gessel, I., and D. Stanton (1982): Strange Evaluations of Hyper-geometric Series <i>SIAM Journal
  76.  *              on Mathematical Analysis</i> <b>13 (2)</b> 295-308
  77.  *      </li>
  78.  *      <li>
  79.  *          Koepf, W (1995): Algorithms for m-fold Hyper-geometric Summation <i>Journal of Symbolic
  80.  *              Computation</i> <b>20 (4)</b> 399-417
  81.  *      </li>
  82.  *      <li>
  83.  *          Lavoie, J. L., F. Grondin, and A. K. Rathie (1996): Generalization of Whipple’s Theorem on the
  84.  *              Sum of a (_2^3)F(a,b;c;z) <i>Journal of Computational and Applied Mathematics</i> <b>72</b>
  85.  *              293-300
  86.  *      </li>
  87.  *      <li>
  88.  *          National Institute of Standards and Technology (2019): Hyper-geometric Function
  89.  *              https://dlmf.nist.gov/15
  90.  *      </li>
  91.  *      <li>
  92.  *          Wikipedia (2019): Hyper-geometric Function https://en.wikipedia.org/wiki/Hypergeometric_function
  93.  *      </li>
  94.  *  </ul>
  95.  *
  96.  *  <br><br>
  97.  *  <ul>
  98.  *      <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/NumericalCore.md">Numerical Core Module</a></li>
  99.  *      <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/NumericalOptimizerLibrary.md">Numerical Optimizer</a></li>
  100.  *      <li><b>Project</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/sample/README.md">Function</a></li>
  101.  *      <li><b>Package</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/sample/hypergeometric/README.md">Estimates of Hyper-geometric Function</a></li>
  102.  *  </ul>
  103.  *
  104.  * @author Lakshmi Krishnamurthy
  105.  */

  106. public class EulerQuadratureEstimate
  107. {

  108.     private static final void Hypergeometric (
  109.         final double a,
  110.         final double b,
  111.         final double c,
  112.         final R2ToR1 logBetaEstimator,
  113.         final int quadratureCount,
  114.         final double[] zArray)
  115.         throws Exception
  116.     {
  117.         EulerQuadratureEstimator eulerQuadratureEstimator = new EulerQuadratureEstimator (
  118.             new HypergeometricParameters (
  119.                 a,
  120.                 b,
  121.                 c
  122.             ),
  123.             logBetaEstimator,
  124.             quadratureCount
  125.         );

  126.         for (double z : zArray)
  127.         {
  128.             System.out.println ("\t| {a=" +
  129.                 FormatUtil.FormatDouble (a, 1, 2, 1., false) + ", b=" +
  130.                 FormatUtil.FormatDouble (b, 1, 2, 1., false) + "; c=" +
  131.                 FormatUtil.FormatDouble (c, 1, 2, 1., false) + "; z=" +
  132.                 FormatUtil.FormatDouble (z, 1, 2, 1.) + "} => " +
  133.                 FormatUtil.FormatDouble (eulerQuadratureEstimator.evaluate (z), 2, 10, 1., false) + " ||"
  134.             );
  135.         }
  136.     }

  137.     public static final void main (
  138.         final String[] argumentArray)
  139.         throws Exception
  140.     {
  141.         EnvManager.InitEnv ("");

  142.         double[] aArray =
  143.         {
  144.             1.,
  145.             2.,
  146.         };
  147.         double[] bArray =
  148.         {
  149.             3.,
  150.             4.,
  151.         };
  152.         double[] cArray =
  153.         {
  154.             5.,
  155.             6.,
  156.         };
  157.         double[] zArray =
  158.         {
  159.             -1.00,
  160.             -0.75,
  161.             -0.50,
  162.             -0.25,
  163.              0.00,
  164.              0.25,
  165.              0.50,
  166.              0.75,
  167.              1.00
  168.         };
  169.         int logBetaTermCount = 1000;
  170.         int hypergeometricQuadratureCount = 10000;

  171.         R2ToR1 logBetaEstimator = LogGammaEstimator.Weierstrass (logBetaTermCount);

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

  173.         System.out.println ("\t| HYPER-GEOMETRIC FUNCTION EULER QUADRATURE ESTIMATE ||");

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

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

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

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

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

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

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

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

  182.         for (double a : aArray)
  183.         {
  184.             for (double b : bArray)
  185.             {
  186.                 for (double c : cArray)
  187.                 {
  188.                     Hypergeometric (
  189.                         a,
  190.                         b,
  191.                         c,
  192.                         logBetaEstimator,
  193.                         hypergeometricQuadratureCount,
  194.                         zArray
  195.                     );
  196.                 }
  197.             }
  198.         }

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

  200.         EnvManager.TerminateEnv();
  201.     }
  202. }