BetaEqualityLemma.java

  1. package org.drip.specialfunction.property;

  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>BetaEqualityLemma</i> implements the Equality Lemmas for the Beta Estimation. The References are:
  76.  *
  77.  * <br><br>
  78.  *  <ul>
  79.  *      <li>
  80.  *          Abramowitz, M., and I. A. Stegun (2007): <i>Handbook of Mathematics Functions</i> <b>Dover Book
  81.  *              on Mathematics</b>
  82.  *      </li>
  83.  *      <li>
  84.  *          Davis, P. J. (1959): Leonhard Euler's Integral: A Historical Profile of the Gamma Function
  85.  *              <i>American Mathematical Monthly</i> <b>66 (10)</b> 849-869
  86.  *      </li>
  87.  *      <li>
  88.  *          Whitaker, E. T., and G. N. Watson (1996): <i>A Course on Modern Analysis</i> <b>Cambridge
  89.  *              University Press</b> New York
  90.  *      </li>
  91.  *      <li>
  92.  *          Wikipedia (2019): Beta Function https://en.wikipedia.org/wiki/Beta_function
  93.  *      </li>
  94.  *      <li>
  95.  *          Wikipedia (2019): Gamma Function https://en.wikipedia.org/wiki/Gamma_function
  96.  *      </li>
  97.  *  </ul>
  98.  *
  99.  *  <br><br>
  100.  *  <ul>
  101.  *      <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/ComputationalCore.md">Computational Core Module</a></li>
  102.  *      <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/FunctionAnalysisLibrary.md">Function Analysis Library</a></li>
  103.  *      <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>
  104.  *      <li><b>Package</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/specialfunction/property/README.md">Special Function Property Lemma Verifiers</a></li>
  105.  *  </ul>
  106.  *
  107.  * @author Lakshmi Krishnamurthy
  108.  */

  109. public class BetaEqualityLemma
  110. {

  111.     /**
  112.      * Construct the Identity #1 Verifier
  113.      *
  114.      * @return The Identity #1 Verifier
  115.      */

  116.     public static final org.drip.function.definition.R2ToR1Property Identity1()
  117.     {
  118.         final org.drip.specialfunction.beta.SummationSeriesEstimator summationSeries =
  119.             org.drip.specialfunction.beta.SummationSeriesEstimator.AbramowitzStegun2007 (1638400);

  120.         try
  121.         {
  122.             return new org.drip.function.definition.R2ToR1Property (
  123.                 org.drip.function.definition.RxToR1Property.EQ,
  124.                 new org.drip.function.definition.R2ToR1()
  125.                 {
  126.                     @Override public double evaluate (
  127.                         final double x,
  128.                         final double y)
  129.                         throws java.lang.Exception
  130.                     {
  131.                         if (!org.drip.numerical.common.NumberUtil.IsValid (x) || 0. >= x ||
  132.                             !org.drip.numerical.common.NumberUtil.IsValid (y) || 0. >= y)
  133.                         {
  134.                             throw new java.lang.Exception
  135.                                 ("BetaEqualityLemma::Identity1::evaluate => Invalid Inputs");
  136.                         }

  137.                         return summationSeries.evaluate (
  138.                             x,
  139.                             y
  140.                         );
  141.                     }
  142.                 },
  143.                 new org.drip.function.definition.R2ToR1()
  144.                 {
  145.                     @Override public double evaluate (
  146.                         final double x,
  147.                         final double y)
  148.                         throws java.lang.Exception
  149.                     {
  150.                         if (!org.drip.numerical.common.NumberUtil.IsValid (x) || 0. >= x ||
  151.                             !org.drip.numerical.common.NumberUtil.IsValid (y) || 0. >= y)
  152.                         {
  153.                             throw new java.lang.Exception
  154.                                 ("BetaEqualityLemma::Identity1::evaluate => Invalid Inputs");
  155.                         }

  156.                         return summationSeries.evaluate (
  157.                             x + 1,
  158.                             y
  159.                         ) + summationSeries.evaluate (
  160.                             x,
  161.                             y + 1
  162.                         );
  163.                     }
  164.                 },
  165.                 org.drip.function.definition.R1ToR1Property.MISMATCH_TOLERANCE
  166.             );
  167.         }
  168.         catch (java.lang.Exception e)
  169.         {
  170.             e.printStackTrace();
  171.         }

  172.         return null;
  173.     }

  174.     /**
  175.      * Construct the Identity #2 Verifier
  176.      *
  177.      * @return The Identity #2 Verifier
  178.      */

  179.     public static final org.drip.function.definition.R2ToR1Property Identity2()
  180.     {
  181.         final org.drip.specialfunction.beta.SummationSeriesEstimator summationSeries =
  182.             org.drip.specialfunction.beta.SummationSeriesEstimator.AbramowitzStegun2007 (1638400);

  183.         try
  184.         {
  185.             return new org.drip.function.definition.R2ToR1Property (
  186.                 org.drip.function.definition.RxToR1Property.EQ,
  187.                 new org.drip.function.definition.R2ToR1()
  188.                 {
  189.                     @Override public double evaluate (
  190.                         final double x,
  191.                         final double y)
  192.                         throws java.lang.Exception
  193.                     {
  194.                         if (!org.drip.numerical.common.NumberUtil.IsValid (x) || 0. >= x ||
  195.                             !org.drip.numerical.common.NumberUtil.IsValid (y) || 0. >= y)
  196.                         {
  197.                             throw new java.lang.Exception
  198.                                 ("BetaEqualityLemma::Identity2::evaluate => Invalid Inputs");
  199.                         }

  200.                         return summationSeries.evaluate (
  201.                             x + 1,
  202.                             y
  203.                         );
  204.                     }
  205.                 },
  206.                 new org.drip.function.definition.R2ToR1()
  207.                 {
  208.                     @Override public double evaluate (
  209.                         final double x,
  210.                         final double y)
  211.                         throws java.lang.Exception
  212.                     {
  213.                         if (!org.drip.numerical.common.NumberUtil.IsValid (x) || 0. >= x ||
  214.                             !org.drip.numerical.common.NumberUtil.IsValid (y) || 0. >= y)
  215.                         {
  216.                             throw new java.lang.Exception
  217.                                 ("BetaEqualityLemma::Identity2::evaluate => Invalid Inputs");
  218.                         }

  219.                         return summationSeries.evaluate (
  220.                             x,
  221.                             y
  222.                         ) * x / (x + y);
  223.                     }
  224.                 },
  225.                 org.drip.function.definition.R1ToR1Property.MISMATCH_TOLERANCE
  226.             );
  227.         }
  228.         catch (java.lang.Exception e)
  229.         {
  230.             e.printStackTrace();
  231.         }

  232.         return null;
  233.     }

  234.     /**
  235.      * Construct the Identity #3 Verifier
  236.      *
  237.      * @return The Identity #3 Verifier
  238.      */

  239.     public static final org.drip.function.definition.R2ToR1Property Identity3()
  240.     {
  241.         final org.drip.specialfunction.beta.SummationSeriesEstimator summationSeries =
  242.             org.drip.specialfunction.beta.SummationSeriesEstimator.AbramowitzStegun2007 (1638400);

  243.         try
  244.         {
  245.             return new org.drip.function.definition.R2ToR1Property (
  246.                 org.drip.function.definition.RxToR1Property.EQ,
  247.                 new org.drip.function.definition.R2ToR1()
  248.                 {
  249.                     @Override public double evaluate (
  250.                         final double x,
  251.                         final double y)
  252.                         throws java.lang.Exception
  253.                     {
  254.                         if (!org.drip.numerical.common.NumberUtil.IsValid (x) || 0. >= x ||
  255.                             !org.drip.numerical.common.NumberUtil.IsValid (y) || 0. >= y)
  256.                         {
  257.                             throw new java.lang.Exception
  258.                                 ("BetaEqualityLemma::Identity3::evaluate => Invalid Inputs");
  259.                         }

  260.                         return summationSeries.evaluate (
  261.                             x,
  262.                             y + 1
  263.                         );
  264.                     }
  265.                 },
  266.                 new org.drip.function.definition.R2ToR1()
  267.                 {
  268.                     @Override public double evaluate (
  269.                         final double x,
  270.                         final double y)
  271.                         throws java.lang.Exception
  272.                     {
  273.                         if (!org.drip.numerical.common.NumberUtil.IsValid (x) || 0. >= x ||
  274.                             !org.drip.numerical.common.NumberUtil.IsValid (y) || 0. >= y)
  275.                         {
  276.                             throw new java.lang.Exception
  277.                                 ("BetaEqualityLemma::Identity3::evaluate => Invalid Inputs");
  278.                         }

  279.                         return summationSeries.evaluate (
  280.                             x,
  281.                             y
  282.                         ) * y / (x + y);
  283.                     }
  284.                 },
  285.                 org.drip.function.definition.R1ToR1Property.MISMATCH_TOLERANCE
  286.             );
  287.         }
  288.         catch (java.lang.Exception e)
  289.         {
  290.             e.printStackTrace();
  291.         }

  292.         return null;
  293.     }

  294.     /**
  295.      * Construct the Identity #4 Verifier
  296.      *
  297.      * @return The Identity #4 Verifier
  298.      */

  299.     public static final org.drip.function.definition.R2ToR1Property Identity4()
  300.     {
  301.         final org.drip.specialfunction.beta.SummationSeriesEstimator summationSeries =
  302.             org.drip.specialfunction.beta.SummationSeriesEstimator.AbramowitzStegun2007 (1638400);

  303.         try
  304.         {
  305.             return new org.drip.function.definition.R2ToR1Property (
  306.                 org.drip.function.definition.RxToR1Property.EQ,
  307.                 new org.drip.function.definition.R2ToR1()
  308.                 {
  309.                     @Override public double evaluate (
  310.                         final double x,
  311.                         final double y)
  312.                         throws java.lang.Exception
  313.                     {
  314.                         if (!org.drip.numerical.common.NumberUtil.IsValid (x) || 0. >= x ||
  315.                             !org.drip.numerical.common.NumberUtil.IsValid (y) || 0. >= y)
  316.                         {
  317.                             throw new java.lang.Exception
  318.                                 ("BetaEqualityLemma::Identity4::evaluate => Invalid Inputs");
  319.                         }

  320.                         return summationSeries.evaluate (
  321.                             x,
  322.                             y
  323.                         ) * summationSeries.evaluate (
  324.                             x + y,
  325.                             1. - y
  326.                         );
  327.                     }
  328.                 },
  329.                 new org.drip.function.definition.R2ToR1()
  330.                 {
  331.                     @Override public double evaluate (
  332.                         final double x,
  333.                         final double y)
  334.                         throws java.lang.Exception
  335.                     {
  336.                         if (!org.drip.numerical.common.NumberUtil.IsValid (x) || 0. >= x ||
  337.                             !org.drip.numerical.common.NumberUtil.IsValid (y) || 0. >= y)
  338.                         {
  339.                             throw new java.lang.Exception
  340.                                 ("BetaEqualityLemma::Identity4::evaluate => Invalid Inputs");
  341.                         }

  342.                         return java.lang.Math.PI / (x * java.lang.Math.sin (java.lang.Math.PI * y));
  343.                     }
  344.                 },
  345.                 org.drip.function.definition.R1ToR1Property.MISMATCH_TOLERANCE
  346.             );
  347.         }
  348.         catch (java.lang.Exception e)
  349.         {
  350.             e.printStackTrace();
  351.         }

  352.         return null;
  353.     }

  354.     /**
  355.      * Construct the Identity #5 Verifier
  356.      *
  357.      * @return The Identity #5 Verifier
  358.      */

  359.     public static final org.drip.function.definition.R1ToR1Property Identity5()
  360.     {
  361.         final org.drip.specialfunction.beta.SummationSeriesEstimator summationSeries =
  362.             org.drip.specialfunction.beta.SummationSeriesEstimator.AbramowitzStegun2007 (1638400);

  363.         try
  364.         {
  365.             return new org.drip.function.definition.R1ToR1Property (
  366.                 org.drip.function.definition.R1ToR1Property.EQ,
  367.                 new org.drip.function.definition.R1ToR1 (null)
  368.                 {
  369.                     @Override public double evaluate (
  370.                         final double z)
  371.                         throws java.lang.Exception
  372.                     {
  373.                         if (!org.drip.numerical.common.NumberUtil.IsValid (z) || 0. >= z)
  374.                         {
  375.                             throw new java.lang.Exception
  376.                                 ("BetaEqualityLemma::Identity5::evaluate => Invalid Inputs");
  377.                         }

  378.                         return summationSeries.evaluate (
  379.                             z,
  380.                             1. - z
  381.                         );
  382.                     }
  383.                 },
  384.                 new org.drip.function.definition.R1ToR1 (null)
  385.                 {
  386.                     @Override public double evaluate (
  387.                         final double z)
  388.                         throws java.lang.Exception
  389.                     {
  390.                         if (!org.drip.numerical.common.NumberUtil.IsValid (z) || 0. >= z)
  391.                         {
  392.                             throw new java.lang.Exception
  393.                                 ("BetaEqualityLemma::Identity5::evaluate => Invalid Inputs");
  394.                         }

  395.                         return java.lang.Math.PI / java.lang.Math.sin (java.lang.Math.PI * z);
  396.                     }
  397.                 },
  398.                 org.drip.function.definition.R1ToR1Property.MISMATCH_TOLERANCE
  399.             );
  400.         }
  401.         catch (java.lang.Exception e)
  402.         {
  403.             e.printStackTrace();
  404.         }

  405.         return null;
  406.     }

  407.     /**
  408.      * Construct the Identity #6 Verifier
  409.      *
  410.      * @return The Identity #6 Verifier
  411.      */

  412.     public static final org.drip.function.definition.R1ToR1Property Identity6()
  413.     {
  414.         final org.drip.specialfunction.beta.SummationSeriesEstimator summationSeries =
  415.             org.drip.specialfunction.beta.SummationSeriesEstimator.AbramowitzStegun2007 (1638400);

  416.         try
  417.         {
  418.             return new org.drip.function.definition.R1ToR1Property (
  419.                 org.drip.function.definition.R1ToR1Property.EQ,
  420.                 new org.drip.function.definition.R1ToR1 (null)
  421.                 {
  422.                     @Override public double evaluate (
  423.                         final double z)
  424.                         throws java.lang.Exception
  425.                     {
  426.                         if (!org.drip.numerical.common.NumberUtil.IsValid (z) || 0. >= z)
  427.                         {
  428.                             throw new java.lang.Exception
  429.                                 ("BetaEqualityLemma::Identity6::evaluate => Invalid Inputs");
  430.                         }

  431.                         return summationSeries.evaluate (
  432.                             1.,
  433.                             z
  434.                         );
  435.                     }
  436.                 },
  437.                 new org.drip.function.definition.R1ToR1 (null)
  438.                 {
  439.                     @Override public double evaluate (
  440.                         final double z)
  441.                         throws java.lang.Exception
  442.                     {
  443.                         if (!org.drip.numerical.common.NumberUtil.IsValid (z) || 0. >= z)
  444.                         {
  445.                             throw new java.lang.Exception
  446.                                 ("BetaEqualityLemma::Identity6::evaluate => Invalid Inputs");
  447.                         }

  448.                         return 1. / z;
  449.                     }
  450.                 },
  451.                 org.drip.function.definition.R1ToR1Property.MISMATCH_TOLERANCE
  452.             );
  453.         }
  454.         catch (java.lang.Exception e)
  455.         {
  456.             e.printStackTrace();
  457.         }

  458.         return null;
  459.     }
  460. }