LocalControlStretchBuilder.java

  1. package org.drip.spline.pchip;

  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>LocalControlStretchBuilder</i> exports Stretch creation/calibration methods to generate customized
  82.  * basis splines, with customized segment behavior using the segment control. It provides the following
  83.  * local-control functionality:
  84.  *
  85.  * <br><br>
  86.  *  <ul>
  87.  *      <li>
  88.  *          Create a Stretch off of Hermite Splines from the specified the Predictor Ordinates, the Response
  89.  *              Values, the Custom Slopes, and the Segment Builder Parameters
  90.  *      </li>
  91.  *      <li>
  92.  *          Create Hermite/Bessel C1 Cubic Spline Stretch
  93.  *      </li>
  94.  *      <li>
  95.  *          Create Hyman (1983) Monotone Preserving Stretch
  96.  *      </li>
  97.  *      <li>
  98.  *          Create Hyman (1989) enhancement to the Hyman (1983) Monotone Preserving Stretch
  99.  *      </li>
  100.  *      <li>
  101.  *          Create the Harmonic Monotone Preserving Stretch
  102.  *      </li>
  103.  *      <li>
  104.  *          Create the Van Leer Limiter Stretch
  105.  *      </li>
  106.  *      <li>
  107.  *          Create the Huynh Le Floch Limiter Stretch
  108.  *      </li>
  109.  *      <li>
  110.  *          Generate the local control C1 Slope using the Akima Cubic Algorithm
  111.  *      </li>
  112.  *      <li>
  113.  *          Generate the local control C1 Slope using the Hagan-West Monotone Convex Algorithm
  114.  *      </li>
  115.  *  </ul>
  116.  *
  117.  * <br><br>
  118.  *  <ul>
  119.  *      <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/ComputationalCore.md">Computational Core Module</a></li>
  120.  *      <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/SplineBuilderLibrary.md">Spline Builder Library</a></li>
  121.  *      <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>
  122.  *      <li><b>Package</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/spline/pchip/README.md">Monotone Convex Themed PCHIP Splines</a></li>
  123.  *  </ul>
  124.  * <br><br>
  125.  *
  126.  * @author Lakshmi Krishnamurthy
  127.  */

  128. public class LocalControlStretchBuilder {

  129.     /**
  130.      * Create a Stretch off of Hermite Splines from the specified the Predictor Ordinates, the Response
  131.      *  Values, the Custom Slopes, and the Segment Builder Parameters.
  132.      *
  133.      * @param strName Stretch Name
  134.      * @param adblPredictorOrdinate Array of Predictor Ordinates
  135.      * @param adblResponseValue Array of Response Values
  136.      * @param adblCustomSlope Array of Custom Slopes
  137.      * @param aSCBC Array of Segment Builder Parameters
  138.      * @param sbfr Stretch Fitness Weighted Response
  139.      * @param iSetupMode Calibration Set up Mode NATURAL | FINANCIAL | FLOATING | NOTAKNOT
  140.      *
  141.      * @return The Instance of the Hermite Spline Stretch
  142.      */

  143.     public static final org.drip.spline.stretch.MultiSegmentSequence CustomSlopeHermiteSpline (
  144.         final java.lang.String strName,
  145.         final double[] adblPredictorOrdinate,
  146.         final double[] adblResponseValue,
  147.         final double[] adblCustomSlope,
  148.         final org.drip.spline.params.SegmentCustomBuilderControl[] aSCBC,
  149.         final org.drip.spline.params.StretchBestFitResponse sbfr,
  150.         final int iSetupMode)
  151.     {
  152.         org.drip.spline.stretch.MultiSegmentSequence msr =
  153.             org.drip.spline.stretch.MultiSegmentSequenceBuilder.CreateUncalibratedStretchEstimator (strName,
  154.                 adblPredictorOrdinate, aSCBC);

  155.         if (null == msr || null == adblResponseValue || null == adblCustomSlope) return null;

  156.         int iNumResponseValue = adblResponseValue.length;
  157.         org.drip.spline.params.SegmentPredictorResponseDerivative[] aSPRDLeft = new
  158.             org.drip.spline.params.SegmentPredictorResponseDerivative[iNumResponseValue - 1];
  159.         org.drip.spline.params.SegmentPredictorResponseDerivative[] aSPRDRight = new
  160.             org.drip.spline.params.SegmentPredictorResponseDerivative[iNumResponseValue - 1];

  161.         if (1 >= iNumResponseValue || adblPredictorOrdinate.length != iNumResponseValue ||
  162.             adblCustomSlope.length != iNumResponseValue)
  163.             return null;

  164.         for (int i = 0; i < iNumResponseValue; ++i) {
  165.             org.drip.spline.params.SegmentPredictorResponseDerivative sprd = null;

  166.             try {
  167.                 sprd = new org.drip.spline.params.SegmentPredictorResponseDerivative (adblResponseValue[i],
  168.                     new double[] {adblCustomSlope[i]});
  169.             } catch (java.lang.Exception e) {
  170.                 e.printStackTrace();

  171.                 return null;
  172.             }

  173.             if (0 == i)
  174.                 aSPRDLeft[i] = sprd;
  175.             else if (iNumResponseValue - 1 == i)
  176.                 aSPRDRight[i - 1] = sprd;
  177.             else {
  178.                 aSPRDLeft[i] = sprd;
  179.                 aSPRDRight[i - 1] = sprd;
  180.             }
  181.         }

  182.         return msr.setupHermite (aSPRDLeft, aSPRDRight, null, sbfr, iSetupMode) ? msr : null;
  183.     }

  184.     /**
  185.      * Create a Stretch off of Hermite Splines from the specified the Predictor Ordinates, the Response
  186.      *  Values, the Custom Slopes, and the Segment Builder Parameters.
  187.      *
  188.      * @param strName Stretch Name
  189.      * @param aiPredictorOrdinate Array of Predictor Ordinates
  190.      * @param adblResponseValue Array of Response Values
  191.      * @param adblCustomSlope Array of Custom Slopes
  192.      * @param aSCBC Array of Segment Builder Parameters
  193.      * @param sbfr Stretch Fitness Weighted Response
  194.      * @param iSetupMode Calibration Set up Mode NATURAL | FINANCIAL | FLOATING | NOTAKNOT
  195.      *
  196.      * @return The Instance of the Hermite Spline Stretch
  197.      */

  198.     public static final org.drip.spline.stretch.MultiSegmentSequence CustomSlopeHermiteSpline (
  199.         final java.lang.String strName,
  200.         final int[] aiPredictorOrdinate,
  201.         final double[] adblResponseValue,
  202.         final double[] adblCustomSlope,
  203.         final org.drip.spline.params.SegmentCustomBuilderControl[] aSCBC,
  204.         final org.drip.spline.params.StretchBestFitResponse sbfr,
  205.         final int iSetupMode)
  206.     {
  207.         if (null == aiPredictorOrdinate) return null;

  208.         int iNumPredictorOrdinate = aiPredictorOrdinate.length;
  209.         double[] adblPredictorOrdinate = new double[iNumPredictorOrdinate];

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

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

  213.         return CustomSlopeHermiteSpline (strName, adblPredictorOrdinate, adblResponseValue, adblCustomSlope,
  214.             aSCBC, sbfr, iSetupMode);
  215.     }

  216.     /**
  217.      * Create Hermite/Bessel C1 Cubic Spline Stretch
  218.      *
  219.      * @param strName Stretch Name
  220.      * @param adblPredictorOrdinate Array of Predictor Ordinates
  221.      * @param adblResponseValue Array of Response Values
  222.      * @param aSCBC Array of Segment Builder Parameters
  223.      * @param sbfr Stretch Fitness Weighted Response
  224.      * @param iSetupMode Segment Setup Mode
  225.      * @param bEliminateSpuriousExtrema TRUE - Eliminate Spurious Extrema
  226.      * @param bApplyMonotoneFilter TRUE - Apply Monotone Filter
  227.      *
  228.      * @return Hermite/Bessel C1 Cubic Spline Stretch
  229.      */

  230.     public static final org.drip.spline.stretch.MultiSegmentSequence CreateBesselCubicSplineStretch (
  231.         final java.lang.String strName,
  232.         final double[] adblPredictorOrdinate,
  233.         final double[] adblResponseValue,
  234.         final org.drip.spline.params.SegmentCustomBuilderControl[] aSCBC,
  235.         final org.drip.spline.params.StretchBestFitResponse sbfr,
  236.         final int iSetupMode,
  237.         final boolean bEliminateSpuriousExtrema,
  238.         final boolean bApplyMonotoneFilter)
  239.     {
  240.         org.drip.spline.pchip.LocalMonotoneCkGenerator lmcg =
  241.             org.drip.spline.pchip.LocalMonotoneCkGenerator.Create (adblPredictorOrdinate, adblResponseValue,
  242.                 org.drip.spline.pchip.LocalMonotoneCkGenerator.C1_BESSEL, bEliminateSpuriousExtrema,
  243.                     bApplyMonotoneFilter);

  244.         return null == lmcg ? null : CustomSlopeHermiteSpline (strName, adblPredictorOrdinate,
  245.             adblResponseValue, lmcg.C1(), aSCBC, sbfr, iSetupMode);
  246.     }

  247.     /**
  248.      * Create Hyman (1983) Monotone Preserving Stretch. The reference is:
  249.      *
  250.      *  Hyman (1983) Accurate Monotonicity Preserving Cubic Interpolation -
  251.      *      SIAM J on Numerical Analysis 4 (4), 645-654.
  252.      *
  253.      * @param strName Stretch Name
  254.      * @param adblPredictorOrdinate Array of Predictor Ordinates
  255.      * @param adblResponseValue Array of Response Values
  256.      * @param aSCBC Array of Segment Builder Parameters
  257.      * @param sbfr Stretch Fitness Weighted Response
  258.      * @param iSetupMode Segment Setup Mode
  259.      * @param bEliminateSpuriousExtrema TRUE - Eliminate Spurious Extrema
  260.      * @param bApplyMonotoneFilter TRUE - Apply Monotone Filter
  261.      *
  262.      * @return Hyman (1983) Monotone Preserving Stretch
  263.      */

  264.     public static final org.drip.spline.stretch.MultiSegmentSequence CreateHyman83MonotoneStretch (
  265.         final java.lang.String strName,
  266.         final double[] adblPredictorOrdinate,
  267.         final double[] adblResponseValue,
  268.         final org.drip.spline.params.SegmentCustomBuilderControl[] aSCBC,
  269.         final org.drip.spline.params.StretchBestFitResponse sbfr,
  270.         final int iSetupMode,
  271.         final boolean bEliminateSpuriousExtrema,
  272.         final boolean bApplyMonotoneFilter)
  273.     {
  274.         org.drip.spline.pchip.LocalMonotoneCkGenerator lmcg =
  275.             org.drip.spline.pchip.LocalMonotoneCkGenerator.Create (adblPredictorOrdinate, adblResponseValue,
  276.                 org.drip.spline.pchip.LocalMonotoneCkGenerator.C1_HYMAN83, bEliminateSpuriousExtrema,
  277.                     bApplyMonotoneFilter);

  278.         return null == lmcg ? null : CustomSlopeHermiteSpline (strName, adblPredictorOrdinate,
  279.             adblResponseValue, lmcg.C1(), aSCBC, sbfr, iSetupMode);
  280.     }

  281.     /**
  282.      * Create Hyman (1989) enhancement to the Hyman (1983) Monotone Preserving Stretch. The reference is:
  283.      *
  284.      *  Doherty, Edelman, and Hyman (1989) Non-negative, monotonic, or convexity preserving cubic and quintic
  285.      *      Hermite interpolation - Mathematics of Computation 52 (186), 471-494.
  286.      *
  287.      * @param strName Stretch Name
  288.      * @param adblPredictorOrdinate Array of Predictor Ordinates
  289.      * @param adblResponseValue Array of Response Values
  290.      * @param aSCBC Array of Segment Builder Parameters
  291.      * @param sbfr Stretch Fitness Weighted Response
  292.      * @param iSetupMode Segment Setup Mode
  293.      * @param bEliminateSpuriousExtrema TRUE - Eliminate Spurious Extrema
  294.      * @param bApplyMonotoneFilter TRUE - Apply Monotone Filter
  295.      *
  296.      * @return Hyman (1989) Monotone Preserving Stretch
  297.      */

  298.     public static final org.drip.spline.stretch.MultiSegmentSequence CreateHyman89MonotoneStretch (
  299.         final java.lang.String strName,
  300.         final double[] adblPredictorOrdinate,
  301.         final double[] adblResponseValue,
  302.         final org.drip.spline.params.SegmentCustomBuilderControl[] aSCBC,
  303.         final org.drip.spline.params.StretchBestFitResponse sbfr,
  304.         final int iSetupMode,
  305.         final boolean bEliminateSpuriousExtrema,
  306.         final boolean bApplyMonotoneFilter)
  307.     {
  308.         org.drip.spline.pchip.LocalMonotoneCkGenerator lmcg =
  309.             org.drip.spline.pchip.LocalMonotoneCkGenerator.Create (adblPredictorOrdinate, adblResponseValue,
  310.                 org.drip.spline.pchip.LocalMonotoneCkGenerator.C1_HYMAN89, bEliminateSpuriousExtrema,
  311.                     bApplyMonotoneFilter);

  312.         return null == lmcg ? null : CustomSlopeHermiteSpline (strName, adblPredictorOrdinate,
  313.             adblResponseValue, lmcg.C1(), aSCBC, sbfr, iSetupMode);
  314.     }

  315.     /**
  316.      * Create the Harmonic Monotone Preserving Stretch. The reference is:
  317.      *
  318.      *  Fritcsh and Butland (1984) A Method for constructing local monotonic piece-wise cubic interpolants -
  319.      *      SIAM J on Scientific and Statistical Computing 5, 300-304.
  320.      *
  321.      * @param strName Stretch Name
  322.      * @param adblPredictorOrdinate Array of Predictor Ordinates
  323.      * @param adblResponseValue Array of Response Values
  324.      * @param aSCBC Array of Segment Builder Parameters
  325.      * @param sbfr Stretch Fitness Weighted Response
  326.      * @param iSetupMode Segment Setup Mode
  327.      * @param bEliminateSpuriousExtrema TRUE - Eliminate Spurious Extrema
  328.      * @param bApplyMonotoneFilter TRUE - Apply Monotone Filter
  329.      *
  330.      * @return Harmonic Monotone Preserving Stretch
  331.      */

  332.     public static final org.drip.spline.stretch.MultiSegmentSequence CreateHarmonicMonotoneStretch (
  333.         final java.lang.String strName,
  334.         final double[] adblPredictorOrdinate,
  335.         final double[] adblResponseValue,
  336.         final org.drip.spline.params.SegmentCustomBuilderControl[] aSCBC,
  337.         final org.drip.spline.params.StretchBestFitResponse sbfr,
  338.         final int iSetupMode,
  339.         final boolean bEliminateSpuriousExtrema,
  340.         final boolean bApplyMonotoneFilter)
  341.     {
  342.         org.drip.spline.pchip.LocalMonotoneCkGenerator lmcg =
  343.             org.drip.spline.pchip.LocalMonotoneCkGenerator.Create (adblPredictorOrdinate, adblResponseValue,
  344.                 org.drip.spline.pchip.LocalMonotoneCkGenerator.C1_HARMONIC, bEliminateSpuriousExtrema,
  345.                     bApplyMonotoneFilter);

  346.         return null == lmcg ? null : CustomSlopeHermiteSpline (strName, adblPredictorOrdinate,
  347.             adblResponseValue, lmcg.C1(), aSCBC, sbfr, iSetupMode);
  348.     }

  349.     /**
  350.      * Create the Van Leer Limiter Stretch. The reference is:
  351.      *
  352.      *  Van Leer (1974) Towards the Ultimate Conservative Difference Scheme. II - Monotonicity and
  353.      *      Conservation combined in a Second-Order Scheme, Journal of Computational Physics 14 (4), 361-370.
  354.      *
  355.      * @param strName Stretch Name
  356.      * @param adblPredictorOrdinate Array of Predictor Ordinates
  357.      * @param adblResponseValue Array of Response Values
  358.      * @param aSCBC Array of Segment Builder Parameters
  359.      * @param sbfr Stretch Fitness Weighted Response
  360.      * @param iSetupMode Segment Setup Mode
  361.      * @param bEliminateSpuriousExtrema TRUE - Eliminate Spurious Extrema
  362.      * @param bApplyMonotoneFilter TRUE - Apply Monotone Filter
  363.      *
  364.      * @return The Van Leer Limiter Stretch
  365.      */

  366.     public static final org.drip.spline.stretch.MultiSegmentSequence CreateVanLeerLimiterStretch (
  367.         final java.lang.String strName,
  368.         final double[] adblPredictorOrdinate,
  369.         final double[] adblResponseValue,
  370.         final org.drip.spline.params.SegmentCustomBuilderControl[] aSCBC,
  371.         final org.drip.spline.params.StretchBestFitResponse sbfr,
  372.         final int iSetupMode,
  373.         final boolean bEliminateSpuriousExtrema,
  374.         final boolean bApplyMonotoneFilter)
  375.     {
  376.         org.drip.spline.pchip.LocalMonotoneCkGenerator lmcg =
  377.             org.drip.spline.pchip.LocalMonotoneCkGenerator.Create (adblPredictorOrdinate, adblResponseValue,
  378.                 org.drip.spline.pchip.LocalMonotoneCkGenerator.C1_VAN_LEER, bEliminateSpuriousExtrema,
  379.                     bApplyMonotoneFilter);

  380.         return null == lmcg ? null : CustomSlopeHermiteSpline (strName, adblPredictorOrdinate,
  381.             adblResponseValue, lmcg.C1(), aSCBC, sbfr, iSetupMode);
  382.     }

  383.     /**
  384.      * Create the Kruger Stretch. The reference is:
  385.      *
  386.      *  Kruger (2002) Constrained Cubic Spline Interpolations for Chemical Engineering Application,
  387.      *      http://www.korf.co.uk/spline.pdf
  388.      *
  389.      * @param strName Stretch Name
  390.      * @param adblPredictorOrdinate Array of Predictor Ordinates
  391.      * @param adblResponseValue Array of Response Values
  392.      * @param aSCBC Array of Segment Builder Parameters
  393.      * @param sbfr Stretch Fitness Weighted Response
  394.      * @param iSetupMode Segment Setup Mode
  395.      * @param bEliminateSpuriousExtrema TRUE - Eliminate Spurious Extrema
  396.      * @param bApplyMonotoneFilter TRUE - Apply Monotone Filter
  397.      *
  398.      * @return The Kruger Stretch
  399.      */

  400.     public static final org.drip.spline.stretch.MultiSegmentSequence CreateKrugerStretch (
  401.         final java.lang.String strName,
  402.         final double[] adblPredictorOrdinate,
  403.         final double[] adblResponseValue,
  404.         final org.drip.spline.params.SegmentCustomBuilderControl[] aSCBC,
  405.         final org.drip.spline.params.StretchBestFitResponse sbfr,
  406.         final int iSetupMode,
  407.         final boolean bEliminateSpuriousExtrema,
  408.         final boolean bApplyMonotoneFilter)
  409.     {
  410.         org.drip.spline.pchip.LocalMonotoneCkGenerator lmcg =
  411.             org.drip.spline.pchip.LocalMonotoneCkGenerator.Create (adblPredictorOrdinate, adblResponseValue,
  412.                 org.drip.spline.pchip.LocalMonotoneCkGenerator.C1_KRUGER, bEliminateSpuriousExtrema,
  413.                     bApplyMonotoneFilter);

  414.         return null == lmcg ? null : CustomSlopeHermiteSpline (strName, adblPredictorOrdinate,
  415.             adblResponseValue, lmcg.C1(), aSCBC, sbfr, iSetupMode);
  416.     }

  417.     /**
  418.      * Create the Huynh Le Floch Limiter Stretch. The reference is:
  419.      *
  420.      *  Huynh (1993) Accurate Monotone Cubic Interpolation, SIAM J on Numerical Analysis 30 (1), 57-100.
  421.      *
  422.      * @param strName Stretch Name
  423.      * @param adblPredictorOrdinate Array of Predictor Ordinates
  424.      * @param adblResponseValue Array of Response Values
  425.      * @param aSCBC Array of Segment Builder Parameters
  426.      * @param sbfr Stretch Fitness Weighted Response
  427.      * @param iSetupMode Segment Setup Mode
  428.      * @param bEliminateSpuriousExtrema TRUE - Eliminate Spurious Extrema
  429.      * @param bApplyMonotoneFilter TRUE - Apply Monotone Filter
  430.      *
  431.      * @return The Huynh Le Floch Limiter Stretch
  432.      */

  433.     public static final org.drip.spline.stretch.MultiSegmentSequence CreateHuynhLeFlochLimiterStretch (
  434.         final java.lang.String strName,
  435.         final double[] adblPredictorOrdinate,
  436.         final double[] adblResponseValue,
  437.         final org.drip.spline.params.SegmentCustomBuilderControl[] aSCBC,
  438.         final org.drip.spline.params.StretchBestFitResponse sbfr,
  439.         final int iSetupMode,
  440.         final boolean bEliminateSpuriousExtrema,
  441.         final boolean bApplyMonotoneFilter)
  442.     {
  443.         org.drip.spline.pchip.LocalMonotoneCkGenerator lmcg =
  444.             org.drip.spline.pchip.LocalMonotoneCkGenerator.Create (adblPredictorOrdinate, adblResponseValue,
  445.                 org.drip.spline.pchip.LocalMonotoneCkGenerator.C1_KRUGER, bEliminateSpuriousExtrema,
  446.                     bApplyMonotoneFilter);

  447.         return null == lmcg ? null : CustomSlopeHermiteSpline (strName, adblPredictorOrdinate,
  448.             adblResponseValue, lmcg.C1(), aSCBC, sbfr, iSetupMode);
  449.     }

  450.     /**
  451.      * Generate the local control C1 Slope using the Akima Cubic Algorithm. The reference is:
  452.      *
  453.      *  Akima (1970): A New Method of Interpolation and Smooth Curve Fitting based on Local Procedures,
  454.      *      Journal of the Association for the Computing Machinery 17 (4), 589-602.
  455.      *
  456.      * @param strName Stretch Name
  457.      * @param adblPredictorOrdinate Array of Predictor Ordinates
  458.      * @param adblResponseValue Array of Response Values
  459.      * @param aSCBC Array of Segment Builder Parameters
  460.      * @param sbfr Stretch Fitness Weighted Response
  461.      * @param iSetupMode Segment Setup Mode
  462.      * @param bEliminateSpuriousExtrema TRUE - Eliminate Spurious Extrema
  463.      * @param bApplyMonotoneFilter TRUE - Apply Monotone Filter
  464.      *
  465.      * @return The Akima Local Control Stretch Instance
  466.      */

  467.     public static final org.drip.spline.stretch.MultiSegmentSequence CreateAkimaStretch (
  468.         final java.lang.String strName,
  469.         final double[] adblPredictorOrdinate,
  470.         final double[] adblResponseValue,
  471.         final org.drip.spline.params.SegmentCustomBuilderControl[] aSCBC,
  472.         final org.drip.spline.params.StretchBestFitResponse sbfr,
  473.         final int iSetupMode,
  474.         final boolean bEliminateSpuriousExtrema,
  475.         final boolean bApplyMonotoneFilter)
  476.     {
  477.         org.drip.spline.pchip.LocalMonotoneCkGenerator lmcg =
  478.             org.drip.spline.pchip.LocalMonotoneCkGenerator.Create (adblPredictorOrdinate, adblResponseValue,
  479.                 org.drip.spline.pchip.LocalMonotoneCkGenerator.C1_AKIMA, bEliminateSpuriousExtrema,
  480.                     bApplyMonotoneFilter);

  481.         return null == lmcg ? null : CustomSlopeHermiteSpline (strName, adblPredictorOrdinate,
  482.             adblResponseValue, lmcg.C1(), aSCBC, sbfr, iSetupMode);
  483.     }

  484.     /**
  485.      * Generate the local control C1 Slope using the Hagan-West Monotone Convex Algorithm. The references
  486.      *  are:
  487.      *
  488.      *  Hagan, P., and G. West (2006): Interpolation Methods for Curve Construction, Applied Mathematical
  489.      *   Finance 13 (2): 89-129.
  490.      *
  491.      *  Hagan, P., and G. West (2008): Methods for Curve a Yield Curve, Wilmott Magazine: 70-81.
  492.      *
  493.      * @param strName Stretch Name
  494.      * @param adblPredictorOrdinate Array of Predictor Ordinates
  495.      * @param adblObservation Array of Observations
  496.      * @param aSCBC Array of Segment Builder Parameters
  497.      * @param sbfr Stretch Fitness Weighted Response
  498.      * @param iSetupMode Segment Setup Mode
  499.      * @param bLinearNodeInference Apply Linear Node Inference from Observations
  500.      * @param bEliminateSpuriousExtrema TRUE - Eliminate Spurious Extrema
  501.      * @param bApplyMonotoneFilter TRUE - Apply Monotone Filter
  502.      *
  503.      * @return The Monotone-Convex Local Control Stretch Instance
  504.      */

  505.     public static final org.drip.spline.stretch.MultiSegmentSequence CreateMonotoneConvexStretch (
  506.         final java.lang.String strName,
  507.         final double[] adblPredictorOrdinate,
  508.         final double[] adblObservation,
  509.         final org.drip.spline.params.SegmentCustomBuilderControl[] aSCBC,
  510.         final org.drip.spline.params.StretchBestFitResponse sbfr,
  511.         final int iSetupMode,
  512.         final boolean bLinearNodeInference,
  513.         final boolean bEliminateSpuriousExtrema,
  514.         final boolean bApplyMonotoneFilter)
  515.     {
  516.         org.drip.spline.pchip.MonotoneConvexHaganWest mchw =
  517.             org.drip.spline.pchip.MonotoneConvexHaganWest.Create (adblPredictorOrdinate, adblObservation,
  518.                 bLinearNodeInference);

  519.         if (null == mchw) return null;

  520.         org.drip.spline.pchip.LocalMonotoneCkGenerator lmcg =
  521.             org.drip.spline.pchip.LocalMonotoneCkGenerator.Create (mchw.predictorOrdinates(),
  522.                 mchw.responseValues(), org.drip.spline.pchip.LocalMonotoneCkGenerator.C1_MONOTONE_CONVEX,
  523.                     bEliminateSpuriousExtrema, bApplyMonotoneFilter);

  524.         return null == lmcg ? null : CustomSlopeHermiteSpline (strName, mchw.predictorOrdinates(),
  525.             mchw.responseValues(), lmcg.C1(), aSCBC, sbfr, iSetupMode);
  526.     }
  527. }