BracketingOutput.java

  1. package org.drip.function.r1tor1solver;

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

  81. /**
  82.  * <i>BracketingOutput</i> carries the results of the bracketing initialization.
  83.  * <br><br>
  84.  *  In addition to the fields of ExecutionInitializationOutput, BracketingOutput holds the left/right bracket
  85.  *      variates and the corresponding values for the objective function.
  86.  *
  87.  *  <br><br>
  88.  *  <ul>
  89.  *      <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/ComputationalCore.md">Computational Core Module</a></li>
  90.  *      <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/NumericalAnalysisLibrary.md">Numerical Analysis Library</a></li>
  91.  *      <li><b>Project</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/function/README.md">R<sup>d</sup> To R<sup>d</sup> Function Analysis</a></li>
  92.  *      <li><b>Package</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/function/r1tor1solver/README.md">Built-in R<sup>1</sup> To R<sup>1</sup> Solvers</a></li>
  93.  *  </ul>
  94.  *
  95.  * @author Lakshmi Krishnamurthy
  96.  */

  97. public class BracketingOutput extends org.drip.function.r1tor1solver.ExecutionInitializationOutput {
  98.     private double _dblOFLeft = java.lang.Double.NaN;
  99.     private double _dblOFRight = java.lang.Double.NaN;
  100.     private double _dblVariateLeft = java.lang.Double.NaN;
  101.     private double _dblVariateRight = java.lang.Double.NaN;

  102.     /**
  103.      * Default BracketingOutput constructor: Initializes the output
  104.      */

  105.     public BracketingOutput()
  106.     {
  107.         super();
  108.     }

  109.     /**
  110.      * Return the left Variate
  111.      *
  112.      * @return Left Variate
  113.      */

  114.     public double getVariateLeft()
  115.     {
  116.         return _dblVariateLeft;
  117.     }

  118.     /**
  119.      * Return the Right Variate
  120.      *
  121.      * @return Right Variate
  122.      */

  123.     public double getVariateRight()
  124.     {
  125.         return _dblVariateRight;
  126.     }

  127.     /**
  128.      * Return the left OF
  129.      *
  130.      * @return Left OF
  131.      */

  132.     public double getOFLeft()
  133.     {
  134.         return _dblOFLeft;
  135.     }

  136.     /**
  137.      * Return the Right OF
  138.      *
  139.      * @return Right OF
  140.      */

  141.     public double getOFRight()
  142.     {
  143.         return _dblOFRight;
  144.     }

  145.     /**
  146.      * Set the brackets in the output object
  147.      *
  148.      * @param dblVariateLeft Left Variate
  149.      * @param dblVariateRight Right Variate
  150.      * @param dblOFLeft Left OF
  151.      * @param dblOFRight Right OF
  152.      * @param dblStartingVariate Starting Variate
  153.      *
  154.      * @return TRUE - Successfully set
  155.      */

  156.     public boolean done (
  157.         final double dblVariateLeft,
  158.         final double dblVariateRight,
  159.         final double dblOFLeft,
  160.         final double dblOFRight,
  161.         final double dblStartingVariate)
  162.     {
  163.         if (!org.drip.numerical.common.NumberUtil.IsValid (_dblVariateLeft = dblVariateLeft) ||
  164.             !org.drip.numerical.common.NumberUtil.IsValid (_dblVariateRight = dblVariateRight) ||
  165.                 !org.drip.numerical.common.NumberUtil.IsValid (_dblOFLeft = dblOFLeft) ||
  166.                     !org.drip.numerical.common.NumberUtil.IsValid (_dblOFRight = dblOFRight) ||
  167.                         !setStartingVariate (dblStartingVariate))
  168.             return false;

  169.         return done();
  170.     }

  171.     /**
  172.      * Make a ConvergenceOutput for the Open Method from the bracketing output
  173.      *
  174.      * @return The ConvergenceOutput object
  175.      */

  176.     public org.drip.function.r1tor1solver.ConvergenceOutput makeConvergenceVariate()
  177.     {
  178.         org.drip.function.r1tor1solver.ConvergenceOutput cop = null;

  179.         try {
  180.             cop = new org.drip.function.r1tor1solver.ConvergenceOutput (this);
  181.         } catch (java.lang.Exception e) {
  182.             e.printStackTrace();
  183.         }

  184.         return cop.done (getStartingVariate()) ? cop : null;
  185.     }

  186.     @Override public java.lang.String displayString()
  187.     {
  188.         java.lang.StringBuffer sb = new java.lang.StringBuffer();

  189.         sb.append (super.displayString());

  190.         sb.append ("\n\t\tLeft Bracket: " + getVariateLeft());

  191.         sb.append ("\n\t\tRight Bracket: " + getVariateRight());

  192.         sb.append ("\n\t\tLeft OF: " + getOFLeft());

  193.         sb.append ("\n\t\tRight OF: " + getOFRight());

  194.         return sb.toString();
  195.     }
  196. }