PlottingPositionGeneratorHeuristic.java

  1. package org.drip.validation.quantile;

  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>PlottingPositionGeneratorHeuristic</i> holds the Expected Order Statistic Based Heuristic Plotting
  76.  * Position Generation Schemes.
  77.  *
  78.  *  <br><br>
  79.  *  <ul>
  80.  *      <li>
  81.  *          Filliben, J. J. (1975): The Probability Plot Correlation Coefficient Test for Normality
  82.  *              <i>Technometrics, American Society for Quality</i> <b>17 (1)</b> 111-117
  83.  *      </li>
  84.  *      <li>
  85.  *          Gibbons, J. D., and S. Chakraborti (2003): <i>Non-parametric Statistical Inference 4th
  86.  *              Edition</i> <b>CRC Press</b>
  87.  *      </li>
  88.  *      <li>
  89.  *          Gnanadesikan, R. (1977): <i>Methods for Statistical Analysis of Multivariate Observations</i>
  90.  *              <b>Wiley</b>
  91.  *      </li>
  92.  *      <li>
  93.  *          Thode, H. C. (2002): <i>Testing for Normality</i> <b>Marcel Dekker</b> New York
  94.  *      </li>
  95.  *      <li>
  96.  *          Wikipedia (2018): Q-Q Plot https://en.wikipedia.org/wiki/Q%E2%80%93Q_plot
  97.  *      </li>
  98.  *  </ul>
  99.  *
  100.  *  <br><br>
  101.  *  <ul>
  102.  *      <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/ComputationalCore.md">Computational Core Module</a></li>
  103.  *      <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/ModelValidationAnalyticsLibrary.md">Model Validation Analytics Library</a></li>
  104.  *      <li><b>Project</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/validation/README.md">Risk Factor and Hypothesis Validation, Evidence Processing, and Model Testing</a></li>
  105.  *      <li><b>Package</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/validation/quantile/README.md">Quantile Based Graphical Numerical Validators</a></li>
  106.  *  </ul>
  107.  * <br><br>
  108.  *
  109.  * @author Lakshmi Krishnamurthy
  110.  */

  111. public class PlottingPositionGeneratorHeuristic extends
  112.     org.drip.validation.quantile.PlottingPositionGenerator
  113. {

  114.     /**
  115.      * Standard Heuristic
  116.      */

  117.     public static final double RELIEF_STANDARD = 0.;

  118.     /**
  119.      * Bernard and Bos-Levenbach (1953) Heuristic
  120.      */

  121.     public static final double RELIEF_BERNARD_BOS_LEVENBACH_1953 = 0.3;

  122.     /**
  123.      * NIST (2013) Heuristic
  124.      */

  125.     public static final double RELIEF_NIST_2013 = 0.3175;

  126.     /**
  127.      * Yu and Huang (2001) Heuristic
  128.      */

  129.     public static final double RELIEF_YU_HUANG_2001 = 0.326;

  130.     /**
  131.      * BMDP (2018) Heuristic
  132.      */

  133.     public static final double RELIEF_BMDP_2018 = 0.333333;

  134.     /**
  135.      * Blom (1958) Heuristic
  136.      */

  137.     public static final double RELIEF_BLOM_1958 = 0.375;

  138.     /**
  139.      * Cunnane (1978) Heuristic
  140.      */

  141.     public static final double RELIEF_CUNNANE_1978 = 0.4;

  142.     /**
  143.      * Gringorten (1963) Heuristic
  144.      */

  145.     public static final double RELIEF_GRINGORTEN_1963 = 0.44;

  146.     /**
  147.      * Hazen (1913) Heuristic
  148.      */

  149.     public static final double RELIEF_HAZEN_1913 = 0.5;

  150.     /**
  151.      * Larsen, Currant, and Hunt (1980) Heuristic
  152.      */

  153.     public static final double RELIEF_LARSEN_CURRANT_HUNT_1980 = 0.567;

  154.     /**
  155.      * Filliben (1975) Heuristic
  156.      */

  157.     public static final double RELIEF_FILLIBEN_1975 = 1.;

  158.     /**
  159.      * Construct the Standard Version of the PlottingPositionGeneratorHeuristic
  160.      *
  161.      * @param orderStatisticCount The Order Statistic Count
  162.      *
  163.      * @return Standard Version of the PlottingPositionGeneratorHeuristic
  164.      */

  165.     public static final PlottingPositionGeneratorHeuristic Standard (
  166.         final int orderStatisticCount)
  167.     {
  168.         try
  169.         {
  170.             return new PlottingPositionGeneratorHeuristic (
  171.                 orderStatisticCount,
  172.                 RELIEF_STANDARD
  173.             );
  174.         }
  175.         catch (java.lang.Exception e)
  176.         {
  177.             e.printStackTrace();
  178.         }

  179.         return null;
  180.     }

  181.     /**
  182.      * Construct the Bernard Bos-Levenbach (1953) Version of the PlottingPositionGeneratorHeuristic
  183.      *
  184.      * @param orderStatisticCount The Order Statistic Count
  185.      *
  186.      * @return Bernard Bos-Levenbach (1953) Version of the PlottingPositionGeneratorHeuristic
  187.      */

  188.     public static final PlottingPositionGeneratorHeuristic BernardBosLevenbach1953 (
  189.         final int orderStatisticCount)
  190.     {
  191.         try
  192.         {
  193.             return new PlottingPositionGeneratorHeuristic (
  194.                 orderStatisticCount,
  195.                 RELIEF_BERNARD_BOS_LEVENBACH_1953
  196.             );
  197.         }
  198.         catch (java.lang.Exception e)
  199.         {
  200.             e.printStackTrace();
  201.         }

  202.         return null;
  203.     }

  204.     /**
  205.      * Construct the NIST (2013) Version of the PlottingPositionGeneratorHeuristic
  206.      *
  207.      * @param orderStatisticCount The Order Statistic Count
  208.      *
  209.      * @return NIST (2013) Version of the PlottingPositionGeneratorHeuristic
  210.      */

  211.     public static final PlottingPositionGeneratorHeuristic NIST2013 (
  212.         final int orderStatisticCount)
  213.     {
  214.         try
  215.         {
  216.             return new PlottingPositionGeneratorHeuristic (
  217.                 orderStatisticCount,
  218.                 RELIEF_NIST_2013
  219.             );
  220.         }
  221.         catch (java.lang.Exception e)
  222.         {
  223.             e.printStackTrace();
  224.         }

  225.         return null;
  226.     }

  227.     /**
  228.      * Construct the Yu and Huang (2001) Version of the PlottingPositionGeneratorHeuristic
  229.      *
  230.      * @param orderStatisticCount The Order Statistic Count
  231.      *
  232.      * @return Yu and Huang (2001) Version of the PlottingPositionGeneratorHeuristic
  233.      */

  234.     public static final PlottingPositionGeneratorHeuristic YuHuang2001 (
  235.         final int orderStatisticCount)
  236.     {
  237.         try
  238.         {
  239.             return new PlottingPositionGeneratorHeuristic (
  240.                 orderStatisticCount,
  241.                 RELIEF_YU_HUANG_2001
  242.             );
  243.         }
  244.         catch (java.lang.Exception e)
  245.         {
  246.             e.printStackTrace();
  247.         }

  248.         return null;
  249.     }

  250.     /**
  251.      * Construct the BMDP (2018) Version of the PlottingPositionGeneratorHeuristic
  252.      *
  253.      * @param orderStatisticCount The Order Statistic Count
  254.      *
  255.      * @return BMDP (2018) Version of the PlottingPositionGeneratorHeuristic
  256.      */

  257.     public static final PlottingPositionGeneratorHeuristic BMDP2018 (
  258.         final int orderStatisticCount)
  259.     {
  260.         try
  261.         {
  262.             return new PlottingPositionGeneratorHeuristic (
  263.                 orderStatisticCount,
  264.                 RELIEF_BMDP_2018
  265.             );
  266.         }
  267.         catch (java.lang.Exception e)
  268.         {
  269.             e.printStackTrace();
  270.         }

  271.         return null;
  272.     }

  273.     /**
  274.      * Construct the Blom (1958) Version of the PlottingPositionGeneratorHeuristic
  275.      *
  276.      * @param orderStatisticCount The Order Statistic Count
  277.      *
  278.      * @return Blom (1958) Version of the PlottingPositionGeneratorHeuristic
  279.      */

  280.     public static final PlottingPositionGeneratorHeuristic Blom1958 (
  281.         final int orderStatisticCount)
  282.     {
  283.         try
  284.         {
  285.             return new PlottingPositionGeneratorHeuristic (
  286.                 orderStatisticCount,
  287.                 RELIEF_BLOM_1958
  288.             );
  289.         }
  290.         catch (java.lang.Exception e)
  291.         {
  292.             e.printStackTrace();
  293.         }

  294.         return null;
  295.     }

  296.     /**
  297.      * Construct the Cunnane (1978) Version of the PlottingPositionGeneratorHeuristic
  298.      *
  299.      * @param orderStatisticCount The Order Statistic Count
  300.      *
  301.      * @return Cunnane (1978) Version of the PlottingPositionGeneratorHeuristic
  302.      */

  303.     public static final PlottingPositionGeneratorHeuristic Cunnane1978 (
  304.         final int orderStatisticCount)
  305.     {
  306.         try
  307.         {
  308.             return new PlottingPositionGeneratorHeuristic (
  309.                 orderStatisticCount,
  310.                 RELIEF_CUNNANE_1978
  311.             );
  312.         }
  313.         catch (java.lang.Exception e)
  314.         {
  315.             e.printStackTrace();
  316.         }

  317.         return null;
  318.     }

  319.     /**
  320.      * Construct the Gringorten (1963) Version of the PlottingPositionGeneratorHeuristic
  321.      *
  322.      * @param orderStatisticCount The Order Statistic Count
  323.      *
  324.      * @return Gringorten (1963) Version of the PlottingPositionGeneratorHeuristic
  325.      */

  326.     public static final PlottingPositionGeneratorHeuristic Gringorten1963 (
  327.         final int orderStatisticCount)
  328.     {
  329.         try
  330.         {
  331.             return new PlottingPositionGeneratorHeuristic (
  332.                 orderStatisticCount,
  333.                 RELIEF_GRINGORTEN_1963
  334.             );
  335.         }
  336.         catch (java.lang.Exception e)
  337.         {
  338.             e.printStackTrace();
  339.         }

  340.         return null;
  341.     }

  342.     /**
  343.      * Construct the Hazen (1913) Version of the PlottingPositionGeneratorHeuristic
  344.      *
  345.      * @param orderStatisticCount The Order Statistic Count
  346.      *
  347.      * @return Hazen (1913) Version of the PlottingPositionGeneratorHeuristic
  348.      */

  349.     public static final PlottingPositionGeneratorHeuristic Hazen1913 (
  350.         final int orderStatisticCount)
  351.     {
  352.         try
  353.         {
  354.             return new PlottingPositionGeneratorHeuristic (
  355.                 orderStatisticCount,
  356.                 RELIEF_HAZEN_1913
  357.             );
  358.         }
  359.         catch (java.lang.Exception e)
  360.         {
  361.             e.printStackTrace();
  362.         }

  363.         return null;
  364.     }

  365.     /**
  366.      * Construct the Larsen, Currant, and Hunt (1980) Version of the PlottingPositionGeneratorHeuristic
  367.      *
  368.      * @param orderStatisticCount The Order Statistic Count
  369.      *
  370.      * @return Larsen, Currant, and Hunt (1980) Version of the PlottingPositionGeneratorHeuristic
  371.      */

  372.     public static final PlottingPositionGeneratorHeuristic LarsenCurrantHunt1980 (
  373.         final int orderStatisticCount)
  374.     {
  375.         try
  376.         {
  377.             return new PlottingPositionGeneratorHeuristic (
  378.                 orderStatisticCount,
  379.                 RELIEF_LARSEN_CURRANT_HUNT_1980
  380.             );
  381.         }
  382.         catch (java.lang.Exception e)
  383.         {
  384.             e.printStackTrace();
  385.         }

  386.         return null;
  387.     }

  388.     /**
  389.      * Construct the Filliben (1975) Version of the PlottingPositionGeneratorHeuristic
  390.      *
  391.      * @param orderStatisticCount The Order Statistic Count
  392.      *
  393.      * @return Filliben (1975) Version of the PlottingPositionGeneratorHeuristic
  394.      */

  395.     public static final PlottingPositionGeneratorHeuristic Filliben1975 (
  396.         final int orderStatisticCount)
  397.     {
  398.         try
  399.         {
  400.             return new PlottingPositionGeneratorHeuristic (
  401.                 orderStatisticCount,
  402.                 RELIEF_FILLIBEN_1975
  403.             );
  404.         }
  405.         catch (java.lang.Exception e)
  406.         {
  407.             e.printStackTrace();
  408.         }

  409.         return null;
  410.     }

  411.     private double _relief = java.lang.Double.NaN;

  412.     /**
  413.      * PlottingPositionGeneratorHeuristic Constructor
  414.      *
  415.      * @param orderStatisticCount Count of Order Statistics
  416.      * @param relief Leading Relief
  417.      *
  418.      * @throws java.lang.Exception Thrown if the Inputs are Invalid
  419.      */

  420.     public PlottingPositionGeneratorHeuristic (
  421.         final int orderStatisticCount,
  422.         final double relief)
  423.         throws java.lang.Exception
  424.     {
  425.         super (orderStatisticCount);

  426.         if (!org.drip.numerical.common.NumberUtil.IsValid (_relief = relief) || 0. > _relief || 1. < _relief)
  427.         {
  428.             throw new java.lang.Exception
  429.                 ("PlottingPositionGeneratorHeuristic Constructor => Invalid Inputs");
  430.         }
  431.     }

  432.     /**
  433.      * Retrieve the Leading Relief
  434.      *
  435.      * @return The Leading Relief
  436.      */

  437.     public double relief()
  438.     {
  439.         return _relief;
  440.     }

  441.     @Override public org.drip.validation.quantile.PlottingPosition[] generate()
  442.     {
  443.         int orderStatisticCount = orderStatisticCount();

  444.         org.drip.validation.quantile.PlottingPosition[] plottingPositionArray = new
  445.             org.drip.validation.quantile.PlottingPosition[orderStatisticCount];

  446.         for (int orderStatisticIndex = 1; orderStatisticIndex <= orderStatisticCount; ++orderStatisticIndex)
  447.         {
  448.             try
  449.             {
  450.                 plottingPositionArray[orderStatisticIndex - 1] =
  451.                     new org.drip.validation.quantile.PlottingPosition (
  452.                         orderStatisticIndex,
  453.                         (((double) orderStatisticIndex) - _relief) /
  454.                             (1. + orderStatisticCount - 2. * _relief)
  455.                     );
  456.             }
  457.             catch (java.lang.Exception e)
  458.             {
  459.                 e.printStackTrace();

  460.                 return null;
  461.             }
  462.         }

  463.         return plottingPositionArray;
  464.     }
  465. }