R1WilsonHilferty.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>R1CentralWilsonHilferty</i> implements the Normal Proxy Version for the R<sup>1</sup> Chi-Square
  76.  *  Distribution using the Wilson-Hilferty Transformation. 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 abstract class R1WilsonHilferty
  114.     extends org.drip.measure.continuous.R1Univariate
  115. {
  116.     private double _degreesOfFreedom = -1;
  117.     private org.drip.measure.gaussian.R1UnivariateNormal _r1UnivariateNormal = null;

  118.     protected R1WilsonHilferty (
  119.         final double degreesOfFreedom,
  120.         final org.drip.measure.gaussian.R1UnivariateNormal r1UnivariateNormal)
  121.         throws java.lang.Exception
  122.     {
  123.         if (!org.drip.numerical.common.NumberUtil.IsValid (
  124.                 _degreesOfFreedom = degreesOfFreedom
  125.             ) || 0. >= _degreesOfFreedom ||
  126.             null == (_r1UnivariateNormal = r1UnivariateNormal)
  127.         )
  128.         {
  129.             throw new java.lang.Exception (
  130.                 "R1WilsonHilferty Constructor => Invalid Inputs"
  131.             );
  132.         }
  133.     }

  134.     /**
  135.      * Retrieve the Degrees of Freedom
  136.      *
  137.      * @return The Degrees of Freedom
  138.      */

  139.     public double degreesOfFreedom()
  140.     {
  141.         return _degreesOfFreedom;
  142.     }

  143.     /**
  144.      * Retrieve the R<sup>1</sup> Univariate Normal
  145.      *
  146.      * @return The R<sup>1</sup> Univariate Normal
  147.      */

  148.     public org.drip.measure.gaussian.R1UnivariateNormal r1UnivariateNormal()
  149.     {
  150.         return _r1UnivariateNormal;
  151.     }

  152.     /**
  153.      * Transform x into the Wilson-Hilferty Variate
  154.      *
  155.      * @param x X
  156.      *
  157.      * @return The Wilson-Hilferty Variate
  158.      */

  159.     public abstract double transform (
  160.         final double x);

  161.     /**
  162.      * Transform the Wilson-Hilferty Variate into x
  163.      *
  164.      * @param wilsonHilferty The Wilson-Hilferty Variate
  165.      *
  166.      * @return The Wilson-Hilferty Variate transformed back to x
  167.      */

  168.     public abstract double inverseTransform (
  169.         final double wilsonHilferty);

  170.     @Override public double[] support()
  171.     {
  172.         return new double[]
  173.         {
  174.             0.,
  175.             java.lang.Double.POSITIVE_INFINITY
  176.         };
  177.     }

  178.     @Override public double density (
  179.         final double t)
  180.         throws java.lang.Exception
  181.     {
  182.         return _r1UnivariateNormal.density (
  183.             transform (
  184.                 t
  185.             )
  186.         );
  187.     }

  188.     @Override public double cumulative (
  189.         final double t)
  190.         throws java.lang.Exception
  191.     {
  192.         return _r1UnivariateNormal.cumulative (
  193.             transform (
  194.                 t
  195.             )
  196.         );
  197.     }

  198.     @Override public double invCumulative (
  199.         final double y)
  200.         throws java.lang.Exception
  201.     {
  202.         return inverseTransform (
  203.             _r1UnivariateNormal.invCumulative (
  204.                 y
  205.             )
  206.         );
  207.     }

  208.     @Override public double mean()
  209.         throws java.lang.Exception
  210.     {
  211.         return _r1UnivariateNormal.mean();
  212.     }

  213.     @Override public double median()
  214.         throws java.lang.Exception
  215.     {
  216.         return _r1UnivariateNormal.median();
  217.     }

  218.     @Override public double mode()
  219.         throws java.lang.Exception
  220.     {
  221.         return _r1UnivariateNormal.mode();
  222.     }

  223.     @Override public double variance()
  224.         throws java.lang.Exception
  225.     {
  226.         return _r1UnivariateNormal.variance();
  227.     }

  228.     @Override public double skewness()
  229.         throws java.lang.Exception
  230.     {
  231.         return _r1UnivariateNormal.skewness();
  232.     }

  233.     @Override public double excessKurtosis()
  234.         throws java.lang.Exception
  235.     {
  236.         return _r1UnivariateNormal.excessKurtosis();
  237.     }

  238.     @Override public org.drip.function.definition.R1ToR1 momentGeneratingFunction()
  239.     {
  240.         return _r1UnivariateNormal.momentGeneratingFunction();
  241.     }

  242.     @Override public org.drip.function.definition.R1ToR1 probabilityGeneratingFunction()
  243.     {
  244.         return _r1UnivariateNormal.probabilityGeneratingFunction();
  245.     }
  246. }