EllipticKIntegralEstimate.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.EllipticKIntegralEstimator;
  7. import org.drip.specialfunction.derived.EllipticKIntegral;

  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>EllipticKIntegralEstimate</i> estimates the Elliptic K-Integral Function using the 2F1 Hyper-geometric
  70.  * Function. 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 EllipticKIntegralEstimate
  107. {

  108.     private static final void EllipticKIntegral (
  109.         final R2ToR1 logBetaEstimator,
  110.         final int quadratureCount,
  111.         final double[] zArray)
  112.         throws Exception
  113.     {
  114.         EllipticKIntegralEstimator ellipticKIntegralEstimator = new EllipticKIntegral (
  115.             logBetaEstimator,
  116.             quadratureCount
  117.         );

  118.         for (double z : zArray)
  119.         {
  120.             System.out.println ("\t| {z=" +
  121.                 FormatUtil.FormatDouble (z, 1, 2, 1.) + "} => " +
  122.                 FormatUtil.FormatDouble (ellipticKIntegralEstimator.evaluate (z), 1, 10, 1., false) + " ||"
  123.             );
  124.         }
  125.     }

  126.     public static final void main (
  127.         final String[] argumentArray)
  128.         throws Exception
  129.     {
  130.         EnvManager.InitEnv ("");

  131.         double[] zArray =
  132.         {
  133.             -1.00,
  134.             -0.90,
  135.             -0.80,
  136.             -0.70,
  137.             -0.60,
  138.             -0.50,
  139.             -0.40,
  140.             -0.30,
  141.             -0.20,
  142.             -0.10,
  143.              0.00,
  144.              0.10,
  145.              0.20,
  146.              0.30,
  147.              0.40,
  148.              0.50,
  149.              0.60,
  150.              0.70,
  151.              0.80,
  152.              0.90,
  153.              1.00
  154.         };
  155.         int logBetaTermCount = 1000;
  156.         int hypergeometricQuadratureCount = 10000;

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

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

  159.         System.out.println ("\t|    ELLIPTIC K INTEGRAL    ||");

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

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

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

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

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

  165.         EllipticKIntegral (
  166.             logBetaEstimator,
  167.             hypergeometricQuadratureCount,
  168.             zArray
  169.         );

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

  171.         EnvManager.TerminateEnv();
  172.     }
  173. }