KummerPfaffSecondTransformation.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.definition.RegularHypergeometricEstimator;
  8. import org.drip.specialfunction.hypergeometric.EulerQuadratureEstimator;

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

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

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

  107. public class KummerPfaffSecondTransformation
  108. {

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

  127.         RegularHypergeometricEstimator regularHypergeometricEstimatorPfaffSecondTransform =
  128.             regularHypergeometricEstimator.albinatePfaffSecond();

  129.         for (double z : zArray)
  130.         {
  131.             System.out.println ("\t| {a=" +
  132.                 FormatUtil.FormatDouble (a, 1, 2, 1., false) + ", b=" +
  133.                 FormatUtil.FormatDouble (b, 1, 2, 1., false) + "; c=" +
  134.                 FormatUtil.FormatDouble (c, 1, 2, 1., false) + "; z=" +
  135.                 FormatUtil.FormatDouble (z, 1, 2, 1.) + "} => " +
  136.                 FormatUtil.FormatDouble (regularHypergeometricEstimator.evaluate (z), 2, 10, 1., false) + " | " +
  137.                 FormatUtil.FormatDouble (regularHypergeometricEstimatorPfaffSecondTransform.evaluate (z), 2, 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[] bArray =
  152.         {
  153.             3.,
  154.             4.,
  155.         };
  156.         double[] cArray =
  157.         {
  158.             5.,
  159.             6.,
  160.         };
  161.         double[] zArray =
  162.         {
  163.             -1.00,
  164.             -0.75,
  165.             -0.50,
  166.             -0.25,
  167.              0.00,
  168.              0.25,
  169.              0.50,
  170.         };
  171.         int logBetaTermCount = 1000;
  172.         int hypergeometricQuadratureCount = 10000;

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

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

  175.         System.out.println ("\t|       HYPER-GEOMETRIC KUMMER SECOND PFAFF TRANSFORM RECONCILE      ||");

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

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

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

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

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

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

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

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

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

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

  202.         EnvManager.TerminateEnv();
  203.     }
  204. }