FixedPointFinderOutput.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>FixedPointFinderOutput</i> holds the result of the fixed point search.
  83.  *
  84.  * FixedPointFinderOutput contains the following fields:
  85.  * <br>
  86.  * <ul>
  87.  *  <li>
  88.  *      Whether the search completed successfully
  89.  *  </li>
  90.  *  <li>
  91.  *      The number of iterations, the number of objective function base/derivative calculations, and the time
  92.  *          taken for the search
  93.  *  </li>
  94.  *  <li>
  95.  *      The output from initialization
  96.  *  </li>
  97.  * </ul>
  98.  *
  99.  *  <br><br>
  100.  *  <ul>
  101.  *      <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/ComputationalCore.md">Computational Core Module</a></li>
  102.  *      <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/NumericalAnalysisLibrary.md">Numerical Analysis Library</a></li>
  103.  *      <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>
  104.  *      <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>
  105.  *  </ul>
  106.  *
  107.  * @author Lakshmi Krishnamurthy
  108.  */

  109. public class FixedPointFinderOutput {
  110.     private int _iNumOFCalcs = 0;
  111.     private long _lStartTime = 0L;
  112.     private int _iNumIterations = 0;
  113.     private int _iNumOFDerivCalcs = 0;
  114.     private boolean _bHasRoot = false;
  115.     private double _dblRoot = java.lang.Double.NaN;
  116.     private double _dblRootFindingTime = java.lang.Double.NaN;
  117.     private org.drip.function.r1tor1solver.ExecutionInitializationOutput _eiop = null;

  118.     /**
  119.      * FixedPointFinderOutput constructor
  120.      *
  121.      * @param eiop Execution Initialization Output 1D
  122.      *
  123.      * @throws java.lang.Exception Thrown if inputs are invalid
  124.      */

  125.     public FixedPointFinderOutput (
  126.         final org.drip.function.r1tor1solver.ExecutionInitializationOutput eiop)
  127.         throws java.lang.Exception
  128.     {
  129.         if (null == (_eiop = eiop))
  130.             throw new java.lang.Exception ("FixedPointFinderOutput constructor: Invalid inputs!");

  131.         _lStartTime = System.nanoTime();
  132.     }

  133.     /**
  134.      * Set the Root
  135.      *
  136.      * @param dblRoot Root
  137.      *
  138.      * @return TRUE - Successfully set
  139.      */

  140.     public boolean setRoot (
  141.         final double dblRoot)
  142.     {
  143.         _dblRootFindingTime = (System.nanoTime() - _lStartTime) * 0.000001;

  144.         if (!org.drip.numerical.common.NumberUtil.IsValid (_dblRoot = dblRoot)) return false;

  145.         return _bHasRoot = true;
  146.     }

  147.     /**
  148.      * Indicate whether the root is present in the output, i.e., if the finder has successfully completed.
  149.      *
  150.      * @return TRUE - Root exists in the output
  151.      */

  152.     public boolean containsRoot()
  153.     {
  154.         return _bHasRoot;
  155.     }

  156.     /**
  157.      * Return the time elapsed for the the full root finding operation
  158.      *
  159.      * @return Time taken for root finding
  160.      */

  161.     public double time()
  162.     {
  163.         return _dblRootFindingTime;
  164.     }

  165.     /**
  166.      * Return the root
  167.      *
  168.      * @return Root
  169.      */

  170.     public double getRoot()
  171.     {
  172.         return _dblRoot;
  173.     }

  174.     /**
  175.      * Increment the number of Iterations
  176.      *
  177.      * @return TRUE - Successfully incremented
  178.      */

  179.     public boolean incrIterations()
  180.     {
  181.         ++_iNumIterations;
  182.         return true;
  183.     }

  184.     /**
  185.      * Return The number of iterations taken
  186.      *
  187.      * @return Number of iterations taken
  188.      */

  189.     public int getNumIterations()
  190.     {
  191.         return _iNumIterations;
  192.     }

  193.     /**
  194.      * Increment the number of Objective Function evaluations
  195.      *
  196.      * @return TRUE - Successfully incremented
  197.      */

  198.     public boolean incrOFCalcs()
  199.     {
  200.         ++_iNumOFCalcs;
  201.         return true;
  202.     }

  203.     /**
  204.      * Retrieve the number of objective function calculations needed
  205.      *
  206.      * @return Number of objective function calculations needed
  207.      */

  208.     public int getNumOFCalcs()
  209.     {
  210.         return _iNumOFCalcs;
  211.     }

  212.     /**
  213.      * Increment the number of Objective Function Derivative evaluations
  214.      *
  215.      * @return TRUE - Successfully incremented
  216.      */

  217.     public boolean incrOFDerivCalcs()
  218.     {
  219.         ++_iNumOFDerivCalcs;
  220.         return true;
  221.     }

  222.     /**
  223.      * Retrieve the number of objective function derivative calculations needed
  224.      *
  225.      * @return Number of objective function derivative calculations needed
  226.      */

  227.     public int getNumOFDerivCalcs()
  228.     {
  229.         return _iNumOFDerivCalcs;
  230.     }

  231.     /**
  232.      * Retrieve the Execution Initialization Output
  233.      *
  234.      * @return Execution Initialization Output
  235.      */

  236.     public org.drip.function.r1tor1solver.ExecutionInitializationOutput getEIOP()
  237.     {
  238.         return _eiop;
  239.     }

  240.     /**
  241.      * Return a string form of the root finder output
  242.      *
  243.      * @return String form of the root finder output
  244.      */

  245.     public java.lang.String displayString()
  246.     {
  247.         java.lang.StringBuffer sb = new java.lang.StringBuffer();

  248.         sb.append (_eiop.displayString());

  249.         sb.append ("\n\tRoot finding Done? " + _bHasRoot + " [" + _dblRootFindingTime + " msec]");

  250.         sb.append ("\n\tRoot: " + _dblRoot);

  251.         sb.append ("\n\tNum Iterations: " + _iNumIterations);

  252.         sb.append ("\n\tNum OF Calculations: " + _iNumOFCalcs);

  253.         sb.append ("\n\tNum OF Derivative Calculations: " + _iNumOFDerivCalcs);

  254.         return sb.toString();
  255.     }
  256. }