Beta.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>Beta</i> demonstrates Generation of Beta R<sup>2</sup> Random Numbers with Two different Degrees of
  67.  * 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 Beta
  104. {

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

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

  116.         System.out.println ("\t|  Degrees of Freedom => [" + degreesOfFreedom1 + " | " + degreesOfFreedom2 + "]");

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

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

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

  127.             System.out.println (rowDump + "|");
  128.         }

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

  130.         System.out.println();
  131.     }

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

  137.         DisplayStream (
  138.             2,
  139.             2
  140.         );

  141.         DisplayStream (
  142.             2,
  143.             5
  144.         );

  145.         DisplayStream (
  146.             2,
  147.             10
  148.         );

  149.         DisplayStream (
  150.             5,
  151.             2
  152.         );

  153.         DisplayStream (
  154.             5,
  155.             5
  156.         );

  157.         DisplayStream (
  158.             5,
  159.             10
  160.         );

  161.         DisplayStream (
  162.             10,
  163.             2
  164.         );

  165.         DisplayStream (
  166.             10,
  167.             5
  168.         );

  169.         DisplayStream (
  170.             10,
  171.             10
  172.         );

  173.         EnvManager.TerminateEnv();
  174.     }
  175. }