KummerConfluentEstimate.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.ConfluentHypergeometricEstimator;
  7. import org.drip.specialfunction.definition.HypergeometricParameters;
  8. import org.drip.specialfunction.derived.Kummer;
  9. import org.drip.specialfunction.hypergeometric.EulerQuadratureEstimator;

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

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

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

  108. public class KummerConfluentEstimate
  109. {

  110.     private static final void ConfluentHypergeometric (
  111.         final double a,
  112.         final double b,
  113.         final double c,
  114.         final R2ToR1 logBetaEstimator,
  115.         final int quadratureCount,
  116.         final double[] zArray)
  117.         throws Exception
  118.     {
  119.         ConfluentHypergeometricEstimator confluentHypergeometricEstimator = new Kummer (
  120.             new EulerQuadratureEstimator (
  121.                 new HypergeometricParameters (
  122.                     a,
  123.                     b,
  124.                     c
  125.                 ),
  126.                 logBetaEstimator,
  127.                 quadratureCount
  128.             )
  129.         );

  130.         for (double z : zArray)
  131.         {
  132.             System.out.println ("\t| {a=" +
  133.                 FormatUtil.FormatDouble (a, 1, 2, 1., false) + ", b=" +
  134.                 FormatUtil.FormatDouble (b, 2, 2, 1., false) + "; c=" +
  135.                 FormatUtil.FormatDouble (c, 2, 2, 1., false) + "; z=" +
  136.                 FormatUtil.FormatDouble (z, 1, 2, 1.) + "} => " +
  137.                 FormatUtil.FormatDouble (confluentHypergeometricEstimator.evaluate (z), 1, 10, 1., false) + " ||"
  138.             );
  139.         }
  140.     }

  141.     public static final void main (
  142.         final String[] argumentArray)
  143.         throws Exception
  144.     {
  145.         EnvManager.InitEnv ("");

  146.         double[] aArray =
  147.         {
  148.             1.,
  149.             2.,
  150.         };
  151.         double[] cArray =
  152.         {
  153.             15.,
  154.             16.,
  155.         };
  156.         double[] cMinusBArray =
  157.         {
  158.             1.,
  159.             2.,
  160.             3.,
  161.             4.,
  162.             5.,
  163.             6.
  164.         };
  165.         double[] zArray =
  166.         {
  167.             -1.00,
  168.             -0.75,
  169.             -0.50,
  170.             -0.25,
  171.              0.00,
  172.              0.25,
  173.              0.50,
  174.              0.75,
  175.              1.00
  176.         };
  177.         int logBetaTermCount = 1000;
  178.         int hypergeometricQuadratureCount = 10000;

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

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

  181.         System.out.println ("\t| KUMMER CONFLUENT HYPER-GEOMETRIC FUNCTION ESTIMATE  ||");

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

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

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

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

  186.         System.out.println ("\t|                - c Minus b                          ||");

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

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

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

  190.         for (double a : aArray)
  191.         {
  192.             for (double cMinusB : cMinusBArray)
  193.             {
  194.                 for (double c : cArray)
  195.                 {
  196.                     ConfluentHypergeometric (
  197.                         a,
  198.                         c - cMinusB,
  199.                         c,
  200.                         logBetaEstimator,
  201.                         hypergeometricQuadratureCount,
  202.                         zArray
  203.                     );
  204.                 }
  205.             }
  206.         }

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

  208.         EnvManager.TerminateEnv();
  209.     }
  210. }