CentralWilsonHilfertyMeasureEstimate.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>CentralWilsonHilfertyMeasureEstimate</i> illustrates the Estimation of Measures for the Wilson-Hilferty
  79.  *  Transformation of 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 CentralWilsonHilfertyMeasureEstimate
  117. {

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

  123.         int[] dofArray =
  124.         {
  125.              // 1,
  126.              2,
  127.              3,
  128.              4,
  129.              5,
  130.              6,
  131.              7,
  132.              8,
  133.              9,
  134.             10,
  135.             11,
  136.             12,
  137.             13,
  138.             14,
  139.             15,
  140.             16,
  141.             17,
  142.             18,
  143.             19,
  144.             20,
  145.             21,
  146.             22,
  147.             23,
  148.             24,
  149.             25,
  150.         };

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

  152.         System.out.println ("\t|               WILSON HILFERTY DISTRIBUTION MEASURES ESTIMATE               ||");

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

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

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

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

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

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

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

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

  161.         for (int dof : dofArray)
  162.         {
  163.             R1CentralWilsonHilferty r1UnivariateWilsonHilferty = R1CentralWilsonHilferty.Standard (dof);

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

  165.             display = display + " " + FormatUtil.FormatDouble (
  166.                 r1UnivariateWilsonHilferty.mean(), 1, 8, 1., false
  167.             ) + " | " + FormatUtil.FormatDouble (
  168.                 r1UnivariateWilsonHilferty.median(), 1, 8, 1., false
  169.             ) + " | " + FormatUtil.FormatDouble (
  170.                 r1UnivariateWilsonHilferty.mode(), 1, 8, 1., true
  171.             ) + " | " + FormatUtil.FormatDouble (
  172.                 r1UnivariateWilsonHilferty.variance(), 1, 8, 1., false
  173.             ) + " |";

  174.             System.out.println (display + "|");
  175.         }

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

  177.         EnvManager.TerminateEnv();
  178.     }
  179. }