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

  102. public class F
  103. {

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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