CentralWilsonHilfertyPDFEstimate.java

  1. package org.drip.sample.chisquaredistribution;

  2. import org.drip.measure.chisquare.R1CentralWilsonHilferty;
  3. import org.drip.numerical.common.FormatUtil;
  4. import org.drip.service.env.EnvManager;

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

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

  77. /**
  78.  * <i>CentralWilsonHilfertyPDFEstimate</i> illustrates the Construction and the Usage of the Wilson-Hilferty
  79.  *  Normal Proxy for a Central Chi-squared Distribution. The References are:
  80.  *
  81.  * <br><br>
  82.  *  <ul>
  83.  *      <li>
  84.  *          Abramowitz, M., and I. A. Stegun (2007): <i>Handbook of Mathematics Functions</i> <b>Dover Book
  85.  *              on Mathematics</b>
  86.  *      </li>
  87.  *      <li>
  88.  *          Backstrom, T., and J. Fischer (2018): Fast Randomization for Distributed Low Bit-rate Coding of
  89.  *              Speech and Audio <i>IEEE/ACM Transactions on Audio, Speech, and Language Processing</i> <b>26
  90.  *              (1)</b> 19-30
  91.  *      </li>
  92.  *      <li>
  93.  *          Chi-Squared Distribution (2019): Chi-Squared Function
  94.  *              https://en.wikipedia.org/wiki/Chi-squared_distribution
  95.  *      </li>
  96.  *      <li>
  97.  *          Johnson, N. L., S. Kotz, and N. Balakrishnan (1994): <i>Continuous Univariate Distributions
  98.  *              2<sup>nd</sup> Edition</i> <b>John Wiley and Sons</b>
  99.  *      </li>
  100.  *      <li>
  101.  *          National Institute of Standards and Technology (2019): Chi-Squared Distribution
  102.  *              https://www.itl.nist.gov/div898/handbook/eda/section3/eda3666.htm
  103.  *      </li>
  104.  *  </ul>
  105.  *
  106.  *  <br><br>
  107.  *  <ul>
  108.  *      <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/ComputationalCore.md">Computational Core Module</a></li>
  109.  *      <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/NumericalAnalysisLibrary.md">Numerical Analysis Library</a></li>
  110.  *      <li><b>Project</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/sample/README.md">DROP API Construction and Usage</a></li>
  111.  *      <li><b>Package</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/sample/chisquaredistribution/README.md">Chi-Square Distribution Usage/Properties</a></li>
  112.  *  </ul>
  113.  *
  114.  * @author Lakshmi Krishnamurthy
  115.  */

  116. public class CentralWilsonHilfertyPDFEstimate
  117. {

  118.     public static final void main (
  119.         final String[] argumentArray)
  120.         throws Exception
  121.     {
  122.         EnvManager.InitEnv ("");

  123.         double[] tArray =
  124.         {
  125.              0.75,
  126.              0.80,
  127.              0.85,
  128.              0.90,
  129.              0.95,
  130.              1.00,
  131.              1.05,
  132.              1.10,
  133.              1.15,
  134.              1.20,
  135.              1.25,
  136.              1.30,
  137.         };
  138.         int[] dofArray =
  139.         {
  140.              // 1,
  141.              2,
  142.              3,
  143.              4,
  144.              5,
  145.              6,
  146.              7,
  147.              8,
  148.              9,
  149.         };
  150.         double[] pValueArray =
  151.         {
  152.              0.00,
  153.              0.05,
  154.              0.10,
  155.              0.15,
  156.              0.20,
  157.              0.25,
  158.              0.30,
  159.              0.35,
  160.              0.40,
  161.              0.45,
  162.              0.50,
  163.              0.55,
  164.         };

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

  166.         System.out.println ("\t|                                             PROBABILITY DENSITY FUNCTION ESTIMATE                                            ||");

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

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

  169.         System.out.println ("\t|                - Degrees of Freedom                                                                                          ||");

  170.         System.out.println ("\t|                - Values for different t                                                                                      ||");

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

  172.         for (int dof : dofArray)
  173.         {
  174.             R1CentralWilsonHilferty r1UnivariateWilsonHilferty = R1CentralWilsonHilferty.Standard (dof);

  175.             String display = "\t| [" + FormatUtil.FormatDouble (dof, 1, 0, 1., false) + "] =>";

  176.             for (double t : tArray)
  177.             {
  178.                 display = display + " " + FormatUtil.FormatDouble (
  179.                     r1UnivariateWilsonHilferty.density (t), 1, 5, 1., false
  180.                 ) + " |";
  181.             }

  182.             System.out.println (display + "|");
  183.         }

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

  185.         System.out.println();

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

  187.         System.out.println ("\t|                                           CUMULATIVE DISTRIBUTION FUNCTION ESTIMATE                                          ||");

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

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

  190.         System.out.println ("\t|                - Degrees of Freedom                                                                                          ||");

  191.         System.out.println ("\t|                - Values for different t                                                                                      ||");

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

  193.         for (int dof : dofArray)
  194.         {
  195.             R1CentralWilsonHilferty r1UnivariateWilsonHilferty = R1CentralWilsonHilferty.Standard (dof);

  196.             String display = "\t| [" + FormatUtil.FormatDouble (dof, 1, 0, 1., false) + "] =>";

  197.             for (double t : tArray)
  198.             {
  199.                 display = display + " " + FormatUtil.FormatDouble (
  200.                     r1UnivariateWilsonHilferty.cumulative (t), 1, 5, 1., false
  201.                 ) + " |";
  202.             }

  203.             System.out.println (display + "|");
  204.         }

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

  206.         System.out.println();

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

  208.         System.out.println ("\t|                                       INVERSE CUMULATIVE DISTRIBUTION FUNCTION ESTIMATE                                      ||");

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

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

  211.         System.out.println ("\t|                - Degrees of Freedom                                                                                          ||");

  212.         System.out.println ("\t|                - Values for different p                                                                                      ||");

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

  214.         for (int dof : dofArray)
  215.         {
  216.             R1CentralWilsonHilferty r1UnivariateWilsonHilferty = R1CentralWilsonHilferty.Standard (dof);

  217.             String display = "\t| [" + FormatUtil.FormatDouble (dof, 1, 0, 1., false) + "] =>";

  218.             for (double p : pValueArray)
  219.             {
  220.                 display = display + " " + FormatUtil.FormatDouble (
  221.                     r1UnivariateWilsonHilferty.invCumulative (p), 1, 5, 1., false
  222.                 ) + " |";
  223.             }

  224.             System.out.println (display + "|");
  225.         }

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

  227.         EnvManager.TerminateEnv();
  228.     }
  229. }