AlphaZeroFirstApproximate.java

  1. package org.drip.sample.bessel;

  2. import org.drip.numerical.common.FormatUtil;
  3. import org.drip.service.env.EnvManager;
  4. import org.drip.specialfunction.bessel.FirstFrobeniusSeriesEstimator;
  5. import org.drip.specialfunction.definition.BesselFirstKindEstimator;
  6. import org.drip.specialfunction.gamma.EulerIntegralSecondKind;

  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>AlphaZeroFirstApproximate</i> illustrates the Alpha=0 Approximation for the Cylindrical Bessel Function
  81.  * of the First Kind. The References 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.  *          Arfken, G. B., and H. J. Weber (2005): <i>Mathematical Methods for Physicists 6<sup>th</sup>
  91.  *              Edition</i> <b>Harcourt</b> San Diego
  92.  *      </li>
  93.  *      <li>
  94.  *          Temme N. M. (1996): <i>Special Functions: An Introduction to the Classical Functions of
  95.  *              Mathematical Physics 2<sup>nd</sup> Edition</i> <b>Wiley</b> New York
  96.  *      </li>
  97.  *      <li>
  98.  *          Watson, G. N. (1995): <i>A Treatise on the Theory of Bessel Functions</i> <b>Cambridge University
  99.  *              Press</b>
  100.  *      </li>
  101.  *      <li>
  102.  *          Wikipedia (2019): Bessel Function https://en.wikipedia.org/wiki/Bessel_function
  103.  *      </li>
  104.  *  </ul>
  105.  *
  106.  *  <br><br>
  107.  *  <ul>
  108.  *      <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/ComputationalCore.md">Computational Core Module</a></li>
  109.  *      <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/FunctionAnalysisLibrary.md">Function Analysis Library</a></li>
  110.  *      <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>
  111.  *      <li><b>Package</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/sample/bessel/README.md">Estimates of the Bessel Functions</a></li>
  112.  *  </ul>
  113.  *
  114.  * @author Lakshmi Krishnamurthy
  115.  */

  116. public class AlphaZeroFirstApproximate
  117. {

  118.     private static final void BesselJ (
  119.         final BesselFirstKindEstimator besselFirstKindEstimatorApproximate,
  120.         final BesselFirstKindEstimator besselFirstKindEstimator,
  121.         final double[] zArray)
  122.         throws Exception
  123.     {
  124.         System.out.println ("\t|-----------------------------------------------||");

  125.         System.out.println ("\t|        ALPHA 0 BESSEL FIRST ASYMPTOTE         ||");

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

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

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

  129.         System.out.println ("\t|                - Bessel Approximate           ||");

  130.         System.out.println ("\t|                - Bessel Frobenius             ||");

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

  132.         for (double z : zArray)
  133.         {
  134.             String display = "\t| [" +
  135.                 FormatUtil.FormatDouble (z, 2, 1, 1., false) + "] => " +
  136.                 FormatUtil.FormatDouble (
  137.                     besselFirstKindEstimatorApproximate.bigJ (
  138.                         0.,
  139.                         z
  140.                     ), 1, 10, 1.
  141.                 ) + " | " +
  142.                 FormatUtil.FormatDouble (
  143.                     besselFirstKindEstimator.bigJ (
  144.                         0.,
  145.                         z
  146.                     ), 1, 10, 1.
  147.                 ) + " |";

  148.             System.out.println (display + "|");
  149.         }

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

  151.         System.out.println();
  152.     }

  153.     public static final void main (
  154.         final String[] argumentArray)
  155.         throws Exception
  156.     {
  157.         EnvManager.InitEnv ("");

  158.         int frobeniusTermCount = 100;
  159.         double[] zArray =
  160.         {
  161.             -20.,
  162.             -19.,
  163.             -18.,
  164.             -17.,
  165.             -16.,
  166.             -15.,
  167.             -14.,
  168.             -13.,
  169.             -12.,
  170.             -11.,
  171.             -10.,
  172.              -9.,
  173.              -8.,
  174.              -7.,
  175.              -6.,
  176.              -5.,
  177.              -4.,
  178.              -3.,
  179.              -2.,
  180.              -1.,
  181.               0.,
  182.               1.,
  183.               2.,
  184.               3.,
  185.               4.,
  186.               5.,
  187.               6.,
  188.               7.,
  189.               8.,
  190.               9.,
  191.              10.,
  192.              11.,
  193.              12.,
  194.              13.,
  195.              14.,
  196.              15.,
  197.              16.,
  198.              17.,
  199.              18.,
  200.              19.,
  201.              20.,
  202.         };

  203.         BesselJ (
  204.             BesselFirstKindEstimator.AlphaZeroApproximate(),
  205.             FirstFrobeniusSeriesEstimator.Standard (
  206.                 new EulerIntegralSecondKind (null),
  207.                 frobeniusTermCount
  208.             ),
  209.             zArray
  210.         );

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