LowerSFixedSeries.java

  1. package org.drip.specialfunction.incompletegamma;

  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>LowerSFixedSeries</i> implements Lower Incomplete Gamma Expansion Series. The References are:
  76.  *
  77.  * <br><br>
  78.  *  <ul>
  79.  *      <li>
  80.  *          Geddes, K. O., M. L. Glasser, R. A. Moore, and T. C. Scott (1990): Evaluation of Classes of
  81.  *              Definite Integrals involving Elementary Functions via Differentiation of Special Functions
  82.  *              <i>Applicable Algebra in Engineering, Communications, and </i> <b>1 (2)</b> 149-165
  83.  *      </li>
  84.  *      <li>
  85.  *          Gradshteyn, I. S., I. M. Ryzhik, Y. V. Geronimus, M. Y. Tseytlin, and A. Jeffrey (2015):
  86.  *              <i>Tables of Integrals, Series, and Products</i> <b>Academic Press</b>
  87.  *      </li>
  88.  *      <li>
  89.  *          Mathar, R. J. (2010): Numerical Evaluation of the Oscillatory Integral over
  90.  *              e<sup>iÏ€x</sup> x<sup>(1/x)</sup> between 1 and ∞
  91.  *              https://arxiv.org/pdf/0912.3844.pdf <b>arXiV</b>
  92.  *      </li>
  93.  *      <li>
  94.  *          National Institute of Standards and Technology (2019): Incomplete Gamma and Related Functions
  95.  *              https://dlmf.nist.gov/8
  96.  *      </li>
  97.  *      <li>
  98.  *          Wikipedia (2019): Incomplete Gamma Function
  99.  *              https://en.wikipedia.org/wiki/Incomplete_gamma_function
  100.  *      </li>
  101.  *  </ul>
  102.  *
  103.  *  <br><br>
  104.  *  <ul>
  105.  *      <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/ComputationalCore.md">Computational Core Module</a></li>
  106.  *      <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/FunctionAnalysisLibrary.md">Function Analysis Library</a></li>
  107.  *      <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>
  108.  *      <li><b>Package</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/specialfunction/gammaincomplete/README.md">Upper/Lower Incomplete Gamma Functions</a></li>
  109.  *  </ul>
  110.  *
  111.  * @author Lakshmi Krishnamurthy
  112.  */

  113. public class LowerSFixedSeries extends org.drip.numerical.estimation.R1ToR1Series
  114. {
  115.     private double _s = java.lang.Double.NaN;
  116.     private double _logGammaS = java.lang.Double.NaN;

  117.     /**
  118.      * Construct the R<sup>1</sup> To R<sup>1</sup> Weierstrass Limit Series
  119.      *
  120.      * @param s Incomplete Gamma s
  121.      * @param termCount Count of the Number of Terms
  122.      *
  123.      * @return The R<sup>1</sup> To R<sup>1</sup> Weierstrass Limit Series
  124.      */

  125.     public static final LowerSFixedSeries WeierstrassLimit (
  126.         final double s,
  127.         final int termCount)
  128.     {
  129.         java.util.TreeMap<java.lang.Integer, java.lang.Double> termWeightMap = new
  130.             java.util.TreeMap<java.lang.Integer, java.lang.Double>();

  131.         for (int termIndex = 0; termIndex <= termCount; ++termIndex)
  132.         {
  133.             termWeightMap.put (
  134.                 termIndex,
  135.                 1.
  136.             );
  137.         }

  138.         try
  139.         {
  140.             return new LowerSFixedSeries (
  141.                 org.drip.specialfunction.incompletegamma.LowerSFixedSeriesTerm.WeierstrassLimit (s),
  142.                 termWeightMap,
  143.                 s,
  144.                 0 == s ? 1. : new org.drip.specialfunction.loggamma.NemesAnalyticEstimator (null).evaluate (s)
  145.             );
  146.         }
  147.         catch (java.lang.Exception e)
  148.         {
  149.             e.printStackTrace();
  150.         }

  151.         return null;
  152.     }

  153.     /**
  154.      * Construct the R<sup>1</sup> To R<sup>1</sup> NIST (2019) Limit Series
  155.      *
  156.      * @param s Incomplete Gamma s
  157.      * @param termCount Count of the Number of Terms
  158.      *
  159.      * @return The R<sup>1</sup> To R<sup>1</sup> NIST (2019) Limit Series
  160.      */

  161.     public static final LowerSFixedSeries NIST2019 (
  162.         final double s,
  163.         final int termCount)
  164.     {
  165.         try
  166.         {
  167.             double logGammaS = new org.drip.specialfunction.loggamma.NemesAnalyticEstimator (null).evaluate (s);

  168.             java.util.TreeMap<java.lang.Integer, java.lang.Double> termWeightMap = new
  169.                 java.util.TreeMap<java.lang.Integer, java.lang.Double>();

  170.             for (int termIndex = 0; termIndex <= termCount; ++termIndex)
  171.             {
  172.                 termWeightMap.put (
  173.                     termIndex,
  174.                     1.
  175.                 );
  176.             }

  177.             return new LowerSFixedSeries (
  178.                 org.drip.specialfunction.incompletegamma.LowerSFixedSeriesTerm.NIST2019 (
  179.                     s,
  180.                     logGammaS
  181.                 ),
  182.                 termWeightMap,
  183.                 s,
  184.                 logGammaS
  185.             );
  186.         }
  187.         catch (java.lang.Exception e)
  188.         {
  189.             e.printStackTrace();
  190.         }

  191.         return null;
  192.     }

  193.     /**
  194.      * LowerSFixedSeries Constructor
  195.      *
  196.      * @param r1ToR1SeriesTerm R<sup>1</sup> To R<sup>1</sup> Series Expansion Term
  197.      * @param termWeightMap Error Term Weight Map
  198.      * @param s s
  199.      * @param logGammaS Log (Gamma (s))
  200.      *
  201.      * @throws java.lang.Exception Thrown if the Inputs are Invalid
  202.      */

  203.     public LowerSFixedSeries (
  204.         final org.drip.numerical.estimation.R1ToR1SeriesTerm r1ToR1SeriesTerm,
  205.         final java.util.TreeMap<java.lang.Integer, java.lang.Double> termWeightMap,
  206.         final double s,
  207.         final double logGammaS)
  208.         throws java.lang.Exception
  209.     {
  210.         super (
  211.             r1ToR1SeriesTerm,
  212.             false,
  213.             termWeightMap
  214.         );

  215.         if (!org.drip.numerical.common.NumberUtil.IsValid (_s = s) ||
  216.             !org.drip.numerical.common.NumberUtil.IsValid (_logGammaS = logGammaS))
  217.         {
  218.             throw new java.lang.Exception ("LowerSFixedSeries Constructor => Invalid Inputs");
  219.         }
  220.     }

  221.     /**
  222.      * Retrieve s
  223.      *
  224.      * @return s
  225.      */

  226.     public double s()
  227.     {
  228.         return _s;
  229.     }

  230.     /**
  231.      * Retrieve Log (Gamma (s))
  232.      *
  233.      * @return Log (Gamma (s))
  234.      */

  235.     public double logGammaS()
  236.     {
  237.         return _logGammaS;
  238.     }
  239. }