PoissonRandomSequenceBound.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.  * PoissonRandomSequenceBound demonstrates the Computation of the Probabilistic Bounds for a Sample Random
  56.  *  Poisson Sequence.
  57.  *
  58.  * @author Lakshmi Krishnamurthy
  59.  */

  60. public class PoissonRandomSequenceBound {

  61.     private static final void Head (
  62.         final String strHeader)
  63.     {
  64.         System.out.println();

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

  66.         System.out.println (strHeader);

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

  68.         System.out.println ("\t| SIZE ||               <-               TOLERANCES               ->               |");

  69.         System.out.println ("\t|----------------------------------------------------------------------------------|");
  70.     }

  71.     private static final void ChernoffStirlingBounds (
  72.         final UnivariateSequenceGenerator iidsg,
  73.         final R1Univariate dist,
  74.         final int[] aiSampleSize,
  75.         final double[] adblTolerance)
  76.         throws Exception
  77.     {
  78.         for (int iSampleSize : aiSampleSize) {
  79.             PoissonSequenceAgnosticMetrics ssamDist = (PoissonSequenceAgnosticMetrics) iidsg.sequence (
  80.                 iSampleSize,
  81.                 dist
  82.             );

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

  84.             for (double dblTolerance : adblTolerance)
  85.                 strDump += FormatUtil.FormatDouble (ssamDist.chernoffStirlingUpperBound (dblTolerance), 1, 9, 1.) + " | ";

  86.             System.out.println (strDump);
  87.         }
  88.     }

  89.     public static void main (
  90.         final String[] args)
  91.         throws Exception
  92.     {
  93.         EnvManager.InitEnv ("");

  94.         Poisson poissonRandom = new Poisson (10.);

  95.         PoissonDistribution poissonDistribution = new PoissonDistribution (10.);

  96.         int[] aiSampleSize = new int[] {
  97.             10, 20, 50, 100, 250
  98.         };

  99.         double[] adblTolerance = new double[] {
  100.             5., 10., 15., 20., 25.
  101.         };

  102.         Head ("\t|        CHERNOFF-STIRLING BOUNDS    -     METRICS FROM UNDERLYING GENERATOR       |");

  103.         ChernoffStirlingBounds (
  104.             poissonRandom,
  105.             poissonDistribution,
  106.             aiSampleSize,
  107.             adblTolerance
  108.         );

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

  110.         Head ("\t|      CHERNOFF-STIRLING BOUNDS    -     METRICS FROM EMPIRICAL DISTRIBUTION       |");

  111.         ChernoffStirlingBounds (
  112.             poissonRandom,
  113.             null,
  114.             aiSampleSize,
  115.             adblTolerance
  116.         );

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