HilleQForm2F1.java

  1. package org.drip.specialfunction.ode;

  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>HilleQForm2F1</i> exposes the Coefficient Terms on the Q-form 2F1 Hyper-geometric ODE. The References
  76.  * are:
  77.  *
  78.  * <br><br>
  79.  *  <ul>
  80.  *      <li>
  81.  *          Gessel, I., and D. Stanton (1982): Strange Evaluations of Hyper-geometric Series <i>SIAM Journal
  82.  *              on Mathematical Analysis</i> <b>13 (2)</b> 295-308
  83.  *      </li>
  84.  *      <li>
  85.  *          Koepf, W (1995): Algorithms for m-fold Hyper-geometric Summation <i>Journal of Symbolic
  86.  *              Computation</i> <b>20 (4)</b> 399-417
  87.  *      </li>
  88.  *      <li>
  89.  *          Lavoie, J. L., F. Grondin, and A. K. Rathie (1996): Generalization of Whipple’s Theorem on the
  90.  *              Sum of a (_2^3)F(a,b;c;z) <i>Journal of Computational and Applied Mathematics</i> <b>72</b>
  91.  *              293-300
  92.  *      </li>
  93.  *      <li>
  94.  *          National Institute of Standards and Technology (2019): Hyper-geometric Function
  95.  *              https://dlmf.nist.gov/15
  96.  *      </li>
  97.  *      <li>
  98.  *          Wikipedia (2019): Hyper-geometric Function https://en.wikipedia.org/wiki/Hypergeometric_function
  99.  *      </li>
  100.  *  </ul>
  101.  *
  102.  *  <br><br>
  103.  *  <ul>
  104.  *      <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/ComputationalCore.md">Computational Core Module</a></li>
  105.  *      <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/FunctionAnalysisLibrary.md">Function Analysis Library</a></li>
  106.  *      <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>
  107.  *      <li><b>Package</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/specialfunction/ode/README.md">Special Function Ordinary Differential Equations</a></li>
  108.  *  </ul>
  109.  *
  110.  * @author Lakshmi Krishnamurthy
  111.  */

  112. public class HilleQForm2F1 extends org.drip.specialfunction.ode.SecondOrder
  113. {
  114.     private org.drip.function.definition.R1ToR1 _q = null;
  115.     private org.drip.function.definition.R1ToR1 _v = null;

  116.     /**
  117.      * Construct the Hille Q-Form of 2F1 ODE
  118.      *
  119.      * @param a A
  120.      * @param b B
  121.      * @param c C
  122.      *
  123.      * @return Hille Q-Form of 2F1 ODE
  124.      */

  125.     public static final HilleQForm2F1 Standard (
  126.         final double a,
  127.         final double b,
  128.         final double c)
  129.     {
  130.         if (!org.drip.numerical.common.NumberUtil.IsValid (a) ||
  131.             !org.drip.numerical.common.NumberUtil.IsValid (b) ||
  132.             !org.drip.numerical.common.NumberUtil.IsValid (c))
  133.         {
  134.             return null;
  135.         }

  136.         final org.drip.function.definition.R1ToR1 q = new org.drip.function.definition.R1ToR1 (null)
  137.         {
  138.             @Override public double evaluate (
  139.                 final double z)
  140.                 throws java.lang.Exception
  141.             {
  142.                 if (!org.drip.numerical.common.NumberUtil.IsValid (z))
  143.                 {
  144.                     throw new java.lang.Exception
  145.                         ("HilleQForm2F1::Standard::q::evaluate => Invalid Inputs");
  146.                 }

  147.                 double aMinusB = a - b;
  148.                 double zMinus1 = z - 1.;

  149.                 return (z * z * (1. - aMinusB * aMinusB) + z * (2. * c * (a + b - 1.) - 4. * a * b) + c *
  150.                     (2. - c)) / (4. * z * z * zMinus1 * zMinus1);
  151.             }
  152.         };

  153.         try
  154.         {
  155.             return new HilleQForm2F1 (
  156.                 new org.drip.function.definition.R2ToR1()
  157.                 {
  158.                     @Override public double evaluate (
  159.                         final double z,
  160.                         final double u)
  161.                         throws java.lang.Exception
  162.                     {
  163.                         return 1.;
  164.                     }
  165.                 },
  166.                 new org.drip.function.definition.R2ToR1()
  167.                 {
  168.                     @Override public double evaluate (
  169.                         final double z,
  170.                         final double w)
  171.                         throws java.lang.Exception
  172.                     {
  173.                         return 0.;
  174.                     }
  175.                 },
  176.                 new org.drip.function.definition.R2ToR1()
  177.                 {
  178.                     @Override public double evaluate (
  179.                         final double z,
  180.                         final double u)
  181.                         throws java.lang.Exception
  182.                     {
  183.                         if (!org.drip.numerical.common.NumberUtil.IsValid (u))
  184.                         {
  185.                             throw new java.lang.Exception
  186.                                 ("HilleQForm2F1::Standard::ZeroOrder::evaluate => Invalid Inputs");
  187.                         }

  188.                         return q.evaluate (z) * u;
  189.                     }
  190.                 },
  191.                 q,
  192.                 new org.drip.function.definition.R1ToR1 (null)
  193.                 {
  194.                     @Override public double evaluate (
  195.                         final double z)
  196.                         throws java.lang.Exception
  197.                     {
  198.                         if (!org.drip.numerical.common.NumberUtil.IsValid (z))
  199.                         {
  200.                             throw new java.lang.Exception
  201.                                 ("HilleQForm2F1::Standard::v::evaluate => Invalid Inputs");
  202.                         }

  203.                         return java.lang.Math.pow (
  204.                             z,
  205.                             -0.5 * c
  206.                         ) * java.lang.Math.pow (
  207.                             1. - z,
  208.                             0.5 * (c - a - b - 1.)
  209.                         );
  210.                     }
  211.                 }
  212.             );
  213.         }
  214.         catch (java.lang.Exception e)
  215.         {
  216.             e.printStackTrace();
  217.         }

  218.         return null;
  219.     }

  220.     private HilleQForm2F1 (
  221.         final org.drip.function.definition.R2ToR1 secondDerivativeCoefficient,
  222.         final org.drip.function.definition.R2ToR1 firstDerivativeCoefficient,
  223.         final org.drip.function.definition.R2ToR1 zeroDerivativeCoefficient,
  224.         final org.drip.function.definition.R1ToR1 q,
  225.         final org.drip.function.definition.R1ToR1 v)
  226.         throws java.lang.Exception
  227.     {
  228.         super (
  229.             secondDerivativeCoefficient,
  230.             firstDerivativeCoefficient,
  231.             zeroDerivativeCoefficient
  232.         );

  233.         if (null == (_q = q) ||
  234.             null == (_v = v))
  235.         {
  236.             throw new java.lang.Exception ("HilleQForm2F1 Constructor => Invalid Inputs");
  237.         }
  238.     }

  239.     /**
  240.      * Retrieve the Q Form Function
  241.      *
  242.      * @return The Q Form Function
  243.      */

  244.     public org.drip.function.definition.R1ToR1 q()
  245.     {
  246.         return _q;
  247.     }

  248.     /**
  249.      * Retrieve the v Function
  250.      *
  251.      * @return The v Function
  252.      */

  253.     public org.drip.function.definition.R1ToR1 v()
  254.     {
  255.         return _v;
  256.     }
  257. }