SphericalFirstEstimator.java

  1. package org.drip.specialfunction.bessel;

  2. /*
  3.  * -*- mode: java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  4.  */

  5. /*!
  6.  * Copyright (C) 2020 Lakshmi Krishnamurthy
  7.  * Copyright (C) 2019 Lakshmi Krishnamurthy
  8.  *
  9.  *  This file is part of DROP, an open-source library targeting analytics/risk, transaction cost analytics,
  10.  *      asset liability management analytics, capital, exposure, and margin analytics, valuation adjustment
  11.  *      analytics, and portfolio construction analytics within and across fixed income, credit, commodity,
  12.  *      equity, FX, and structured products. It also includes auxiliary libraries for algorithm support,
  13.  *      numerical analysis, numerical optimization, spline builder, model validation, statistical learning,
  14.  *      and computational support.
  15.  *  
  16.  *      https://lakshmidrip.github.io/DROP/
  17.  *  
  18.  *  DROP is composed of three modules:
  19.  *  
  20.  *  - DROP Product Core - https://lakshmidrip.github.io/DROP-Product-Core/
  21.  *  - DROP Portfolio Core - https://lakshmidrip.github.io/DROP-Portfolio-Core/
  22.  *  - DROP Computational Core - https://lakshmidrip.github.io/DROP-Computational-Core/
  23.  *
  24.  *  DROP Product Core implements libraries for the following:
  25.  *  - Fixed Income Analytics
  26.  *  - Loan Analytics
  27.  *  - Transaction Cost Analytics
  28.  *
  29.  *  DROP Portfolio Core implements libraries for the following:
  30.  *  - Asset Allocation Analytics
  31.  *  - Asset Liability Management Analytics
  32.  *  - Capital Estimation Analytics
  33.  *  - Exposure Analytics
  34.  *  - Margin Analytics
  35.  *  - XVA Analytics
  36.  *
  37.  *  DROP Computational Core implements libraries for the following:
  38.  *  - Algorithm Support
  39.  *  - Computation Support
  40.  *  - Function Analysis
  41.  *  - Model Validation
  42.  *  - Numerical Analysis
  43.  *  - Numerical Optimizer
  44.  *  - Spline Builder
  45.  *  - Statistical Learning
  46.  *
  47.  *  Documentation for DROP is Spread Over:
  48.  *
  49.  *  - Main                     => https://lakshmidrip.github.io/DROP/
  50.  *  - Wiki                     => https://github.com/lakshmiDRIP/DROP/wiki
  51.  *  - GitHub                   => https://github.com/lakshmiDRIP/DROP
  52.  *  - Repo Layout Taxonomy     => https://github.com/lakshmiDRIP/DROP/blob/master/Taxonomy.md
  53.  *  - Javadoc                  => https://lakshmidrip.github.io/DROP/Javadoc/index.html
  54.  *  - Technical Specifications => https://github.com/lakshmiDRIP/DROP/tree/master/Docs/Internal
  55.  *  - Release Versions         => https://lakshmidrip.github.io/DROP/version.html
  56.  *  - Community Credits        => https://lakshmidrip.github.io/DROP/credits.html
  57.  *  - Issues Catalog           => https://github.com/lakshmiDRIP/DROP/issues
  58.  *  - JUnit                    => https://lakshmidrip.github.io/DROP/junit/index.html
  59.  *  - Jacoco                   => https://lakshmidrip.github.io/DROP/jacoco/index.html
  60.  *
  61.  *  Licensed under the Apache License, Version 2.0 (the "License");
  62.  *      you may not use this file except in compliance with the License.
  63.  *  
  64.  *  You may obtain a copy of the License at
  65.  *      http://www.apache.org/licenses/LICENSE-2.0
  66.  *  
  67.  *  Unless required by applicable law or agreed to in writing, software
  68.  *      distributed under the License is distributed on an "AS IS" BASIS,
  69.  *      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  70.  *  
  71.  *  See the License for the specific language governing permissions and
  72.  *      limitations under the License.
  73.  */

  74. /**
  75.  * <i>SphericalFirstEstimator</i> implements the Integral Estimator for the Spherical Bessel Function of the
  76.  * First Kind. The References are:
  77.  *
  78.  * <br><br>
  79.  *  <ul>
  80.  *      <li>
  81.  *          Abramowitz, M., and I. A. Stegun (2007): <i>Handbook of Mathematics Functions</i> <b>Dover Book
  82.  *              on Mathematics</b>
  83.  *      </li>
  84.  *      <li>
  85.  *          Arfken, G. B., and H. J. Weber (2005): <i>Mathematical Methods for Physicists 6<sup>th</sup>
  86.  *              Edition</i> <b>Harcourt</b> San Diego
  87.  *      </li>
  88.  *      <li>
  89.  *          Temme N. M. (1996): <i>Special Functions: An Introduction to the Classical Functions of
  90.  *              Mathematical Physics 2<sup>nd</sup> Edition</i> <b>Wiley</b> New York
  91.  *      </li>
  92.  *      <li>
  93.  *          Watson, G. N. (1995): <i>A Treatise on the Theory of Bessel Functions</i> <b>Cambridge University
  94.  *              Press</b>
  95.  *      </li>
  96.  *      <li>
  97.  *          Wikipedia (2019): Bessel Function https://en.wikipedia.org/wiki/Bessel_function
  98.  *      </li>
  99.  *  </ul>
  100.  *
  101.  *  <br><br>
  102.  *  <ul>
  103.  *      <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/ComputationalCore.md">Computational Core Module</a></li>
  104.  *      <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/FunctionAnalysisLibrary.md">Function Analysis Library</a></li>
  105.  *      <li><b>Project</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/specialfunction/README.md">Special Function Implementation Analysis</a></li>
  106.  *      <li><b>Package</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/specialfunction/bessel/README.md">Ordered Bessel Function Variant Estimators</a></li>
  107.  *  </ul>
  108.  *
  109.  * @author Lakshmi Krishnamurthy
  110.  */

  111. public class SphericalFirstEstimator extends
  112.     org.drip.specialfunction.definition.SphericalBesselFirstKindEstimator
  113. {
  114.     private org.drip.specialfunction.definition.BesselFirstKindEstimator _besselFirstKindEstimator = null;

  115.     /**
  116.      * Retrieve the Order 0 Spherical Bessel First Kind Estimator
  117.      *
  118.      * @return The Order 0 Spherical Bessel First Kind Estimator
  119.      */

  120.     public static final org.drip.specialfunction.definition.SphericalBesselFirstKindEstimator OrderZero()
  121.     {
  122.         return new org.drip.specialfunction.definition.SphericalBesselFirstKindEstimator()
  123.         {
  124.             @Override public double smallJ (
  125.                 final double alpha,
  126.                 final double z)
  127.                 throws java.lang.Exception
  128.             {
  129.                 if (0. != alpha ||
  130.                     !org.drip.numerical.common.NumberUtil.IsValid (z))
  131.                 {
  132.                     throw new java.lang.Exception
  133.                         ("SphericalFirstEstimator::OrderZero::smallJ => Invalid Inputs");
  134.                 }

  135.                 return 0. == z ? 1. : java.lang.Math.sin (z) / z;
  136.             }
  137.         };
  138.     }

  139.     /**
  140.      * Retrieve the Order +1 Spherical Bessel First Kind Estimator
  141.      *
  142.      * @return The Order +1 Spherical Bessel First Kind Estimator
  143.      */

  144.     public static final org.drip.specialfunction.definition.SphericalBesselFirstKindEstimator OrderPlusOne()
  145.     {
  146.         return new org.drip.specialfunction.definition.SphericalBesselFirstKindEstimator()
  147.         {
  148.             @Override public double smallJ (
  149.                 final double alpha,
  150.                 final double z)
  151.                 throws java.lang.Exception
  152.             {
  153.                 if (1. != alpha ||
  154.                     !org.drip.numerical.common.NumberUtil.IsValid (z))
  155.                 {
  156.                     throw new java.lang.Exception
  157.                         ("SphericalFirstEstimator::OrderPlusOne::smallJ => Invalid Inputs");
  158.                 }

  159.                 return java.lang.Math.sin (z) / (z * z) - java.lang.Math.cos (z) / z;
  160.             }
  161.         };
  162.     }

  163.     /**
  164.      * Retrieve the Order -1 Spherical Bessel First Kind Estimator
  165.      *
  166.      * @return The Order -1 Spherical Bessel First Kind Estimator
  167.      */

  168.     public static final org.drip.specialfunction.definition.SphericalBesselFirstKindEstimator OrderMinusOne()
  169.     {
  170.         return new org.drip.specialfunction.definition.SphericalBesselFirstKindEstimator()
  171.         {
  172.             @Override public double smallJ (
  173.                 final double alpha,
  174.                 final double z)
  175.                 throws java.lang.Exception
  176.             {
  177.                 if (-1. != alpha ||
  178.                     !org.drip.numerical.common.NumberUtil.IsValid (z))
  179.                 {
  180.                     throw new java.lang.Exception
  181.                         ("SphericalFirstEstimator::OrderMinusOne::smallJ => Invalid Inputs");
  182.                 }

  183.                 return java.lang.Math.cos (z) / z;
  184.             }
  185.         };
  186.     }

  187.     /**
  188.      * Retrieve the Order +2 Spherical Bessel First Kind Estimator
  189.      *
  190.      * @return The Order +2 Spherical Bessel First Kind Estimator
  191.      */

  192.     public static final org.drip.specialfunction.definition.SphericalBesselFirstKindEstimator OrderPlusTwo()
  193.     {
  194.         return new org.drip.specialfunction.definition.SphericalBesselFirstKindEstimator()
  195.         {
  196.             @Override public double smallJ (
  197.                 final double alpha,
  198.                 final double z)
  199.                 throws java.lang.Exception
  200.             {
  201.                 if (2. != alpha ||
  202.                     !org.drip.numerical.common.NumberUtil.IsValid (z))
  203.                 {
  204.                     throw new java.lang.Exception
  205.                         ("SphericalFirstEstimator::OrderPlusTwo::smallJ => Invalid Inputs");
  206.                 }

  207.                 double oneOverZ = 1. / z;
  208.                 double oneOverZ2 = oneOverZ * oneOverZ;

  209.                 return (3. * oneOverZ2 - 1.) * java.lang.Math.sin (z) * oneOverZ -
  210.                     3. * java.lang.Math.cos (z) * oneOverZ2;
  211.             }
  212.         };
  213.     }

  214.     /**
  215.      * Retrieve the Order -2 Spherical Bessel First Kind Estimator
  216.      *
  217.      * @return The Order -2 Spherical Bessel First Kind Estimator
  218.      */

  219.     public static final org.drip.specialfunction.definition.SphericalBesselFirstKindEstimator OrderMinusTwo()
  220.     {
  221.         return new org.drip.specialfunction.definition.SphericalBesselFirstKindEstimator()
  222.         {
  223.             @Override public double smallJ (
  224.                 final double alpha,
  225.                 final double z)
  226.                 throws java.lang.Exception
  227.             {
  228.                 if (-2. != alpha ||
  229.                     !org.drip.numerical.common.NumberUtil.IsValid (z))
  230.                 {
  231.                     throw new java.lang.Exception
  232.                         ("SphericalFirstEstimator::OrderMinusTwo::smallJ => Invalid Inputs");
  233.                 }

  234.                 double oneOverZ = 1. / z;

  235.                 return -1. * java.lang.Math.cos (z) * oneOverZ * oneOverZ -
  236.                     java.lang.Math.sin (z) * oneOverZ;
  237.             }
  238.         };
  239.     }

  240.     /**
  241.      * Retrieve the Order +3 Spherical Bessel First Kind Estimator
  242.      *
  243.      * @return The Order +3 Spherical Bessel First Kind Estimator
  244.      */

  245.     public static final org.drip.specialfunction.definition.SphericalBesselFirstKindEstimator
  246.         OrderPlusThree()
  247.     {
  248.         return new org.drip.specialfunction.definition.SphericalBesselFirstKindEstimator()
  249.         {
  250.             @Override public double smallJ (
  251.                 final double alpha,
  252.                 final double z)
  253.                 throws java.lang.Exception
  254.             {
  255.                 if (3. != alpha ||
  256.                     !org.drip.numerical.common.NumberUtil.IsValid (z))
  257.                 {
  258.                     throw new java.lang.Exception
  259.                         ("SphericalFirstEstimator::OrderPlusThree::smallJ => Invalid Inputs");
  260.                 }

  261.                 double oneOverZ = 1. / z;
  262.                 double oneOverZ2 = oneOverZ * oneOverZ;

  263.                 return (15. * oneOverZ2 * oneOverZ - 6. * oneOverZ) * java.lang.Math.sin (z) * oneOverZ -
  264.                     (15. * oneOverZ2 - 1.) * java.lang.Math.cos (z) * oneOverZ;
  265.             }
  266.         };
  267.     }

  268.     /**
  269.      * Retrieve the Order -3 Spherical Bessel First Kind Estimator
  270.      *
  271.      * @return The Order -3 Spherical Bessel First Kind Estimator
  272.      */

  273.     public static final org.drip.specialfunction.definition.SphericalBesselFirstKindEstimator
  274.         OrderMinusThree()
  275.     {
  276.         return new org.drip.specialfunction.definition.SphericalBesselFirstKindEstimator()
  277.         {
  278.             @Override public double smallJ (
  279.                 final double alpha,
  280.                 final double z)
  281.                 throws java.lang.Exception
  282.             {
  283.                 if (-3. != alpha ||
  284.                     !org.drip.numerical.common.NumberUtil.IsValid (z))
  285.                 {
  286.                     throw new java.lang.Exception
  287.                         ("SphericalFirstEstimator::OrderMinusThree::smallJ => Invalid Inputs");
  288.                 }

  289.                 double oneOverZ = 1. / z;
  290.                 double oneOverZ2 = oneOverZ * oneOverZ;

  291.                 return (1. - 3. * oneOverZ2) * java.lang.Math.cos (z) * oneOverZ -
  292.                     3. * java.lang.Math.sin (z) * oneOverZ2;
  293.             }
  294.         };
  295.     }

  296.     /**
  297.      * Retrieve the Order -4 Spherical Bessel First Kind Estimator
  298.      *
  299.      * @return The Order -4 Spherical Bessel First Kind Estimator
  300.      */

  301.     public static final org.drip.specialfunction.definition.SphericalBesselFirstKindEstimator
  302.         OrderMinusFour()
  303.     {
  304.         return new org.drip.specialfunction.definition.SphericalBesselFirstKindEstimator()
  305.         {
  306.             @Override public double smallJ (
  307.                 final double alpha,
  308.                 final double z)
  309.                 throws java.lang.Exception
  310.             {
  311.                 if (-4. != alpha ||
  312.                     !org.drip.numerical.common.NumberUtil.IsValid (z))
  313.                 {
  314.                     throw new java.lang.Exception
  315.                         ("SphericalFirstEstimator::OrderOrderMinusFour::smallJ => Invalid Inputs");
  316.                 }

  317.                 double oneOverZ = 1. / z;
  318.                 double oneOverZ2 = oneOverZ * oneOverZ;

  319.                 return (6. * oneOverZ - 15. * oneOverZ2 * oneOverZ) * java.lang.Math.cos (z) * oneOverZ -
  320.                     (15. * oneOverZ2 - 1.) * java.lang.Math.sin (z) * oneOverZ;
  321.             }
  322.         };
  323.     }

  324.     /**
  325.      * SphericalFirstEstimator Constructor
  326.      *
  327.      * @param besselFirstKindEstimator Bessel Function First Kind Estimator
  328.      *
  329.      * @throws java.lang.Exception Thrown if Inputs are Invalid
  330.      */

  331.     public SphericalFirstEstimator (
  332.         final org.drip.specialfunction.definition.BesselFirstKindEstimator besselFirstKindEstimator)
  333.         throws java.lang.Exception
  334.     {
  335.         if (null == (_besselFirstKindEstimator = besselFirstKindEstimator))
  336.         {
  337.             throw new java.lang.Exception ("SphericalFirstEstimator Constructor => Invalid Inputs");
  338.         }
  339.     }

  340.     @Override public double smallJ (
  341.         final double alpha,
  342.         final double z)
  343.         throws java.lang.Exception
  344.     {
  345.         return java.lang.Math.sqrt (0.5 * java.lang.Math.PI / z) * _besselFirstKindEstimator.bigJ (
  346.             alpha + 0.5,
  347.             z
  348.         );
  349.     }

  350.     /**
  351.      * Retrieve the Bessel Function First Kind Estimator
  352.      *
  353.      * @return Bessel Function First Kind Estimator
  354.      */

  355.     public org.drip.specialfunction.definition.BesselFirstKindEstimator besselFirstKindEstimator()
  356.     {
  357.         return _besselFirstKindEstimator;
  358.     }
  359. }