MultiSegmentSequenceBuilder.java

  1. package org.drip.spline.stretch;

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

  80. /**
  81.  * <i>MultiSegmentSequenceBuilder</i> exports Stretch creation/calibration methods to generate customized
  82.  * basis splines, with customized segment behavior using the segment control. It exports the following
  83.  * method of Stretch Creation:
  84.  *
  85.  * <br><br>
  86.  *  <ul>
  87.  *      <li>
  88.  *          Create an uncalibrated Stretch instance over the specified Predictor Ordinate Array using the
  89.  *              specified Basis Spline Parameters for the Segment
  90.  *      </li>
  91.  *      <li>
  92.  *          Create a calibrated Stretch Instance over the specified array of Predictor Ordinates and Response
  93.  *              Values using the specified Basis Splines
  94.  *      </li>
  95.  *      <li>
  96.  *          Create a calibrated Stretch Instance over the specified Predictor Ordinates, Response Values, and
  97.  *              their Constraints, using the specified Segment Builder Parameters
  98.  *      </li>
  99.  *      <li>
  100.  *          Create a Calibrated Stretch Instance from the Array of Predictor Ordinates and a flat Response
  101.  *              Value
  102.  *      </li>
  103.  *      <li>
  104.  *          Create a Regression Spline Instance over the specified array of Predictor Ordinate Knot Points
  105.  *              and the Set of the Points to be Best Fit
  106.  *      </li>
  107.  *  </ul>
  108.  *
  109.  * <br><br>
  110.  *  <ul>
  111.  *      <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/ComputationalCore.md">Computational Core Module</a></li>
  112.  *      <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/SplineBuilderLibrary.md">Spline Builder Library</a></li>
  113.  *      <li><b>Project</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/spline/README.md">Basis Splines and Linear Compounders across a Broad Family of Spline Basis Functions</a></li>
  114.  *      <li><b>Package</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/spline/stretch/README.md">Multi-Segment Sequence Spline Stretch</a></li>
  115.  *  </ul>
  116.  * <br><br>
  117.  *
  118.  * @author Lakshmi Krishnamurthy
  119.  */

  120. public class MultiSegmentSequenceBuilder {

  121.     /**
  122.      * Polynomial Spline
  123.      */

  124.     public static final java.lang.String BASIS_SPLINE_POLYNOMIAL = "Polynomial";

  125.     /**
  126.      * Bernstein Polynomial Spline
  127.      */

  128.     public static final java.lang.String BASIS_SPLINE_BERNSTEIN_POLYNOMIAL = "BernsteinPolynomial";

  129.     /**
  130.      * Hyperbolic Tension Spline
  131.      */

  132.     public static final java.lang.String BASIS_SPLINE_HYPERBOLIC_TENSION = "HyperbolicTension";

  133.     /**
  134.      * Exponential Tension Spline
  135.      */

  136.     public static final java.lang.String BASIS_SPLINE_EXPONENTIAL_TENSION = "ExponentialTension";

  137.     /**
  138.      * Kaklis Pandelis Spline
  139.      */

  140.     public static final java.lang.String BASIS_SPLINE_KAKLIS_PANDELIS = "KaklisPandelis";

  141.     /**
  142.      * Exponential Rational Basis Spline
  143.      */

  144.     public static final java.lang.String BASIS_SPLINE_EXPONENTIAL_RATIONAL = "ExponentialRational";

  145.     /**
  146.      * Exponential Mixture Basis Spline
  147.      */

  148.     public static final java.lang.String BASIS_SPLINE_EXPONENTIAL_MIXTURE = "ExponentialMixture";

  149.     /**
  150.      * Koch-Lyche-Kvasov Exponential Tension Spline
  151.      */

  152.     public static final java.lang.String BASIS_SPLINE_KLK_EXPONENTIAL_TENSION = "KLKExponentialTension";

  153.     /**
  154.      * Koch-Lyche-Kvasov Hyperbolic Tension Spline
  155.      */

  156.     public static final java.lang.String BASIS_SPLINE_KLK_HYPERBOLIC_TENSION = "KLKHyperbolicTension";

  157.     /**
  158.      * Koch-Lyche-Kvasov Rational Linear Tension Spline
  159.      */

  160.     public static final java.lang.String BASIS_SPLINE_KLK_RATIONAL_LINEAR_TENSION =
  161.         "KLKRationalLinearTension";

  162.     /**
  163.      * Koch-Lyche-Kvasov Rational Quadratic Tension Spline
  164.      */

  165.     public static final java.lang.String BASIS_SPLINE_KLK_RATIONAL_QUADRATIC_TENSION =
  166.         "KLKRationalQuadraticTension";

  167.     /**
  168.      * Create an uncalibrated Stretch instance over the specified Predictor Ordinate Array using the
  169.      *  specified Basis Spline Parameters for the Segment.
  170.      *
  171.      * @param adblPredictorOrdinate Predictor Ordinate Array
  172.      * @param aSCBC Array of Segment Builder Parameters
  173.      *
  174.      * @return Stretch instance
  175.      */

  176.     public static final org.drip.spline.segment.LatentStateResponseModel[] CreateSegmentSet (
  177.         final double[] adblPredictorOrdinate,
  178.         final org.drip.spline.params.SegmentCustomBuilderControl[] aSCBC)
  179.     {
  180.         if (null == adblPredictorOrdinate || null == aSCBC) return null;

  181.         int iNumSegment = adblPredictorOrdinate.length - 1;

  182.         if (1 > iNumSegment || iNumSegment != aSCBC.length) return null;

  183.         org.drip.spline.segment.LatentStateResponseModel[] aCS = new
  184.             org.drip.spline.segment.LatentStateResponseModel[iNumSegment];

  185.         for (int i = 0; i < iNumSegment; ++i) {
  186.             if (null == aSCBC[i]) return null;

  187.             java.lang.String strBasisSpline = aSCBC[i].basisSpline();

  188.             if (null == strBasisSpline || (!BASIS_SPLINE_POLYNOMIAL.equalsIgnoreCase (strBasisSpline) &&
  189.                 !BASIS_SPLINE_BERNSTEIN_POLYNOMIAL.equalsIgnoreCase (strBasisSpline) &&
  190.                     !BASIS_SPLINE_HYPERBOLIC_TENSION.equalsIgnoreCase (strBasisSpline) &&
  191.                         !BASIS_SPLINE_EXPONENTIAL_TENSION.equalsIgnoreCase (strBasisSpline) &&
  192.                             !BASIS_SPLINE_KAKLIS_PANDELIS.equalsIgnoreCase (strBasisSpline) &&
  193.                                 !BASIS_SPLINE_EXPONENTIAL_RATIONAL.equalsIgnoreCase (strBasisSpline) &&
  194.                                     !BASIS_SPLINE_EXPONENTIAL_MIXTURE.equalsIgnoreCase (strBasisSpline) &&
  195.                                         !BASIS_SPLINE_KLK_EXPONENTIAL_TENSION.equalsIgnoreCase
  196.                                             (strBasisSpline) &&
  197.                                                 !BASIS_SPLINE_KLK_HYPERBOLIC_TENSION.equalsIgnoreCase
  198.                                                     (strBasisSpline) &&
  199.                                                         !BASIS_SPLINE_KLK_RATIONAL_LINEAR_TENSION.equalsIgnoreCase
  200.                 (strBasisSpline) && !BASIS_SPLINE_KLK_RATIONAL_QUADRATIC_TENSION.equalsIgnoreCase
  201.                     (strBasisSpline)))
  202.                 return null;

  203.             if (BASIS_SPLINE_POLYNOMIAL.equalsIgnoreCase (strBasisSpline)) {
  204.                 if (null == (aCS[i] = org.drip.spline.segment.LatentStateResponseModel.Create
  205.                     (adblPredictorOrdinate[i], adblPredictorOrdinate[i + 1],
  206.                         org.drip.spline.basis.FunctionSetBuilder.PolynomialBasisSet
  207.                             ((org.drip.spline.basis.PolynomialFunctionSetParams) aSCBC[i].basisSetParams()),
  208.                                 aSCBC[i].shapeController(), aSCBC[i].inelasticParams())))
  209.                     return null;
  210.             } else if (BASIS_SPLINE_BERNSTEIN_POLYNOMIAL.equalsIgnoreCase (strBasisSpline)) {
  211.                 if (null == (aCS[i] = org.drip.spline.segment.LatentStateResponseModel.Create
  212.                     (adblPredictorOrdinate[i], adblPredictorOrdinate[i + 1],
  213.                         org.drip.spline.basis.FunctionSetBuilder.BernsteinPolynomialBasisSet
  214.                             ((org.drip.spline.basis.PolynomialFunctionSetParams) aSCBC[i].basisSetParams()),
  215.                                 aSCBC[i].shapeController(), aSCBC[i].inelasticParams())))
  216.                     return null;
  217.             } else if (BASIS_SPLINE_HYPERBOLIC_TENSION.equalsIgnoreCase (strBasisSpline)) {
  218.                 if (null == (aCS[i] = org.drip.spline.segment.LatentStateResponseModel.Create
  219.                     (adblPredictorOrdinate[i], adblPredictorOrdinate[i + 1],
  220.                         org.drip.spline.basis.FunctionSetBuilder.HyperbolicTensionBasisSet
  221.                             ((org.drip.spline.basis.ExponentialTensionSetParams) aSCBC[i].basisSetParams()),
  222.                                 aSCBC[i].shapeController(), aSCBC[i].inelasticParams())))
  223.                     return null;
  224.             } else if (BASIS_SPLINE_EXPONENTIAL_TENSION.equalsIgnoreCase (strBasisSpline)) {
  225.                 if (null == (aCS[i] = org.drip.spline.segment.LatentStateResponseModel.Create
  226.                     (adblPredictorOrdinate[i], adblPredictorOrdinate[i + 1],
  227.                         org.drip.spline.basis.FunctionSetBuilder.ExponentialTensionBasisSet
  228.                             ((org.drip.spline.basis.ExponentialTensionSetParams) aSCBC[i].basisSetParams()),
  229.                                 aSCBC[i].shapeController(), aSCBC[i].inelasticParams())))
  230.                     return null;
  231.             } else if (BASIS_SPLINE_KAKLIS_PANDELIS.equalsIgnoreCase (strBasisSpline)) {
  232.                 if (null == (aCS[i] = org.drip.spline.segment.LatentStateResponseModel.Create
  233.                     (adblPredictorOrdinate[i], adblPredictorOrdinate[i + 1],
  234.                         org.drip.spline.basis.FunctionSetBuilder.KaklisPandelisBasisSet
  235.                             ((org.drip.spline.basis.KaklisPandelisSetParams) aSCBC[i].basisSetParams()),
  236.                                 aSCBC[i].shapeController(), aSCBC[i].inelasticParams())))
  237.                     return null;
  238.             } else if (BASIS_SPLINE_EXPONENTIAL_RATIONAL.equalsIgnoreCase (strBasisSpline)) {
  239.                 if (null == (aCS[i] = org.drip.spline.segment.LatentStateResponseModel.Create
  240.                     (adblPredictorOrdinate[i], adblPredictorOrdinate[i + 1],
  241.                         org.drip.spline.basis.FunctionSetBuilder.ExponentialRationalBasisSet
  242.                             ((org.drip.spline.basis.ExponentialRationalSetParams) aSCBC[i].basisSetParams()),
  243.                                 aSCBC[i].shapeController(), aSCBC[i].inelasticParams())))
  244.                     return null;
  245.             } else if (BASIS_SPLINE_EXPONENTIAL_MIXTURE.equalsIgnoreCase (strBasisSpline)) {
  246.                 if (null == (aCS[i] = org.drip.spline.segment.LatentStateResponseModel.Create
  247.                     (adblPredictorOrdinate[i], adblPredictorOrdinate[i + 1],
  248.                         org.drip.spline.basis.FunctionSetBuilder.ExponentialMixtureBasisSet
  249.                             ((org.drip.spline.basis.ExponentialMixtureSetParams) aSCBC[i].basisSetParams()),
  250.                                 aSCBC[i].shapeController(), aSCBC[i].inelasticParams())))
  251.                     return null;
  252.             } else if (BASIS_SPLINE_KLK_EXPONENTIAL_TENSION.equalsIgnoreCase (strBasisSpline)) {
  253.                 if (null == (aCS[i] = org.drip.spline.segment.LatentStateResponseModel.Create
  254.                     (adblPredictorOrdinate[i], adblPredictorOrdinate[i + 1],
  255.                         org.drip.spline.tension.KochLycheKvasovFamily.FromExponentialPrimitive
  256.                             ((org.drip.spline.basis.ExponentialTensionSetParams) aSCBC[i].basisSetParams()),
  257.                                 aSCBC[i].shapeController(), aSCBC[i].inelasticParams())))
  258.                     return null;
  259.             } else if (BASIS_SPLINE_KLK_HYPERBOLIC_TENSION.equalsIgnoreCase (strBasisSpline)) {
  260.                 if (null == (aCS[i] = org.drip.spline.segment.LatentStateResponseModel.Create
  261.                     (adblPredictorOrdinate[i], adblPredictorOrdinate[i + 1],
  262.                         org.drip.spline.tension.KochLycheKvasovFamily.FromHyperbolicPrimitive
  263.                             ((org.drip.spline.basis.ExponentialTensionSetParams) aSCBC[i].basisSetParams()),
  264.                                 aSCBC[i].shapeController(), aSCBC[i].inelasticParams())))
  265.                     return null;
  266.             } else if (BASIS_SPLINE_KLK_RATIONAL_LINEAR_TENSION.equalsIgnoreCase (strBasisSpline)) {
  267.                 if (null == (aCS[i] = org.drip.spline.segment.LatentStateResponseModel.Create
  268.                     (adblPredictorOrdinate[i], adblPredictorOrdinate[i + 1],
  269.                         org.drip.spline.tension.KochLycheKvasovFamily.FromRationalLinearPrimitive
  270.                             ((org.drip.spline.basis.ExponentialTensionSetParams) aSCBC[i].basisSetParams()),
  271.                                 aSCBC[i].shapeController(), aSCBC[i].inelasticParams())))
  272.                     return null;
  273.             } else if (BASIS_SPLINE_KLK_RATIONAL_QUADRATIC_TENSION.equalsIgnoreCase (strBasisSpline)) {
  274.                 if (null == (aCS[i] = org.drip.spline.segment.LatentStateResponseModel.Create
  275.                     (adblPredictorOrdinate[i], adblPredictorOrdinate[i + 1],
  276.                         org.drip.spline.tension.KochLycheKvasovFamily.FromRationalQuadraticPrimitive
  277.                             ((org.drip.spline.basis.ExponentialTensionSetParams) aSCBC[i].basisSetParams()),
  278.                                 aSCBC[i].shapeController(), aSCBC[i].inelasticParams())))
  279.                     return null;
  280.             }
  281.         }

  282.         return aCS;
  283.     }

  284.     /**
  285.      * Create an uncalibrated Stretch instance over the specified Predictor Ordinate Array using the specified
  286.      *  Basis Spline Parameters for the Segment.
  287.      *
  288.      * @param strName Name of the Stretch
  289.      * @param adblPredictorOrdinate Predictor Ordinate Array
  290.      * @param aSCBC Array of Segment Builder Parameters
  291.      *
  292.      * @return Stretch instance
  293.      */

  294.     public static final org.drip.spline.stretch.MultiSegmentSequence CreateUncalibratedStretchEstimator (
  295.         final java.lang.String strName,
  296.         final double[] adblPredictorOrdinate,
  297.         final org.drip.spline.params.SegmentCustomBuilderControl[] aSCBC)
  298.     {
  299.         org.drip.spline.segment.LatentStateResponseModel[] latentStateResponseModelArray = CreateSegmentSet (
  300.             adblPredictorOrdinate,
  301.             aSCBC
  302.         );

  303.         try {
  304.             return null == latentStateResponseModelArray ? null :
  305.             new org.drip.spline.stretch.CalibratableMultiSegmentSequence (
  306.                 strName,
  307.                 latentStateResponseModelArray,
  308.                 aSCBC
  309.             );
  310.         } catch (java.lang.Exception e) {
  311.             e.printStackTrace();
  312.         }

  313.         return null;
  314.     }

  315.     /**
  316.      * Create a calibrated Stretch Instance over the specified array of Predictor Ordinates and Response
  317.      *  Values using the specified Basis Splines.
  318.      *
  319.      * @param strName Name of the Stretch
  320.      * @param adblPredictorOrdinate Predictor Ordinate Array
  321.      * @param adblResponseValue Response Value Array
  322.      * @param aSCBC Array of Segment Builder Parameters
  323.      * @param rbfr Stretch Fitness Weighted Response
  324.      * @param bs The Calibration Boundary Condition
  325.      * @param iCalibrationDetail The Calibration Detail
  326.      *
  327.      * @return Stretch instance
  328.      */

  329.     public static final org.drip.spline.stretch.MultiSegmentSequence CreateCalibratedStretchEstimator (
  330.         final java.lang.String strName,
  331.         final double[] adblPredictorOrdinate,
  332.         final double[] adblResponseValue,
  333.         final org.drip.spline.params.SegmentCustomBuilderControl[] aSCBC,
  334.         final org.drip.spline.params.StretchBestFitResponse rbfr,
  335.         final org.drip.spline.stretch.BoundarySettings bs,
  336.         final int iCalibrationDetail)
  337.     {
  338.         org.drip.spline.stretch.MultiSegmentSequence mss = CreateUncalibratedStretchEstimator (strName,
  339.             adblPredictorOrdinate, aSCBC);

  340.         if (null == mss || null == adblResponseValue) return null;

  341.         int iNumRightNode = adblResponseValue.length - 1;
  342.         double[] adblResponseValueRight = new double[iNumRightNode];

  343.         if (0 == iNumRightNode) return null;

  344.         for (int i = 0; i < iNumRightNode; ++i)
  345.             adblResponseValueRight[i] = adblResponseValue[i + 1];

  346.         return mss.setup (adblResponseValue[0], adblResponseValueRight, rbfr, bs, iCalibrationDetail) ? mss :
  347.             null;
  348.     }

  349.     /**
  350.      * Create a calibrated Stretch Instance over the specified array of Predictor Ordinates and Response
  351.      *  Values using the specified Basis Splines.
  352.      *
  353.      * @param strName Name of the Stretch
  354.      * @param aiPredictorOrdinate Predictor Ordinate Array
  355.      * @param adblResponseValue Response Value Array
  356.      * @param aSCBC Array of Segment Builder Parameters
  357.      * @param rbfr Stretch Fitness Weighted Response
  358.      * @param bs The Calibration Boundary Condition
  359.      * @param iCalibrationDetail The Calibration Detail
  360.      *
  361.      * @return Stretch instance
  362.      */

  363.     public static final org.drip.spline.stretch.MultiSegmentSequence CreateCalibratedStretchEstimator (
  364.         final java.lang.String strName,
  365.         final int[] aiPredictorOrdinate,
  366.         final double[] adblResponseValue,
  367.         final org.drip.spline.params.SegmentCustomBuilderControl[] aSCBC,
  368.         final org.drip.spline.params.StretchBestFitResponse rbfr,
  369.         final org.drip.spline.stretch.BoundarySettings bs,
  370.         final int iCalibrationDetail)
  371.     {
  372.         if (null == aiPredictorOrdinate) return null;

  373.         int iNumPredictorOrdinate = aiPredictorOrdinate.length;
  374.         double[] adblPredictorOrdinate = new double[iNumPredictorOrdinate];

  375.         if (0 == iNumPredictorOrdinate) return null;

  376.         for (int i = 0; i < iNumPredictorOrdinate; ++i)
  377.             adblPredictorOrdinate[i] = aiPredictorOrdinate[i];

  378.         return CreateCalibratedStretchEstimator (strName, adblPredictorOrdinate, adblResponseValue, aSCBC,
  379.             rbfr, bs, iCalibrationDetail);
  380.     }

  381.     /**
  382.      * Create a calibrated Stretch Instance over the specified Predictor Ordinates, Response Values, and their
  383.      *  Constraints, using the specified Segment Builder Parameters.
  384.      *
  385.      * @param strName Name of the Stretch
  386.      * @param adblPredictorOrdinate Predictor Ordinate Array
  387.      * @param dblStretchLeftResponseValue Left-most Y Point
  388.      * @param aSRVC Array of Response Value Constraints - One per Segment
  389.      * @param aSCBC Array of Segment Builder Parameters - One per Segment
  390.      * @param rbfr Stretch Fitness Weighted Response
  391.      * @param bs The Calibration Boundary Condition
  392.      * @param iCalibrationDetail The Calibration Detail
  393.      *
  394.      * @return Stretch Instance
  395.      */

  396.     public static final org.drip.spline.stretch.MultiSegmentSequence CreateCalibratedStretchEstimator (
  397.         final java.lang.String strName,
  398.         final double[] adblPredictorOrdinate,
  399.         final double dblStretchLeftResponseValue,
  400.         final org.drip.spline.params.SegmentResponseValueConstraint[] aSRVC,
  401.         final org.drip.spline.params.SegmentCustomBuilderControl[] aSCBC,
  402.         final org.drip.spline.params.StretchBestFitResponse rbfr,
  403.         final org.drip.spline.stretch.BoundarySettings bs,
  404.         final int iCalibrationDetail)
  405.     {
  406.         org.drip.spline.stretch.MultiSegmentSequence mss = CreateUncalibratedStretchEstimator (strName,
  407.             adblPredictorOrdinate, aSCBC);

  408.         return null == mss ? null : mss.setup (dblStretchLeftResponseValue, aSRVC, rbfr, bs,
  409.             iCalibrationDetail) ? mss : null;
  410.     }

  411.     /**
  412.      * Create a calibrated Stretch Instance over the specified Predictor Ordinates and the Response Value
  413.      *  Constraints, with the Segment Builder Parameters.
  414.      *
  415.      * @param strName Name of the Stretch
  416.      * @param adblPredictorOrdinate Predictor Ordinate Array
  417.      * @param srvcStretchLeft Stretch Left Constraint
  418.      * @param aSRVC Array of Segment Constraints - One per Segment
  419.      * @param aSCBC Array of Segment Builder Parameters - One per Segment
  420.      * @param sbfr Stretch Fitness Weighted Response
  421.      * @param bs The Calibration Boundary Condition
  422.      * @param iCalibrationDetail The Calibration Detail
  423.      *
  424.      * @return Stretch Instance
  425.      */

  426.     public static final org.drip.spline.stretch.MultiSegmentSequence CreateCalibratedStretchEstimator (
  427.         final java.lang.String strName,
  428.         final double[] adblPredictorOrdinate,
  429.         final org.drip.spline.params.SegmentResponseValueConstraint srvcStretchLeft,
  430.         final org.drip.spline.params.SegmentResponseValueConstraint[] aSRVC,
  431.         final org.drip.spline.params.SegmentCustomBuilderControl[] aSCBC,
  432.         final org.drip.spline.params.StretchBestFitResponse sbfr,
  433.         final org.drip.spline.stretch.BoundarySettings bs,
  434.         final int iCalibrationDetail)
  435.     {
  436.         org.drip.spline.stretch.MultiSegmentSequence mss = CreateUncalibratedStretchEstimator (strName,
  437.             adblPredictorOrdinate, aSCBC);

  438.         return null == mss ? null : mss.setup (srvcStretchLeft, aSRVC, sbfr, bs, iCalibrationDetail) ? mss :
  439.             null;
  440.     }

  441.     /**
  442.      * Create a Calibrated Stretch Instance from the Array of Predictor Ordinates and a flat Response Value
  443.      *
  444.      * @param strName Name of the Stretch
  445.      * @param adblPredictorOrdinate Predictor Ordinate Array
  446.      * @param dblResponseValue Response Value
  447.      * @param scbc Segment Builder Parameters - One per Segment
  448.      * @param sbfr Stretch Fitness Weighted Response
  449.      * @param bs The Calibration Boundary Condition
  450.      * @param iCalibrationDetail The Calibration Detail
  451.      *
  452.      * @return Stretch Instance
  453.      */

  454.     public static final org.drip.spline.stretch.MultiSegmentSequence CreateCalibratedStretchEstimator (
  455.         final java.lang.String strName,
  456.         final double[] adblPredictorOrdinate,
  457.         final double dblResponseValue,
  458.         final org.drip.spline.params.SegmentCustomBuilderControl scbc,
  459.         final org.drip.spline.params.StretchBestFitResponse sbfr,
  460.         final org.drip.spline.stretch.BoundarySettings bs,
  461.         final int iCalibrationDetail)
  462.     {
  463.         if (!org.drip.numerical.common.NumberUtil.IsValid (dblResponseValue) || null == adblPredictorOrdinate ||
  464.             null == scbc)
  465.             return null;

  466.         int iNumPredictorOrdinate = adblPredictorOrdinate.length;

  467.         if (1 >= iNumPredictorOrdinate) return null;

  468.         double[] adblResponseValue = new double[iNumPredictorOrdinate];
  469.         org.drip.spline.params.SegmentCustomBuilderControl[] aSCBC = new
  470.             org.drip.spline.params.SegmentCustomBuilderControl[iNumPredictorOrdinate - 1];

  471.         for (int i = 0; i < iNumPredictorOrdinate; ++i) {
  472.             adblResponseValue[i] = dblResponseValue;

  473.             if (0 != i) aSCBC[i - 1] = scbc;
  474.         }

  475.         return CreateCalibratedStretchEstimator (strName, adblPredictorOrdinate, adblResponseValue, aSCBC,
  476.             sbfr, bs, iCalibrationDetail);
  477.     }

  478.     /**
  479.      * Create a Regression Spline Instance over the specified array of Predictor Ordinate Knot Points and the
  480.      *  Set of the Points to be Best Fit.
  481.      *
  482.      * @param strName Name of the Stretch
  483.      * @param adblKnotPredictorOrdinate Array of the Predictor Ordinate Knots
  484.      * @param aSCBC Array of Segment Builder Parameters
  485.      * @param sbfr Stretch Fitness Weighted Response
  486.      * @param bs The Calibration Boundary Condition
  487.      * @param iCalibrationDetail The Calibration Detail
  488.      *
  489.      * @return Stretch instance
  490.      */

  491.     public static final org.drip.spline.stretch.MultiSegmentSequence CreateRegressionSplineEstimator (
  492.         final java.lang.String strName,
  493.         final double[] adblKnotPredictorOrdinate,
  494.         final org.drip.spline.params.SegmentCustomBuilderControl[] aSCBC,
  495.         final org.drip.spline.params.StretchBestFitResponse sbfr,
  496.         final org.drip.spline.stretch.BoundarySettings bs,
  497.         final int iCalibrationDetail)
  498.     {
  499.         org.drip.spline.stretch.MultiSegmentSequence mss = CreateUncalibratedStretchEstimator (strName,
  500.             adblKnotPredictorOrdinate, aSCBC);

  501.         if (null == mss) return null;

  502.         return mss.setup (null, null, sbfr, bs, iCalibrationDetail) ? mss : null;
  503.     }
  504. }