IntegerRandomSequenceBound.java

  1. package org.drip.sample.sequence;

  2. import org.drip.measure.continuous.R1Univariate;
  3. import org.drip.measure.discrete.*;
  4. import org.drip.numerical.common.FormatUtil;
  5. import org.drip.sequence.metrics.*;
  6. import org.drip.sequence.random.*;
  7. import org.drip.service.env.EnvManager;

  8. /*
  9.  * -*- mode: java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  10.  */

  11. /*!
  12.  * Copyright (C) 2018 Lakshmi Krishnamurthy
  13.  * Copyright (C) 2017 Lakshmi Krishnamurthy
  14.  * Copyright (C) 2016 Lakshmi Krishnamurthy
  15.  * Copyright (C) 2015 Lakshmi Krishnamurthy
  16.  *
  17.  *  This file is part of DRIP, a free-software/open-source library for buy/side financial/trading model
  18.  *      libraries targeting analysts and developers
  19.  *      https://lakshmidrip.github.io/DRIP/
  20.  *  
  21.  *  DRIP is composed of four main libraries:
  22.  *  
  23.  *  - DRIP Fixed Income - https://lakshmidrip.github.io/DRIP-Fixed-Income/
  24.  *  - DRIP Asset Allocation - https://lakshmidrip.github.io/DRIP-Asset-Allocation/
  25.  *  - DRIP Numerical Optimizer - https://lakshmidrip.github.io/DRIP-Numerical-Optimizer/
  26.  *  - DRIP Statistical Learning - https://lakshmidrip.github.io/DRIP-Statistical-Learning/
  27.  *
  28.  *  - DRIP Fixed Income: Library for Instrument/Trading Conventions, Treasury Futures/Options,
  29.  *      Funding/Forward/Overnight Curves, Multi-Curve Construction/Valuation, Collateral Valuation and XVA
  30.  *      Metric Generation, Calibration and Hedge Attributions, Statistical Curve Construction, Bond RV
  31.  *      Metrics, Stochastic Evolution and Option Pricing, Interest Rate Dynamics and Option Pricing, LMM
  32.  *      Extensions/Calibrations/Greeks, Algorithmic Differentiation, and Asset Backed Models and Analytics.
  33.  *
  34.  *  - DRIP Asset Allocation: Library for model libraries for MPT framework, Black Litterman Strategy
  35.  *      Incorporator, Holdings Constraint, and Transaction Costs.
  36.  *
  37.  *  - DRIP Numerical Optimizer: Library for Numerical Optimization and Spline Functionality.
  38.  *
  39.  *  - DRIP Statistical Learning: Library for Statistical Evaluation and Machine Learning.
  40.  *
  41.  *  Licensed under the Apache License, Version 2.0 (the "License");
  42.  *      you may not use this file except in compliance with the License.
  43.  *  
  44.  *  You may obtain a copy of the License at
  45.  *      http://www.apache.org/licenses/LICENSE-2.0
  46.  *  
  47.  *  Unless required by applicable law or agreed to in writing, software
  48.  *      distributed under the License is distributed on an "AS IS" BASIS,
  49.  *      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  50.  *  
  51.  *  See the License for the specific language governing permissions and
  52.  *      limitations under the License.
  53.  */

  54. /**
  55.  * IntegerRandomSequenceBound demonstrates the Computation of the Probabilistic Bounds for a Sample Random
  56.  *  Integer Sequence.
  57.  *
  58.  * @author Lakshmi Krishnamurthy
  59.  */

  60. public class IntegerRandomSequenceBound {

  61.     private static final void IntegerBounds (
  62.         final UnivariateSequenceGenerator iidsg,
  63.         final R1Univariate dist,
  64.         final int[] aiSampleSize)
  65.         throws Exception
  66.     {
  67.         for (int iSampleSize : aiSampleSize) {
  68.             IntegerSequenceAgnosticMetrics ssamDist = (IntegerSequenceAgnosticMetrics) iidsg.sequence (
  69.                 iSampleSize,
  70.                 dist
  71.             );

  72.             String strDump = "\t| " + FormatUtil.FormatDouble (iSampleSize, 3, 0, 1) + " => ";

  73.             strDump +=
  74.                 FormatUtil.FormatDouble (ssamDist.probGreaterThanZeroUpperBound(), 1, 9, 1.) + " | " +
  75.                 FormatUtil.FormatDouble (ssamDist.probEqualToZeroUpperBound(), 1, 9, 1.) + " | ";

  76.             System.out.println (strDump);
  77.         }
  78.     }

  79.     public static void main (
  80.         final String[] args)
  81.         throws Exception
  82.     {
  83.         EnvManager.InitEnv ("");

  84.         BoundedUniformInteger buiSequence = new BoundedUniformInteger (
  85.             0,
  86.             100
  87.         );

  88.         BoundedUniformIntegerDistribution buiDistribution = new BoundedUniformIntegerDistribution (
  89.             0,
  90.             100
  91.         );

  92.         int[] aiSampleSize = new int[] {
  93.             10, 20, 50, 100, 250
  94.         };

  95.         System.out.println();

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

  97.         System.out.println ("\t| Generating Integer Random Sequence Metrics");

  98.         System.out.println ("\t| \tL -> R:");

  99.         System.out.println ("\t| \t\tSample Size");

  100.         System.out.println ("\t| \t\tUpper Probability Bound for X != 0");

  101.         System.out.println ("\t| \t\tUpper Probability Bound for X = 0");

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

  103.         System.out.println ("\t| Generating Metrics off of Underlying Distribution");

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

  105.         IntegerBounds (
  106.             buiSequence,
  107.             buiDistribution,
  108.             aiSampleSize
  109.         );

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

  111.         System.out.println();

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

  113.         System.out.println ("\t| Generating Metrics off of Empirical Distribution");

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

  115.         IntegerBounds (
  116.             buiSequence,
  117.             null,
  118.             aiSampleSize
  119.         );

  120.         System.out.println ("\t|----------------------------------------------------------------------------------|");
  121.     }
  122. }