DualRandomSequenceBound.java

  1. package org.drip.sample.sequence;

  2. import org.drip.numerical.common.FormatUtil;
  3. import org.drip.sequence.metrics.*;
  4. import org.drip.sequence.random.BoundedUniform;
  5. import org.drip.service.env.EnvManager;

  6. /*

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

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

  52. /**
  53.  * DualRandomSequenceBound demonstrates the Computation of the Probabilistic Bounds for a Joint Realizations
  54.  *  of a Sample Random Sequence.
  55.  *
  56.  * @author Lakshmi Krishnamurthy
  57.  */

  58. public class DualRandomSequenceBound {

  59.     private static final void CauchySchwartzBound (
  60.         final double dblLeft1,
  61.         final double dblRight1,
  62.         final double dblLeft2,
  63.         final double dblRight2)
  64.         throws Exception
  65.     {
  66.         SingleSequenceAgnosticMetrics ssam1 = new BoundedUniform (
  67.             dblLeft1,
  68.             dblRight1
  69.         ).sequence (
  70.             50000,
  71.             null
  72.         );

  73.         SingleSequenceAgnosticMetrics ssam2 = new BoundedUniform (
  74.             dblLeft2,
  75.             dblRight2
  76.         ).sequence (
  77.             50000,
  78.             null
  79.         );

  80.         DualSequenceAgnosticMetrics dsam = new DualSequenceAgnosticMetrics (
  81.             ssam1,
  82.             ssam2
  83.         );

  84.         System.out.println ("\t| " +
  85.             FormatUtil.FormatDouble (ssam1.empiricalExpectation(), 1, 4, 1.) + " | " +
  86.             FormatUtil.FormatDouble (ssam2.empiricalExpectation(), 1, 4, 1.) + " | " +
  87.             FormatUtil.FormatDouble (dsam.cauchySchwarzAbsoluteBound(), 1, 4, 1.) + " |"
  88.         );
  89.     }

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

  95.         System.out.println();

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

  97.         System.out.println ("\t| MEAN #1 | MEAN #2 |  JOINT  |");

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

  99.         CauchySchwartzBound (0., 1., 0., 1.);

  100.         CauchySchwartzBound (0., 1., 1., 2.);

  101.         CauchySchwartzBound (0., 1., 2., 3.);

  102.         CauchySchwartzBound (0., 1., 3., 4.);

  103.         CauchySchwartzBound (0., 1., 4., 5.);

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