CentralCLTProxyPDFEstimate.java

  1. package org.drip.sample.chisquaredistribution;

  2. import org.drip.measure.chisquare.R1CentralCLTProxy;
  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>CentralCLTProxyPDFEstimate</i> illustrates the Construction and the Usage of a CLT Proxy for a Central
  79.  * 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 CentralCLTProxyPDFEstimate
  117. {

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

  123.         double[] tArray =
  124.         {
  125.              0.1,
  126.              1.0,
  127.              2.0,
  128.              3.0,
  129.              4.0,
  130.              5.0,
  131.              6.0,
  132.              7.0,
  133.              8.0,
  134.              9.0,
  135.             10.0,
  136.             12.0,
  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.25,
  153.              0.30,
  154.              0.35,
  155.              0.40,
  156.              0.45,
  157.              0.50,
  158.              0.55,
  159.              0.60,
  160.              0.65,
  161.              0.70,
  162.              0.75,
  163.         };

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

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

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

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

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

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

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

  171.         for (int dof : dofArray)
  172.         {
  173.             R1CentralCLTProxy r1UnivariateCLTProxy = new R1CentralCLTProxy (dof);

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

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

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

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

  184.         System.out.println();

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

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

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

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

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

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

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

  192.         for (int dof : dofArray)
  193.         {
  194.             R1CentralCLTProxy r1UnivariateCLTProxy = new R1CentralCLTProxy (dof);

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

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

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

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

  205.         System.out.println();

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

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

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

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

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

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

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

  213.         for (int dof : dofArray)
  214.         {
  215.             R1CentralCLTProxy r1UnivariateCLTProxy = new R1CentralCLTProxy (dof);

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

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

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

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

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