NonCentralAbdelAtyPDFEstimate.java

  1. package org.drip.sample.chisquaredistribution;

  2. import org.drip.measure.chisquare.R1NonCentralAbdelAty;
  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>NonCentralAbdelAtyPDFEstimate</i> illustrates the Construction and the Usage of the Abdel-Aty (1954)
  79.  *  Wilson-Hilferty Based R<sup>1</sup> Normal Approximation of an R<sup>1</sup> Non-central Chi-square
  80.  *  Distribution. The References are:
  81.  *
  82.  * <br><br>
  83.  *  <ul>
  84.  *      <li>
  85.  *          Johnson, N. L., S. Kotz, and N. Balakrishnan (1995): <i>Continuous Univariate Distributions
  86.  *              2<sup>nd</sup> Edition</i> <b>John Wiley and Sons</b>
  87.  *      </li>
  88.  *      <li>
  89.  *          Muirhead, R. (2005): <i>Aspects of Multivariate Statistical Theory 2<sup>nd</sup> Edition</i>
  90.  *              <b>Wiley</b>
  91.  *      </li>
  92.  *      <li>
  93.  *          Non-central Chi-Squared Distribution (2019): Chi-Squared Function
  94.  *              https://en.wikipedia.org/wiki/Noncentral_chi-squared_distribution
  95.  *      </li>
  96.  *      <li>
  97.  *          Sankaran, M. (1963): Approximations to the Non-Central Chi-Square Distribution <i>Biometrika</i>
  98.  *              <b>50 (1-2)</b> 199-204
  99.  *      </li>
  100.  *      <li>
  101.  *          Young, D. S. (2010): tolerance: An R Package for Estimating Tolerance Intervals <i>Journal of
  102.  *              Statistical Software</i> <b>36 (5)</b> 1-39
  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 NonCentralAbdelAtyPDFEstimate
  117. {

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

  123.         double[] nonCentralityParameterArray =
  124.         {
  125.             0.5,
  126.             1.0,
  127.             1.5,
  128.             2.0,
  129.         };
  130.         double[] tArray =
  131.         {
  132.              0.1,
  133.              1.0,
  134.              2.0,
  135.              3.0,
  136.              4.0,
  137.              5.0,
  138.              6.0,
  139.              7.0,
  140.              8.0,
  141.              9.0,
  142.             10.0,
  143.             12.0,
  144.         };
  145.         int[] dofArray =
  146.         {
  147.              2,
  148.              3,
  149.              4,
  150.              5,
  151.              6,
  152.              7,
  153.              8,
  154.              9,
  155.         };
  156.         double[] pValueArray =
  157.         {
  158.              0.05,
  159.              0.10,
  160.              0.15,
  161.              0.20,
  162.              0.25,
  163.              0.30,
  164.              0.35,
  165.              0.40,
  166.              0.45,
  167.              0.50,
  168.              0.55,
  169.              0.60,
  170.         };

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

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

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

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

  175.         System.out.println ("\t|                - Degrees of Freedom; Non-centrality Parameter                                                                ||");

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

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

  178.         for (double nonCentralityParameter : nonCentralityParameterArray)
  179.         {
  180.             for (int dof : dofArray)
  181.             {
  182.                 R1NonCentralAbdelAty r1NonCentralAbdelAty = R1NonCentralAbdelAty.Standard (
  183.                     dof,
  184.                     1.
  185.                 );

  186.                 String display = "\t| [" +
  187.                     FormatUtil.FormatDouble (dof, 2, 0, 1., false) + " | " +
  188.                     FormatUtil.FormatDouble (nonCentralityParameter, 1, 1, 1., false) +
  189.                 "] =>";

  190.                 for (double t : tArray)
  191.                 {
  192.                     display = display + " " + FormatUtil.FormatDouble (
  193.                         r1NonCentralAbdelAty.density (
  194.                             t
  195.                         ), 1, 5, 1., false
  196.                     ) + " |";
  197.                 }

  198.                 System.out.println (display + "|");
  199.             }
  200.         }

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

  202.         System.out.println();

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

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

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

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

  207.         System.out.println ("\t|                - Degrees of Freedom; Non-centrality Parameter                                                                ||");

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

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

  210.         for (double nonCentralityParameter : nonCentralityParameterArray)
  211.         {
  212.             for (int dof : dofArray)
  213.             {
  214.                 R1NonCentralAbdelAty r1NonCentralAbdelAty = R1NonCentralAbdelAty.Standard (
  215.                     dof,
  216.                     1.
  217.                 );

  218.                 String display = "\t| [" +
  219.                     FormatUtil.FormatDouble (dof, 2, 0, 1., false) + " | " +
  220.                     FormatUtil.FormatDouble (nonCentralityParameter, 1, 1, 1., false) +
  221.                 "] =>";

  222.                 for (double t : tArray)
  223.                 {
  224.                     display = display + " " + FormatUtil.FormatDouble (
  225.                         r1NonCentralAbdelAty.cumulative (
  226.                             t
  227.                         ), 1, 5, 1., false
  228.                     ) + " |";
  229.                 }

  230.                 System.out.println (display + "|");
  231.             }
  232.         }

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

  234.         System.out.println();

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

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

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

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

  239.         System.out.println ("\t|                - Degrees of Freedom; Non-centrality Parameter                                                                ||");

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

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

  242.         for (double nonCentralityParameter : nonCentralityParameterArray)
  243.         {
  244.             for (int dof : dofArray)
  245.             {
  246.                 R1NonCentralAbdelAty r1NonCentralAbdelAty = R1NonCentralAbdelAty.Standard (
  247.                     dof,
  248.                     1.
  249.                 );

  250.                 String display = "\t| [" +
  251.                     FormatUtil.FormatDouble (dof, 2, 0, 1., false) + " | " +
  252.                     FormatUtil.FormatDouble (nonCentralityParameter, 1, 1, 1., false) +
  253.                 "] =>";

  254.                 for (double p : pValueArray)
  255.                 {
  256.                     display = display + " " + FormatUtil.FormatDouble (
  257.                         r1NonCentralAbdelAty.invCumulative (
  258.                             p
  259.                         ), 1, 5, 1., false
  260.                     ) + " |";
  261.                 }

  262.                 System.out.println (display + "|");
  263.             }
  264.         }

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

  266.         EnvManager.TerminateEnv();
  267.     }
  268. }