CompoundBracketingRegressorSet.java

  1. package org.drip.regression.fixedpointfinder;

  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>CompoundBracketingRegressorSet</i> implements regression run for the Compound Bracketing Fixed Point
  83.  * Search Method. It implements the following 2 compound bracketing schemes: Brent and Zheng.
  84.  *
  85.  * <br><br>
  86.  *  <ul>
  87.  *      <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/ComputationalCore.md">Computational Core Module</a></li>
  88.  *      <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/ComputationSupportLibrary.md">Computation Support</a></li>
  89.  *      <li><b>Project</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/regression/README.md">Regression Engine Core and the Unit Regressors</a></li>
  90.  *      <li><b>Package</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/regression/fixedpointfinder/README.md">Fixed Point Finder Regression Engine</a></li>
  91.  *  </ul>
  92.  * <br><br>
  93.  *
  94.  * @author Lakshmi Krishnamurthy
  95.  */

  96. public class CompoundBracketingRegressorSet implements org.drip.regression.core.RegressorSet {
  97.     private org.drip.function.definition.R1ToR1 _of = null;
  98.     private java.lang.String _strRegressionScenario = "org.drip.math.solver1D.FixedPointFinderCompound";

  99.     private java.util.List<org.drip.regression.core.UnitRegressor> _setRegressors = new
  100.         java.util.ArrayList<org.drip.regression.core.UnitRegressor>();

  101.     public CompoundBracketingRegressorSet()
  102.     {
  103.         _of = new org.drip.function.definition.R1ToR1 (null)
  104.         {
  105.             public double evaluate (
  106.                 final double dblVariate)
  107.                 throws java.lang.Exception
  108.             {
  109.                 if (java.lang.Double.isNaN (dblVariate))
  110.                     throw new java.lang.Exception
  111.                         ("FixedPointFinderRegressorOF.evalTarget => Invalid variate!");

  112.                 /* return java.lang.Math.cos (dblVariate) - dblVariate * dblVariate * dblVariate;

  113.                 return dblVariate * dblVariate * dblVariate - 3. * dblVariate * dblVariate + 2. *
  114.                     dblVariate;

  115.                 return dblVariate * dblVariate * dblVariate + 4. * dblVariate + 4.;

  116.                 return 32. * dblVariate * dblVariate * dblVariate * dblVariate * dblVariate * dblVariate
  117.                     - 48. * dblVariate * dblVariate * dblVariate * dblVariate + 18. * dblVariate *
  118.                         dblVariate - 1.; */

  119.                 return 1. + 3. * dblVariate - 2. * java.lang.Math.sin (dblVariate);
  120.             }

  121.             @Override public double integrate (
  122.                 final double dblBegin,
  123.                 final double dblEnd)
  124.                 throws java.lang.Exception
  125.             {
  126.                 return org.drip.numerical.integration.R1ToR1Integrator.Boole (this, dblBegin, dblEnd);
  127.             }
  128.         };
  129.     }

  130.     @Override public boolean setupRegressors()
  131.     {
  132.         try {
  133.             _setRegressors.add (new org.drip.regression.core.UnitRegressionExecutor ("BrentFixedPointFinder",
  134.                 _strRegressionScenario)
  135.             {
  136.                 org.drip.function.r1tor1solver.FixedPointFinderBrent fpfbBrent = null;
  137.                 org.drip.function.r1tor1solver.FixedPointFinderOutput fpfopBrent = null;

  138.                 @Override public boolean preRegression()
  139.                 {
  140.                     try {
  141.                         fpfbBrent = new org.drip.function.r1tor1solver.FixedPointFinderBrent (0., _of, true);

  142.                         return true;
  143.                     } catch (java.lang.Exception e) {
  144.                         e.printStackTrace();
  145.                     }

  146.                     return false;
  147.                 }

  148.                 @Override public boolean execRegression()
  149.                 {
  150.                     if (null == (fpfopBrent = fpfbBrent.findRoot())) return false;

  151.                     return true;
  152.                 }

  153.                 @Override public boolean postRegression (
  154.                     final org.drip.regression.core.RegressionRunDetail rnvd)
  155.                 {
  156.                     rnvd.set ("FixedPoint", "" + fpfopBrent.getRoot());

  157.                     return true;
  158.                 }
  159.             });

  160.             _setRegressors.add (new org.drip.regression.core.UnitRegressionExecutor ("ZhengFixedPointFinder",
  161.                 _strRegressionScenario)
  162.             {
  163.                 org.drip.function.r1tor1solver.FixedPointFinderZheng fpfbZheng = null;
  164.                 org.drip.function.r1tor1solver.FixedPointFinderOutput fpfopZheng = null;

  165.                 @Override public boolean preRegression()
  166.                 {
  167.                     try {
  168.                         fpfbZheng = new org.drip.function.r1tor1solver.FixedPointFinderZheng (0., _of, true);

  169.                         return true;
  170.                     } catch (java.lang.Exception e) {
  171.                         e.printStackTrace();
  172.                     }

  173.                     return false;
  174.                 }

  175.                 @Override public boolean execRegression()
  176.                 {
  177.                     if (null == (fpfopZheng = fpfbZheng.findRoot())) return false;

  178.                     return true;
  179.                 }

  180.                 @Override public boolean postRegression (
  181.                     final org.drip.regression.core.RegressionRunDetail rnvd)
  182.                 {
  183.                     rnvd.set ("FixedPoint", "" + fpfopZheng.getRoot());

  184.                     return true;
  185.                 }
  186.             });
  187.         } catch (java.lang.Exception e) {
  188.             e.printStackTrace();
  189.         }

  190.         return true;
  191.     }

  192.     @Override public java.util.List<org.drip.regression.core.UnitRegressor> getRegressorSet()
  193.     {
  194.         return _setRegressors;
  195.     }

  196.     @Override public java.lang.String getSetName()
  197.     {
  198.         return _strRegressionScenario;
  199.     }
  200. }