PillaiSpecialChiSquare.java

  1. package org.drip.sample.randomdiscrete;

  2. import org.drip.measure.discrete.SequenceGenerator;
  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) 2019 Lakshmi Krishnamurthy
  10.  *
  11.  *  This file is part of DROP, an open-source library targeting risk, transaction costs, exposure, margin
  12.  *      calculations, and portfolio construction within and across fixed income, credit, commodity, equity,
  13.  *      FX, and structured products.
  14.  *  
  15.  *      https://lakshmidrip.github.io/DROP/
  16.  *  
  17.  *  DROP is composed of three main modules:
  18.  *  
  19.  *  - DROP Analytics Core - https://lakshmidrip.github.io/DROP-Analytics-Core/
  20.  *  - DROP Portfolio Core - https://lakshmidrip.github.io/DROP-Portfolio-Core/
  21.  *  - DROP Numerical Core - https://lakshmidrip.github.io/DROP-Numerical-Core/
  22.  *
  23.  *  DROP Analytics Core implements libraries for the following:
  24.  *  - Fixed Income Analytics
  25.  *  - Asset Backed Analytics
  26.  *  - XVA Analytics
  27.  *  - Exposure and Margin Analytics
  28.  *
  29.  *  DROP Portfolio Core implements libraries for the following:
  30.  *  - Asset Allocation Analytics
  31.  *  - Transaction Cost Analytics
  32.  *
  33.  *  DROP Numerical Core implements libraries for the following:
  34.  *  - Statistical Learning Library
  35.  *  - Numerical Optimizer Library
  36.  *  - Machine Learning Library
  37.  *  - Spline Builder Library
  38.  *
  39.  *  Documentation for DROP is Spread Over:
  40.  *
  41.  *  - Main                     => https://lakshmidrip.github.io/DROP/
  42.  *  - Wiki                     => https://github.com/lakshmiDRIP/DROP/wiki
  43.  *  - GitHub                   => https://github.com/lakshmiDRIP/DROP
  44.  *  - Javadoc                  => https://lakshmidrip.github.io/DROP/Javadoc/index.html
  45.  *  - Technical Specifications => https://github.com/lakshmiDRIP/DROP/tree/master/Docs/Internal
  46.  *  - Release Versions         => https://lakshmidrip.github.io/DROP/version.html
  47.  *  - Community Credits        => https://lakshmidrip.github.io/DROP/credits.html
  48.  *  - Issues Catalog           => https://github.com/lakshmiDRIP/DROP/issues
  49.  *  - JUnit                    => https://lakshmidrip.github.io/DROP/junit/index.html
  50.  *  - Jacoco                   => https://lakshmidrip.github.io/DROP/jacoco/index.html
  51.  *
  52.  *  Licensed under the Apache License, Version 2.0 (the "License");
  53.  *      you may not use this file except in compliance with the License.
  54.  *  
  55.  *  You may obtain a copy of the License at
  56.  *      http://www.apache.org/licenses/LICENSE-2.0
  57.  *  
  58.  *  Unless required by applicable law or agreed to in writing, software
  59.  *      distributed under the License is distributed on an "AS IS" BASIS,
  60.  *      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  61.  *  
  62.  *  See the License for the specific language governing permissions and
  63.  *      limitations under the License.
  64.  */

  65. /**
  66.  * <i>PillaiSpecialChiSquare</i> demonstrates Generation of Pillai (2016) Special Chi-Squared R<sup>1</sup>
  67.  * Random Numbers with different Degrees of Freedom.
  68.  *
  69.  * <br><br>
  70.  *  <ul>
  71.  *      <li>
  72.  *          Backstrom, T., and J. Fischer (2018): Fast Randomization for Distributed Low Bit-rate Coding of
  73.  *              Speech and Audio <i>IEEE/ACM Transactions on Audio, Speech, and Language Processing</i> <b>26
  74.  *              (1)</b> 19-30
  75.  *      </li>
  76.  *      <li>
  77.  *          Chi-Squared Distribution (2019): Chi-Squared Function
  78.  *              https://en.wikipedia.org/wiki/Chi-squared_distribution
  79.  *      </li>
  80.  *      <li>
  81.  *          Johnson, N. L., S. Klotz, and N. Balakrishnan (1994): <i>Continuous Univariate Distributions
  82.  *              <b>1</b> 2<sup>nd</sup> Edition</i> <b>John Wiley and Sons</b>
  83.  *      </li>
  84.  *      <li>
  85.  *          Lancaster, H, O. (1969): <i>The Chi-Squared Distribution</i> <b>Wiley</b>
  86.  *      </li>
  87.  *      <li>
  88.  *          Pillai, N. S. (1026): An Unexpected Encounter with Cauchy and Levy <i>Annals of Statistics</i>
  89.  *              <b>44 (5)</b> 2089-2097
  90.  *      </li>
  91.  *  </ul>
  92.  *
  93.  *  <br><br>
  94.  *  <ul>
  95.  *      <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/NumericalCore.md">Numerical Core Module</a></li>
  96.  *      <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/NumericalOptimizerLibrary.md">Numerical Optimizer Library</a></li>
  97.  *      <li><b>Project</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/measure">Measure</a></li>
  98.  *      <li><b>Package</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/measure/discrete">Discrete</a></li>
  99.  *  </ul>
  100.  *
  101.  * @author Lakshmi Krishnamurthy
  102.  */

  103. public class PillaiSpecialChiSquare
  104. {

  105.     private static final void DisplayStream (
  106.         final double[][] covarianceMatrix,
  107.         final double[] weightArray)
  108.         throws Exception
  109.     {
  110.         double[] randomArray = SequenceGenerator.PillaiSpecialChiSquare (
  111.             200,
  112.             covarianceMatrix,
  113.             weightArray
  114.         );

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

  116.         for (int row = 0; row < 20; ++row)
  117.         {
  118.             String rowDump = "\t|";

  119.             for (int column = 0; column < 10; ++column)
  120.             {
  121.                 rowDump = rowDump + FormatUtil.FormatDouble (
  122.                     randomArray[row * 10 + column], 2, 4, 1.
  123.                 ) + " |";
  124.             }

  125.             System.out.println (rowDump + "|");
  126.         }

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

  128.         System.out.println();
  129.     }

  130.     public static final void main (
  131.         final String[] argumentArray)
  132.         throws Exception
  133.     {
  134.         EnvManager.InitEnv ("");

  135.         double[][] covarianceMatrix =
  136.         {
  137.             {1.00, 0.90, 0.10},
  138.             {0.90, 1.00, 0.50},
  139.             {0.10, 0.50, 1.00},
  140.         };
  141.         double[] weightArray =
  142.         {
  143.             0.2,
  144.             0.3,
  145.             0.5,
  146.         };

  147.         DisplayStream (
  148.             covarianceMatrix,
  149.             weightArray
  150.         );

  151.         EnvManager.TerminateEnv();
  152.     }
  153. }