MultiplicationProperty.java

  1. package org.drip.sample.gamma;

  2. import org.drip.function.definition.R1ToR1Property;
  3. import org.drip.function.definition.R1PropertyVerification;
  4. import org.drip.numerical.common.FormatUtil;
  5. import org.drip.service.env.EnvManager;
  6. import org.drip.specialfunction.property.GammaEqualityLemma;

  7. /*
  8.  * -*- mode: java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  9.  */

  10. /*!
  11.  * Copyright (C) 2019 Lakshmi Krishnamurthy
  12.  *
  13.  *  This file is part of DROP, an open-source library targeting risk, transaction costs, exposure, margin
  14.  *      calculations, and portfolio construction within and across fixed income, credit, commodity, equity,
  15.  *      FX, and structured products.
  16.  *  
  17.  *      https://lakshmidrip.github.io/DROP/
  18.  *  
  19.  *  DROP is composed of three main modules:
  20.  *  
  21.  *  - DROP Analytics Core - https://lakshmidrip.github.io/DROP-Analytics-Core/
  22.  *  - DROP Portfolio Core - https://lakshmidrip.github.io/DROP-Portfolio-Core/
  23.  *  - DROP Numerical Core - https://lakshmidrip.github.io/DROP-Numerical-Core/
  24.  *
  25.  *  DROP Analytics Core implements libraries for the following:
  26.  *  - Fixed Income Analytics
  27.  *  - Asset Backed Analytics
  28.  *  - XVA Analytics
  29.  *  - Exposure and Margin Analytics
  30.  *
  31.  *  DROP Portfolio Core implements libraries for the following:
  32.  *  - Asset Allocation Analytics
  33.  *  - Transaction Cost Analytics
  34.  *
  35.  *  DROP Numerical Core implements libraries for the following:
  36.  *  - Statistical Learning Library
  37.  *  - Numerical Optimizer Library
  38.  *  - Machine Learning Library
  39.  *  - Spline Builder Library
  40.  *
  41.  *  Documentation for DROP is Spread Over:
  42.  *
  43.  *  - Main                     => https://lakshmidrip.github.io/DROP/
  44.  *  - Wiki                     => https://github.com/lakshmiDRIP/DROP/wiki
  45.  *  - GitHub                   => https://github.com/lakshmiDRIP/DROP
  46.  *  - Javadoc                  => https://lakshmidrip.github.io/DROP/Javadoc/index.html
  47.  *  - Technical Specifications => https://github.com/lakshmiDRIP/DROP/tree/master/Docs/Internal
  48.  *  - Release Versions         => https://lakshmidrip.github.io/DROP/version.html
  49.  *  - Community Credits        => https://lakshmidrip.github.io/DROP/credits.html
  50.  *  - Issues Catalog           => https://github.com/lakshmiDRIP/DROP/issues
  51.  *  - JUnit                    => https://lakshmidrip.github.io/DROP/junit/index.html
  52.  *  - Jacoco                   => https://lakshmidrip.github.io/DROP/jacoco/index.html
  53.  *
  54.  *  Licensed under the Apache License, Version 2.0 (the "License");
  55.  *      you may not use this file except in compliance with the License.
  56.  *  
  57.  *  You may obtain a copy of the License at
  58.  *      http://www.apache.org/licenses/LICENSE-2.0
  59.  *  
  60.  *  Unless required by applicable law or agreed to in writing, software
  61.  *      distributed under the License is distributed on an "AS IS" BASIS,
  62.  *      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  63.  *  
  64.  *  See the License for the specific language governing permissions and
  65.  *      limitations under the License.
  66.  */

  67. /**
  68.  * <i>MultiplicationProperty</i> demonstrates the Verification of the Multiplication Property of the Gamma
  69.  * Function. The References are:
  70.  *
  71.  * <br><br>
  72.  *  <ul>
  73.  *      <li>
  74.  *          Blagouchine, I. V. (2014): Re-discovery of Malmsten's Integrals, their Evaluation by Contour
  75.  *              Integration Methods, and some Related Results <i>Ramanujan Journal</i> <b>35 (1)</b> 21-110
  76.  *      </li>
  77.  *      <li>
  78.  *          Borwein, J. M., and R. M. Corless (2017): Gamma Function and the Factorial in the Monthly
  79.  *              https://arxiv.org/abs/1703.05349 <b>arXiv</b>
  80.  *      </li>
  81.  *      <li>
  82.  *          Davis, P. J. (1959): Leonhard Euler's Integral: A Historical Profile of the Gamma Function
  83.  *              <i>American Mathematical Monthly</i> <b>66 (10)</b> 849-869
  84.  *      </li>
  85.  *      <li>
  86.  *          Whitaker, E. T., and G. N. Watson (1996): <i>A Course on Modern Analysis</i> <b>Cambridge
  87.  *              University Press</b> New York
  88.  *      </li>
  89.  *      <li>
  90.  *          Wikipedia (2019): Gamma Function https://en.wikipedia.org/wiki/Gamma_function
  91.  *      </li>
  92.  *  </ul>
  93.  *
  94.  *  <br><br>
  95.  *  <ul>
  96.  *      <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/NumericalCore.md">Numerical Core Module</a></li>
  97.  *      <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/NumericalOptimizerLibrary.md">Numerical Optimizer</a></li>
  98.  *      <li><b>Project</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/sample/README.md">Function</a></li>
  99.  *      <li><b>Package</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/sample/gamma/README.md">Integrand Estimates of Gamma Functions</a></li>
  100.  *  </ul>
  101.  *
  102.  * @author Lakshmi Krishnamurthy
  103.  */

  104. public class MultiplicationProperty
  105. {

  106.     private static final void Verifier (
  107.         final int m,
  108.         final double[] sArray,
  109.         final R1ToR1Property multiplicationProperty)
  110.         throws Exception
  111.     {
  112.         System.out.println ("\t|----------------------------------------------||");

  113.         System.out.println ("\t|    GAMMA FUNCTION MULTIPLICATION PROPERTY    ||");

  114.         System.out.println ("\t|                  m = " + FormatUtil.FormatDouble (m, 1, 0, 1.));

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

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

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

  118.         System.out.println ("\t|                - LHS Value                   ||");

  119.         System.out.println ("\t|                - RHS Value                   ||");

  120.         System.out.println ("\t|                - Verification Success?       ||");

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

  122.         for (double s : sArray)
  123.         {
  124.             R1PropertyVerification propertyVerification = multiplicationProperty.verify (s);

  125.             System.out.println (
  126.                 "\t|" + FormatUtil.FormatDouble (s, 1, 2, 1.) + " => " +
  127.                     FormatUtil.FormatDouble (propertyVerification.lValue(), 1, 10, 1.) + " | " +
  128.                     FormatUtil.FormatDouble (propertyVerification.rValue(), 1, 10, 1.) + " | " +
  129.                     propertyVerification.verified() + " ||"
  130.             );
  131.         }

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

  133.         System.out.println();
  134.     }

  135.     public static final void main (
  136.         final String[] argumentArray)
  137.         throws Exception
  138.     {
  139.         EnvManager.InitEnv ("");

  140.         int[] mArray =
  141.         {
  142.             3,
  143.             4,
  144.             5,
  145.             6,
  146.             7,
  147.             8,
  148.             9,
  149.         };
  150.         double[] sArray =
  151.         {
  152.             0.05,
  153.             0.10,
  154.             0.15,
  155.             0.20,
  156.             0.25,
  157.             0.30,
  158.             0.35,
  159.             0.40,
  160.             0.45,
  161.             0.50,
  162.             0.60,
  163.             0.70,
  164.             0.80,
  165.             0.90,
  166.         };

  167.         for (int m : mArray)
  168.         {
  169.             Verifier (
  170.                 m,
  171.                 sArray,
  172.                 GammaEqualityLemma.MultiplicationFormula (m)
  173.             );
  174.         }

  175.         EnvManager.TerminateEnv();
  176.     }
  177. }