L1R1CoveringBounds.java

  1. package org.drip.spaces.cover;

  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.  * Copyright (C) 2018 Lakshmi Krishnamurthy
  9.  * Copyright (C) 2017 Lakshmi Krishnamurthy
  10.  * Copyright (C) 2016 Lakshmi Krishnamurthy
  11.  * Copyright (C) 2015 Lakshmi Krishnamurthy
  12.  *
  13.  *  This file is part of DROP, an open-source library targeting analytics/risk, transaction cost analytics,
  14.  *      asset liability management analytics, capital, exposure, and margin analytics, valuation adjustment
  15.  *      analytics, and portfolio construction analytics within and across fixed income, credit, commodity,
  16.  *      equity, FX, and structured products. It also includes auxiliary libraries for algorithm support,
  17.  *      numerical analysis, numerical optimization, spline builder, model validation, statistical learning,
  18.  *      and computational support.
  19.  *  
  20.  *      https://lakshmidrip.github.io/DROP/
  21.  *  
  22.  *  DROP is composed of three modules:
  23.  *  
  24.  *  - DROP Product Core - https://lakshmidrip.github.io/DROP-Product-Core/
  25.  *  - DROP Portfolio Core - https://lakshmidrip.github.io/DROP-Portfolio-Core/
  26.  *  - DROP Computational Core - https://lakshmidrip.github.io/DROP-Computational-Core/
  27.  *
  28.  *  DROP Product Core implements libraries for the following:
  29.  *  - Fixed Income Analytics
  30.  *  - Loan Analytics
  31.  *  - Transaction Cost Analytics
  32.  *
  33.  *  DROP Portfolio Core implements libraries for the following:
  34.  *  - Asset Allocation Analytics
  35.  *  - Asset Liability Management Analytics
  36.  *  - Capital Estimation Analytics
  37.  *  - Exposure Analytics
  38.  *  - Margin Analytics
  39.  *  - XVA Analytics
  40.  *
  41.  *  DROP Computational Core implements libraries for the following:
  42.  *  - Algorithm Support
  43.  *  - Computation Support
  44.  *  - Function Analysis
  45.  *  - Model Validation
  46.  *  - Numerical Analysis
  47.  *  - Numerical Optimizer
  48.  *  - Spline Builder
  49.  *  - Statistical Learning
  50.  *
  51.  *  Documentation for DROP is Spread Over:
  52.  *
  53.  *  - Main                     => https://lakshmidrip.github.io/DROP/
  54.  *  - Wiki                     => https://github.com/lakshmiDRIP/DROP/wiki
  55.  *  - GitHub                   => https://github.com/lakshmiDRIP/DROP
  56.  *  - Repo Layout Taxonomy     => https://github.com/lakshmiDRIP/DROP/blob/master/Taxonomy.md
  57.  *  - Javadoc                  => https://lakshmidrip.github.io/DROP/Javadoc/index.html
  58.  *  - Technical Specifications => https://github.com/lakshmiDRIP/DROP/tree/master/Docs/Internal
  59.  *  - Release Versions         => https://lakshmidrip.github.io/DROP/version.html
  60.  *  - Community Credits        => https://lakshmidrip.github.io/DROP/credits.html
  61.  *  - Issues Catalog           => https://github.com/lakshmiDRIP/DROP/issues
  62.  *  - JUnit                    => https://lakshmidrip.github.io/DROP/junit/index.html
  63.  *  - Jacoco                   => https://lakshmidrip.github.io/DROP/jacoco/index.html
  64.  *
  65.  *  Licensed under the Apache License, Version 2.0 (the "License");
  66.  *      you may not use this file except in compliance with the License.
  67.  *  
  68.  *  You may obtain a copy of the License at
  69.  *      http://www.apache.org/licenses/LICENSE-2.0
  70.  *  
  71.  *  Unless required by applicable law or agreed to in writing, software
  72.  *      distributed under the License is distributed on an "AS IS" BASIS,
  73.  *      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  74.  *  
  75.  *  See the License for the specific language governing permissions and
  76.  *      limitations under the License.
  77.  */

  78. /**
  79.  * <i>L1R1CoveringBounds</i> implements the Lower/Upper Bounds for the Class of Non-decreasing R<sup>1</sup>
  80.  * To L<sub>1</sub> R<sup>1</sup> for Functions that are:
  81.  *
  82.  * <br><br>
  83.  *  <ul>
  84.  *      <li>
  85.  *          Absolutely Bounded
  86.  *      </li>
  87.  *      <li>
  88.  *          Have Bounded Variation
  89.  *      </li>
  90.  *  </ul>
  91.  *
  92.  * The References are:
  93.  *
  94.  * <br><br>
  95.  *  <ul>
  96.  *      <li>
  97.  *          P. L. Bartlett, S. R. Kulkarni, and S. E. Posner (1997): Covering Numbers for Real-valued
  98.  *              Function Classes <i>IEEE Transactions on Information Theory</i> <b>45 (5)</b> 1721-1724
  99.  *      </li>
  100.  *      <li>
  101.  *          L. Birge (1987): Estimating a Density Under Order Restrictions: Non-asymptotic Minimax Risk
  102.  *              <i>Annals of Statistics</i> <b>15</b> 995-1012
  103.  *      </li>
  104.  *  </ul>
  105.  *
  106.  * <br><br>
  107.  *  <ul>
  108.  *      <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/ComputationalCore.md">Computational Core Module</a></li>
  109.  *      <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/StatisticalLearningLibrary.md">Statistical Learning Library</a></li>
  110.  *      <li><b>Project</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/spaces/README.md">R<sup>1</sup> and R<sup>d</sup> Vector/Tensor Spaces (Validated and/or Normed), and Function Classes</a></li>
  111.  *      <li><b>Package</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/spaces/cover/README.md">Vector Spaces Covering Number Estimator</a></li>
  112.  *  </ul>
  113.  * <br><br>
  114.  *
  115.  * @author Lakshmi Krishnamurthy
  116.  */

  117. public class L1R1CoveringBounds implements org.drip.spaces.cover.FunctionClassCoveringBounds {
  118.     private double _dblBound = java.lang.Double.NaN;
  119.     private double _dblSupport = java.lang.Double.NaN;
  120.     private double _dblVariation = java.lang.Double.NaN;

  121.     /**
  122.      * L1R1CoveringBounds Constructor
  123.      *
  124.      * @param dblSupport The Ordinate Support
  125.      * @param dblVariation The Function Variation
  126.      * @param dblBound The Function Bound
  127.      *
  128.      * @throws java.lang.Exception Thrown if the Inputs are Invalid
  129.      */

  130.     public L1R1CoveringBounds (
  131.         final double dblSupport,
  132.         final double dblVariation,
  133.         final double dblBound)
  134.         throws java.lang.Exception
  135.     {
  136.         if (!org.drip.numerical.common.NumberUtil.IsValid (_dblSupport = dblSupport) || 0. >= _dblSupport ||
  137.             !org.drip.numerical.common.NumberUtil.IsValid (_dblVariation = dblVariation) || 0. >= _dblVariation)
  138.             throw new java.lang.Exception ("L1R1CoveringBounds ctr: Invalid Inputs");

  139.         if (org.drip.numerical.common.NumberUtil.IsValid (_dblBound = dblBound) && _dblBound <= 0.5 *
  140.             _dblVariation)
  141.             throw new java.lang.Exception ("L1R1CoveringBounds ctr: Invalid Inputs");
  142.     }

  143.     /**
  144.      * Retrieve the Ordinate Support
  145.      *
  146.      * @return The Ordinate Support
  147.      */

  148.     public double support()
  149.     {
  150.         return _dblSupport;
  151.     }

  152.     /**
  153.      * Retrieve the Function Variation
  154.      *
  155.      * @return The Function Variation
  156.      */

  157.     public double variation()
  158.     {
  159.         return _dblVariation;
  160.     }

  161.     /**
  162.      * Retrieve the Function Bound
  163.      *
  164.      * @return The Function Bound
  165.      */

  166.     public double bound()
  167.     {
  168.         return _dblBound;
  169.     }

  170.     @Override public double logLowerBound (
  171.         final double dblCover)
  172.         throws java.lang.Exception
  173.     {
  174.         if (!org.drip.numerical.common.NumberUtil.IsValid (dblCover) || 0. == dblCover)
  175.             throw new java.lang.Exception ("L1R1CoveringBounds::logLowerBound => Invalid Inputs");

  176.         double dblVariationCoverScale = dblCover / (_dblSupport * _dblVariation);
  177.         double dblVariationLogLowerBound = 1. / (54. * dblVariationCoverScale);

  178.         if (1. < 12. * dblVariationCoverScale)
  179.             throw new java.lang.Exception ("L1R1CoveringBounds::logLowerBound => Invalid Inputs");

  180.         return !org.drip.numerical.common.NumberUtil.IsValid (_dblBound) ? dblVariationLogLowerBound : 1. +
  181.             dblVariationLogLowerBound * java.lang.Math.log (2.) + java.lang.Math.log (_dblSupport * _dblBound
  182.                 / (6. * dblCover));
  183.     }

  184.     @Override public double logUpperBound (
  185.         final double dblCover)
  186.         throws java.lang.Exception
  187.     {
  188.         if (!org.drip.numerical.common.NumberUtil.IsValid (dblCover))
  189.             throw new java.lang.Exception ("L1R1CoveringBounds::logUpperBound => Invalid Inputs");

  190.         double dblVariationCoverScale = dblCover / (_dblSupport * _dblVariation);

  191.         if (1. < 12. * dblVariationCoverScale)
  192.             throw new java.lang.Exception ("L1R1CoveringBounds::logUpperBound => Invalid Inputs");

  193.         if (!org.drip.numerical.common.NumberUtil.IsValid (_dblBound))
  194.             return java.lang.Math.log (2.) * 12. / dblVariationCoverScale;

  195.         return java.lang.Math.log (2.) * 18. / dblVariationCoverScale + 3. * _dblSupport * (2. * _dblBound -
  196.             _dblVariation) / (8. * dblCover);
  197.     }
  198. }