R1CentralFisherProxy.java

  1. package org.drip.measure.chisquare;

  2. /*
  3.  * -*- mode: java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  4.  */

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

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

  113. public class R1CentralFisherProxy extends org.drip.measure.continuous.R1Univariate
  114. {
  115.     private int _degreesOfFreedom = -1;
  116.     private org.drip.measure.gaussian.R1UnivariateNormal _r1UnivariateNormal = null;

  117.     /**
  118.      * R1CentralFisherProxy Constructor
  119.      *
  120.      * @param degreesOfFreedom Degrees of Freedom
  121.      *
  122.      * @throws java.lang.Exception Thrown if the Inputs are Invalid
  123.      */

  124.     public R1CentralFisherProxy (
  125.         final int degreesOfFreedom)
  126.         throws java.lang.Exception
  127.     {
  128.         if (0 >= (_degreesOfFreedom = degreesOfFreedom))
  129.         {
  130.             throw new java.lang.Exception ("R1CentralFisherProxy Constructor => Invalid Inputs");
  131.         }

  132.         _r1UnivariateNormal = new org.drip.measure.gaussian.R1UnivariateNormal (
  133.             java.lang.Math.sqrt (2. * _degreesOfFreedom - 1),
  134.             1.
  135.         );
  136.     }

  137.     /**
  138.      * Retrieve the Degrees of Freedom
  139.      *
  140.      * @return The Degrees of Freedom
  141.      */

  142.     public int degreesOfFreedom()
  143.     {
  144.         return _degreesOfFreedom;
  145.     }

  146.     /**
  147.      * Retrieve the R^1 Univariate Normal
  148.      *
  149.      * @return The R^1 Univariate Normal
  150.      */

  151.     public org.drip.measure.gaussian.R1UnivariateNormal r1UnivariateNormal()
  152.     {
  153.         return _r1UnivariateNormal;
  154.     }

  155.     @Override public double[] support()
  156.     {
  157.         return new double[]
  158.         {
  159.             0.,
  160.             java.lang.Double.POSITIVE_INFINITY
  161.         };
  162.     }

  163.     @Override public double density (
  164.         final double t)
  165.         throws java.lang.Exception
  166.     {
  167.         return _r1UnivariateNormal.density (t);
  168.     }

  169.     @Override public double cumulative (
  170.         final double t)
  171.         throws java.lang.Exception
  172.     {
  173.         return _r1UnivariateNormal.cumulative (t);
  174.     }

  175.     @Override public double mean()
  176.         throws java.lang.Exception
  177.     {
  178.         return _r1UnivariateNormal.mean();
  179.     }

  180.     @Override public double median()
  181.         throws java.lang.Exception
  182.     {
  183.         return _r1UnivariateNormal.median();
  184.     }

  185.     @Override public double mode()
  186.         throws java.lang.Exception
  187.     {
  188.         return _r1UnivariateNormal.mode();
  189.     }

  190.     @Override public double variance()
  191.         throws java.lang.Exception
  192.     {
  193.         return 1.;
  194.     }

  195.     @Override public double skewness()
  196.         throws java.lang.Exception
  197.     {
  198.         return _r1UnivariateNormal.skewness();
  199.     }

  200.     @Override public double excessKurtosis()
  201.         throws java.lang.Exception
  202.     {
  203.         return _r1UnivariateNormal.excessKurtosis();
  204.     }

  205.     @Override public double differentialEntropy()
  206.         throws java.lang.Exception
  207.     {
  208.         return _r1UnivariateNormal.differentialEntropy();
  209.     }

  210.     @Override public org.drip.function.definition.R1ToR1 momentGeneratingFunction()
  211.     {
  212.         return _r1UnivariateNormal.momentGeneratingFunction();
  213.     }

  214.     @Override public org.drip.function.definition.R1ToR1 probabilityGeneratingFunction()
  215.     {
  216.         return _r1UnivariateNormal.probabilityGeneratingFunction();
  217.     }

  218.     @Override public double random()
  219.         throws java.lang.Exception
  220.     {
  221.         double sumOfStandardNormalSquares = 0.;

  222.         for (int drawIndex = 0; drawIndex < _degreesOfFreedom; ++drawIndex)
  223.         {
  224.             double randomStandardNormal = org.drip.measure.gaussian.NormalQuadrature.InverseCDF
  225.                 (java.lang.Math.random());

  226.             sumOfStandardNormalSquares = sumOfStandardNormalSquares +
  227.                 randomStandardNormal * randomStandardNormal;
  228.         }

  229.         return java.lang.Math.sqrt (2. * sumOfStandardNormalSquares);
  230.     }
  231. }