ScenarioDiscountCurveBuilder.java

  1. package org.drip.state.creator;

  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>ScenarioDiscountCurveBuilder</i> implements the the construction of the scenario discount curve using
  83.  * the input discount curve instruments, and a wide variety of custom builds. It implements the following
  84.  * functionality:
  85.  *
  86.  *  <br><br>
  87.  *  <ul>
  88.  *      <li>
  89.  *          Non-linear Custom Discount Curve
  90.  *      </li>
  91.  *      <li>
  92.  *          Shape Preserving Discount Curve Builds - Standard Cubic Polynomial/Cubic KLK Hyperbolic Tension,
  93.  *              and other Custom Builds
  94.  *      </li>
  95.  *      <li>
  96.  *          Smoothing Local/Control Custom Build - DC/Forward/Zero Rate LSQM's
  97.  *      </li>
  98.  *      <li>
  99.  *          "Industry Standard Methodologies" - DENSE/DUALDENSE/CUSTOMDENSE and Hagan-West Forward
  100.  *              Interpolator Schemes
  101.  *      </li>
  102.  *  </ul>
  103.  *
  104.  *  <br><br>
  105.  *  <ul>
  106.  *      <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/ProductCore.md">Product Core Module</a></li>
  107.  *      <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/FixedIncomeAnalyticsLibrary.md">Fixed Income Analytics</a></li>
  108.  *      <li><b>Project</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/state/README.md">Latent State Inference and Creation Utilities</a></li>
  109.  *      <li><b>Package</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/state/creator/README.md">Scenario State Curve/Surface Builders</a></li>
  110.  *  </ul>
  111.  * <br><br>
  112.  *
  113.  * @author Lakshmi Krishnamurthy
  114.  */

  115. public class ScenarioDiscountCurveBuilder {
  116.     static class CompQuote {
  117.         double _dblQuote = java.lang.Double.NaN;
  118.         org.drip.product.definition.CalibratableComponent _comp = null;
  119.  
  120.         CompQuote (
  121.             final org.drip.product.definition.CalibratableComponent comp,
  122.             final double dblQuote)
  123.         {
  124.             _comp = comp;
  125.             _dblQuote = dblQuote;
  126.         }
  127.     }

  128.     private static final boolean s_bBlog = false;

  129.     private static final CompQuote[] CompQuote (
  130.         final org.drip.param.valuation.ValuationParams valParams,
  131.         final org.drip.param.market.CurveSurfaceQuoteContainer csqs,
  132.         final java.lang.String strCurrency,
  133.         final org.drip.analytics.date.JulianDate dtEffective,
  134.         final org.drip.analytics.date.JulianDate dtInitialMaturity,
  135.         final org.drip.analytics.date.JulianDate dtTerminalMaturity,
  136.         final java.lang.String strTenor,
  137.         final boolean bIsIRS)
  138.     {
  139.         java.util.List<java.lang.Double> lsCalibQuote = new java.util.ArrayList<java.lang.Double>();

  140.         java.util.List<org.drip.product.definition.CalibratableComponent> lsCompDENSE = new
  141.             java.util.ArrayList<org.drip.product.definition.CalibratableComponent>();

  142.         org.drip.analytics.date.JulianDate dtMaturity = dtInitialMaturity;

  143.         while (dtMaturity.julian() <= dtTerminalMaturity.julian()) {
  144.             try {
  145.                 org.drip.product.definition.CalibratableComponent comp = null;

  146.                 if (bIsIRS) {
  147.                     java.lang.String strMaturityTenor = ((int) ((dtMaturity.julian() - dtEffective.julian())
  148.                         * 12 / 365.25)) + "M";

  149.                     org.drip.market.otc.FixedFloatSwapConvention ffConv =
  150.                         org.drip.market.otc.IBORFixedFloatContainer.ConventionFromJurisdiction (strCurrency,
  151.                             "ALL", strMaturityTenor, "MAIN");

  152.                     if (null == ffConv) return null;

  153.                     comp = ffConv.createFixFloatComponent (dtEffective, strMaturityTenor, 0., 0., 1.);
  154.                 } else {
  155.                     org.drip.param.period.ComposableFloatingUnitSetting cfusDeposit = new
  156.                         org.drip.param.period.ComposableFloatingUnitSetting ("3M",
  157.                             org.drip.analytics.support.CompositePeriodBuilder.EDGE_DATE_SEQUENCE_SINGLE,
  158.                                 null, org.drip.state.identifier.ForwardLabel.Standard (strCurrency + "-3M"),
  159.                                     org.drip.analytics.support.CompositePeriodBuilder.REFERENCE_PERIOD_IN_ADVANCE,
  160.                         0.);

  161.                     org.drip.param.period.CompositePeriodSetting cpsDeposit = new
  162.                         org.drip.param.period.CompositePeriodSetting (4, "3M", strCurrency, null, 1., null,
  163.                             null, null, null);

  164.                     comp = new org.drip.product.rates.SingleStreamComponent ("DEPOSIT_" + dtMaturity, new
  165.                         org.drip.product.rates.Stream
  166.                             (org.drip.analytics.support.CompositePeriodBuilder.FloatingCompositeUnit
  167.                                 (org.drip.analytics.support.CompositePeriodBuilder.EdgePair (dtEffective,
  168.                                     dtMaturity), cpsDeposit, cfusDeposit)), null);
  169.                 }

  170.                 lsCompDENSE.add (comp);

  171.                 lsCalibQuote.add (comp.measureValue (valParams, null, csqs, null, "Rate"));
  172.             } catch (java.lang.Exception e) {
  173.                 e.printStackTrace();

  174.                 return null;
  175.             }

  176.             if (null == (dtMaturity = dtMaturity.addTenorAndAdjust (strTenor, strCurrency))) return null;
  177.         }

  178.         int iNumDENSEComp = lsCompDENSE.size();

  179.         if (0 == iNumDENSEComp) return null;

  180.         CompQuote[] aCQ = new CompQuote[iNumDENSEComp];

  181.         for (int i = 0; i < iNumDENSEComp; ++i)
  182.             aCQ[i] = new CompQuote (lsCompDENSE.get (i), lsCalibQuote.get (i));

  183.         return aCQ;
  184.     }

  185.     /**
  186.      * Create an DiscountCurveScenarioContainer Instance from the currency and the array of the calibration
  187.      *  instruments
  188.      *
  189.      * @param strCurrency Currency
  190.      * @param aCalibInst Array of the calibration instruments
  191.      *
  192.      * @return The DiscountCurveScenarioContainer instance
  193.      */

  194.     public static final org.drip.param.market.DiscountCurveScenarioContainer FromIRCSG (
  195.         final java.lang.String strCurrency,
  196.         final org.drip.product.definition.CalibratableComponent[] aCalibInst)
  197.     {
  198.         try {
  199.             return new org.drip.param.market.DiscountCurveScenarioContainer (aCalibInst);
  200.         } catch (java.lang.Exception e) {
  201.             e.printStackTrace();
  202.         }

  203.         return null;
  204.     }

  205.     /**
  206.      * Create Discount Curve from the Calibration Instruments
  207.      *
  208.      * @param dt Valuation Date
  209.      * @param strCurrency Currency
  210.      * @param aCalibInst Input Calibration Instruments
  211.      * @param adblCalibQuote Input Calibration Quotes
  212.      * @param astrCalibMeasure Input Calibration Measures
  213.      * @param lsfc Latent State Fixings Container
  214.      *
  215.      * @return The Calibrated Discount Curve
  216.      */

  217.     public static final org.drip.state.discount.MergedDiscountForwardCurve NonlinearBuild (
  218.         final org.drip.analytics.date.JulianDate dt,
  219.         final java.lang.String strCurrency,
  220.         final org.drip.product.definition.CalibratableComponent[] aCalibInst,
  221.         final double[] adblCalibQuote,
  222.         final java.lang.String[] astrCalibMeasure,
  223.         final org.drip.param.market.LatentStateFixingsContainer lsfc)
  224.     {
  225.         return null == dt ? null : org.drip.state.boot.DiscountCurveScenario.Standard
  226.             (org.drip.param.valuation.ValuationParams.Spot (dt.julian()), aCalibInst, adblCalibQuote,
  227.                 astrCalibMeasure, 0., null, lsfc, null);
  228.     }

  229.     /**
  230.      * Build the Shape Preserving Discount Curve using the Custom Parameters
  231.      *
  232.      * @param strCurrency Currency
  233.      * @param llsc The Linear Latent State Calibrator Instance
  234.      * @param aStretchSpec Array of the Instrument Representation Stretches
  235.      * @param valParam Valuation Parameters
  236.      * @param pricerParam Pricer Parameters
  237.      * @param csqs Market Parameters
  238.      * @param quotingParam Quoting Parameters
  239.      * @param dblEpochResponse The Starting Response Value
  240.      *
  241.      * @return Instance of the Shape Preserving Discount Curve
  242.      */

  243.     public static final org.drip.state.discount.MergedDiscountForwardCurve ShapePreservingDFBuild (
  244.         final java.lang.String strCurrency,
  245.         final org.drip.state.inference.LinearLatentStateCalibrator llsc,
  246.         final org.drip.state.inference.LatentStateStretchSpec[] aStretchSpec,
  247.         final org.drip.param.valuation.ValuationParams valParam,
  248.         final org.drip.param.pricer.CreditPricerParams pricerParam,
  249.         final org.drip.param.market.CurveSurfaceQuoteContainer csqs,
  250.         final org.drip.param.valuation.ValuationCustomizationParams quotingParam,
  251.         final double dblEpochResponse)
  252.     {
  253.         if (null == llsc) return null;

  254.         try {
  255.             org.drip.spline.grid.Span spanDF = llsc.calibrateSpan (aStretchSpec, dblEpochResponse, valParam,
  256.                 pricerParam, quotingParam, csqs);

  257.             if (null == spanDF) return null;

  258.             org.drip.state.curve.DiscountFactorDiscountCurve dcdf = new
  259.                 org.drip.state.curve.DiscountFactorDiscountCurve (strCurrency, spanDF);

  260.             return dcdf.setCCIS (new org.drip.analytics.input.LatentStateShapePreservingCCIS (llsc,
  261.                 aStretchSpec, valParam, pricerParam, quotingParam, csqs)) ? dcdf : null;
  262.         } catch (java.lang.Exception e) {
  263.             e.printStackTrace();
  264.         }

  265.         return null;
  266.     }

  267.     /**
  268.      * Build a Globally Smoothed Instance of the Discount Curve using the Custom Parameters
  269.      *
  270.      * @param dcShapePreserver Instance of the Shape Preserving Discount Curve
  271.      * @param llsc The Linear Latent State Calibrator Instance
  272.      * @param gccp Global Smoothing Curve Control Parameters
  273.      * @param valParam Valuation Parameters
  274.      * @param pricerParam Pricer Parameters
  275.      * @param csqs Market Parameters
  276.      * @param quotingParam Quoting Parameters
  277.      *
  278.      * @return Globally Smoothed Instance of the Discount Curve
  279.      */

  280.     public static final org.drip.state.discount.MergedDiscountForwardCurve SmoothingGlobalControlBuild (
  281.         final org.drip.state.discount.MergedDiscountForwardCurve dcShapePreserver,
  282.         final org.drip.state.inference.LinearLatentStateCalibrator llsc,
  283.         final org.drip.state.estimator.GlobalControlCurveParams gccp,
  284.         final org.drip.param.valuation.ValuationParams valParam,
  285.         final org.drip.param.pricer.CreditPricerParams pricerParam,
  286.         final org.drip.param.market.CurveSurfaceQuoteContainer csqs,
  287.         final org.drip.param.valuation.ValuationCustomizationParams quotingParam)
  288.     {
  289.         if (null == dcShapePreserver) return null;

  290.         if (null == gccp) return dcShapePreserver;

  291.         java.lang.String strSmootheningQM = gccp.smootheningQuantificationMetric();

  292.         java.util.Map<java.lang.Integer, java.lang.Double> mapQMTruth = dcShapePreserver.canonicalTruthness
  293.             (strSmootheningQM);

  294.         if (null == mapQMTruth) return null;

  295.         int iTruthSize = mapQMTruth.size();

  296.         if (0 == iTruthSize) return null;

  297.         java.util.Set<java.util.Map.Entry<java.lang.Integer, java.lang.Double>> esQMTruth =
  298.             mapQMTruth.entrySet();

  299.         if (null == esQMTruth || 0 == esQMTruth.size()) return null;

  300.         java.lang.String strName = dcShapePreserver.label().fullyQualifiedName();

  301.         int i = 0;
  302.         int[] aiDate = new int[iTruthSize];
  303.         double[] adblQM = new double[iTruthSize];
  304.         org.drip.spline.params.SegmentCustomBuilderControl[] aPRBP = new
  305.             org.drip.spline.params.SegmentCustomBuilderControl[iTruthSize - 1];

  306.         for (java.util.Map.Entry<java.lang.Integer, java.lang.Double> meQMTruth : esQMTruth) {
  307.             if (null == meQMTruth) return null;

  308.             if (0 != i) aPRBP[i - 1] = gccp.defaultSegmentBuilderControl();

  309.             aiDate[i] = meQMTruth.getKey();

  310.             adblQM[i++] = meQMTruth.getValue();

  311.             if (s_bBlog)
  312.                 System.out.println ("\t\t" + new org.drip.analytics.date.JulianDate (meQMTruth.getKey()) +
  313.                     " = " + meQMTruth.getValue());
  314.         }

  315.         try {
  316.             org.drip.spline.stretch.MultiSegmentSequence stretch =
  317.                 org.drip.spline.stretch.MultiSegmentSequenceBuilder.CreateCalibratedStretchEstimator
  318.                     (strName + "_STRETCH", aiDate, adblQM, aPRBP, gccp.bestFitWeightedResponse(),
  319.                         gccp.calibrationBoundaryCondition(), gccp.calibrationDetail());

  320.             org.drip.state.discount.MergedDiscountForwardCurve dcMultiPass = null;

  321.             if (org.drip.analytics.definition.LatentStateStatic.DISCOUNT_QM_DISCOUNT_FACTOR.equalsIgnoreCase
  322.                 (strSmootheningQM))
  323.                 dcMultiPass = new org.drip.state.curve.DiscountFactorDiscountCurve (strName, new
  324.                     org.drip.spline.grid.OverlappingStretchSpan (stretch));
  325.             else if
  326.                 (org.drip.analytics.definition.LatentStateStatic.DISCOUNT_QM_ZERO_RATE.equalsIgnoreCase
  327.                 (strSmootheningQM))
  328.                 dcMultiPass = new org.drip.state.curve.ZeroRateDiscountCurve (strName, new
  329.                     org.drip.spline.grid.OverlappingStretchSpan (stretch));

  330.             return dcMultiPass;
  331.         } catch (java.lang.Exception e) {
  332.             e.printStackTrace();
  333.         }

  334.         return null;
  335.     }

  336.     /**
  337.      * Build a Locally Smoothed Instance of the Discount Curve using the Custom Parameters
  338.      *
  339.      * @param dcShapePreserver Instance of the Shape Preserving Discount Curve
  340.      * @param llsc The Linear Latent State Calibrator Instance
  341.      * @param lccp Local Smoothing Curve Control Parameters
  342.      * @param valParam Valuation Parameters
  343.      * @param pricerParam Pricer Parameters
  344.      * @param csqs Market Parameters
  345.      * @param quotingParam Quoting Parameters
  346.      *
  347.      * @return Locally Smoothed Instance of the Discount Curve
  348.      */

  349.     public static final org.drip.state.discount.MergedDiscountForwardCurve SmoothingLocalControlBuild (
  350.         final org.drip.state.discount.MergedDiscountForwardCurve dcShapePreserver,
  351.         final org.drip.state.inference.LinearLatentStateCalibrator llsc,
  352.         final org.drip.state.estimator.LocalControlCurveParams lccp,
  353.         final org.drip.param.valuation.ValuationParams valParam,
  354.         final org.drip.param.pricer.CreditPricerParams pricerParam,
  355.         final org.drip.param.market.CurveSurfaceQuoteContainer csqs,
  356.         final org.drip.param.valuation.ValuationCustomizationParams quotingParam)
  357.     {
  358.         if (null == dcShapePreserver) return null;

  359.         if (null == lccp) return dcShapePreserver;

  360.         java.lang.String strSmootheningQM = lccp.smootheningQuantificationMetric();

  361.         java.util.Map<java.lang.Integer, java.lang.Double> mapQMTruth = dcShapePreserver.canonicalTruthness
  362.             (strSmootheningQM);

  363.         if (null == mapQMTruth) return null;

  364.         int iTruthSize = mapQMTruth.size();

  365.         if (0 == iTruthSize) return null;

  366.         java.util.Set<java.util.Map.Entry<java.lang.Integer, java.lang.Double>> esQMTruth =
  367.             mapQMTruth.entrySet();

  368.         if (null == esQMTruth || 0 == esQMTruth.size()) return null;

  369.         java.lang.String strName = dcShapePreserver.label().fullyQualifiedName();

  370.         int i = 0;
  371.         int[] aiDate = new int[iTruthSize];
  372.         double[] adblQM = new double[iTruthSize];
  373.         org.drip.spline.params.SegmentCustomBuilderControl[] aPRBP = new
  374.             org.drip.spline.params.SegmentCustomBuilderControl[iTruthSize - 1];

  375.         for (java.util.Map.Entry<java.lang.Integer, java.lang.Double> meQMTruth : esQMTruth) {
  376.             if (null == meQMTruth) return null;

  377.             if (0 != i) aPRBP[i - 1] = lccp.defaultSegmentBuilderControl();

  378.             aiDate[i] = meQMTruth.getKey();

  379.             adblQM[i++] = meQMTruth.getValue();

  380.             if (s_bBlog)
  381.                 System.out.println ("\t\t" + new org.drip.analytics.date.JulianDate (meQMTruth.getKey()) +
  382.                     " = " + meQMTruth.getValue());
  383.         }

  384.         try {
  385.             org.drip.spline.pchip.LocalMonotoneCkGenerator lcr =
  386.                 org.drip.spline.pchip.LocalMonotoneCkGenerator.Create (aiDate, adblQM,
  387.                     lccp.C1GeneratorScheme(), lccp.eliminateSpuriousExtrema(), lccp.applyMonotoneFilter());

  388.             if (null == lcr) return null;

  389.             org.drip.spline.stretch.MultiSegmentSequence stretch =
  390.                 org.drip.spline.pchip.LocalControlStretchBuilder.CustomSlopeHermiteSpline (strName +
  391.                     "_STRETCH", aiDate, adblQM, lcr.C1(), aPRBP, lccp.bestFitWeightedResponse(),
  392.                         lccp.calibrationDetail());

  393.             org.drip.state.discount.MergedDiscountForwardCurve dcMultiPass = null;

  394.             if (org.drip.analytics.definition.LatentStateStatic.DISCOUNT_QM_DISCOUNT_FACTOR.equalsIgnoreCase
  395.                 (strSmootheningQM))
  396.                 dcMultiPass = new org.drip.state.curve.DiscountFactorDiscountCurve (strName, new
  397.                     org.drip.spline.grid.OverlappingStretchSpan (stretch));
  398.             else if
  399.                 (org.drip.analytics.definition.LatentStateStatic.DISCOUNT_QM_ZERO_RATE.equalsIgnoreCase
  400.                 (strSmootheningQM))
  401.                 dcMultiPass = new org.drip.state.curve.ZeroRateDiscountCurve (strName, new
  402.                     org.drip.spline.grid.OverlappingStretchSpan (stretch));

  403.             return dcMultiPass;
  404.         } catch (java.lang.Exception e) {
  405.             e.printStackTrace();
  406.         }

  407.         return null;
  408.     }

  409.     /**
  410.      * Construct an instance of the Shape Preserver of the desired basis type, using the specified basis set
  411.      *  builder parameters.
  412.      *
  413.      * @param strName Curve Name
  414.      * @param valParams Valuation Parameters
  415.      * @param pricerParam Pricer Parameters
  416.      * @param csqs Market Parameters
  417.      * @param quotingParam Quoting Parameters
  418.      * @param strBasisType The Basis Type
  419.      * @param fsbp The Function Set Basis Parameters
  420.      * @param aCalibComp1 Array of Calibration Components #1
  421.      * @param adblQuote1 Array of Calibration Quotes #1
  422.      * @param astrManifestMeasure1 Array of Manifest Measures for component Array #1
  423.      * @param aCalibComp2 Array of Calibration Components #2
  424.      * @param adblQuote2 Array of Calibration Quotes #2
  425.      * @param astrManifestMeasure2 Array of Manifest Measures for component Array #2
  426.      * @param dblEpochResponse The Stretch Start DF
  427.      * @param bZeroSmooth TRUE - Turn on the Zero Rate Smoothing
  428.      *
  429.      * @return Instance of the Shape Preserver of the desired basis type
  430.      */

  431.     public static final org.drip.state.discount.MergedDiscountForwardCurve DFRateShapePreserver (
  432.         final java.lang.String strName,
  433.         final org.drip.param.valuation.ValuationParams valParams,
  434.         final org.drip.param.pricer.CreditPricerParams pricerParam,
  435.         final org.drip.param.market.CurveSurfaceQuoteContainer csqs,
  436.         final org.drip.param.valuation.ValuationCustomizationParams quotingParam,
  437.         final java.lang.String strBasisType,
  438.         final org.drip.spline.basis.FunctionSetBuilderParams fsbp,
  439.         final org.drip.product.definition.CalibratableComponent[] aCalibComp1,
  440.         final double[] adblQuote1,
  441.         final java.lang.String[] astrManifestMeasure1,
  442.         final org.drip.product.definition.CalibratableComponent[] aCalibComp2,
  443.         final double[] adblQuote2,
  444.         final java.lang.String[] astrManifestMeasure2,
  445.         final double dblEpochResponse,
  446.         final boolean bZeroSmooth)
  447.     {
  448.         if (null == strName || strName.isEmpty() || null == strBasisType || strBasisType.isEmpty() || null ==
  449.             valParams || null == fsbp)
  450.             return null;

  451.         int iNumQuote1 = null == adblQuote1 ? 0 : adblQuote1.length;
  452.         int iNumQuote2 = null == adblQuote2 ? 0 : adblQuote2.length;
  453.         int iNumComp1 = null == aCalibComp1 ? 0 : aCalibComp1.length;
  454.         int iNumComp2 = null == aCalibComp2 ? 0 : aCalibComp2.length;
  455.         org.drip.state.estimator.LocalControlCurveParams lccp = null;
  456.         org.drip.state.inference.LinearLatentStateCalibrator llsc = null;
  457.         org.drip.state.inference.LatentStateStretchSpec stretchSpec1 = null;
  458.         org.drip.state.inference.LatentStateStretchSpec stretchSpec2 = null;
  459.         org.drip.state.representation.LatentStateSpecification[] aLSS = null;
  460.         org.drip.state.inference.LatentStateStretchSpec[] aStretchSpec = null;
  461.         org.drip.state.representation.LatentStateSpecification lssFunding = null;
  462.         org.drip.state.discount.MergedDiscountForwardCurve dcShapePreserving = null;
  463.         int iNumManifestMeasures1 = null == astrManifestMeasure1 ? 0 : astrManifestMeasure1.length;
  464.         int iNumManifestMeasures2 = null == astrManifestMeasure2 ? 0 : astrManifestMeasure2.length;
  465.         org.drip.analytics.support.CaseInsensitiveTreeMap<org.drip.state.identifier.ForwardLabel>
  466.             mapForwardLabel = null;

  467.         if ((0 == iNumComp1 && 0 == iNumComp2) || iNumComp1 != iNumQuote1 || iNumComp2 != iNumQuote2 ||
  468.             iNumComp1 != iNumManifestMeasures1 || iNumComp2 != iNumManifestMeasures2)
  469.             return null;

  470.         java.lang.String strCurrency = (0 == iNumComp1 ? aCalibComp2 : aCalibComp1)[0].payCurrency();

  471.         try {
  472.             lssFunding = new org.drip.state.representation.LatentStateSpecification
  473.                 (org.drip.analytics.definition.LatentStateStatic.LATENT_STATE_FUNDING,
  474.                     org.drip.analytics.definition.LatentStateStatic.DISCOUNT_QM_DISCOUNT_FACTOR,
  475.                         org.drip.state.identifier.FundingLabel.Standard (strCurrency));
  476.         } catch (java.lang.Exception e) {
  477.             e.printStackTrace();

  478.             return null;
  479.         }

  480.         if (0 != iNumComp1) mapForwardLabel = aCalibComp1[0].forwardLabel();

  481.         if (null == mapForwardLabel && 0 != iNumComp2) mapForwardLabel = aCalibComp2[0].forwardLabel();

  482.         if (null == mapForwardLabel || 0 == mapForwardLabel.size())
  483.             aLSS = new org.drip.state.representation.LatentStateSpecification[] {lssFunding};
  484.         else {
  485.             try {
  486.                 aLSS = new org.drip.state.representation.LatentStateSpecification[] {lssFunding, new
  487.                     org.drip.state.representation.LatentStateSpecification
  488.                         (org.drip.analytics.definition.LatentStateStatic.LATENT_STATE_FORWARD,
  489.                             org.drip.analytics.definition.LatentStateStatic.FORWARD_QM_FORWARD_RATE,
  490.                                 mapForwardLabel.get ("DERIVED"))};
  491.             } catch (java.lang.Exception e) {
  492.                 e.printStackTrace();

  493.                 return null;
  494.             }
  495.         }

  496.         if (0 != iNumComp1) {
  497.             org.drip.state.inference.LatentStateSegmentSpec[] aSegmentSpec = new
  498.                 org.drip.state.inference.LatentStateSegmentSpec[iNumComp1];

  499.             try {
  500.                 for (int i = 0; i < iNumComp1; ++i) {
  501.                     org.drip.product.calib.ProductQuoteSet pqs = aCalibComp1[i].calibQuoteSet (aLSS);

  502.                     if (null == pqs || !pqs.set (astrManifestMeasure1[i], adblQuote1[i])) return null;

  503.                     aSegmentSpec[i] = new org.drip.state.inference.LatentStateSegmentSpec (aCalibComp1[i],
  504.                         pqs);
  505.                 }

  506.                 stretchSpec1 = new org.drip.state.inference.LatentStateStretchSpec (strName + "_COMP1",
  507.                     aSegmentSpec);
  508.             } catch (java.lang.Exception e) {
  509.                 e.printStackTrace();

  510.                 return null;
  511.             }
  512.         }

  513.         if (0 != iNumComp2) {
  514.             org.drip.state.inference.LatentStateSegmentSpec[] aSegmentSpec = new
  515.                 org.drip.state.inference.LatentStateSegmentSpec[iNumComp2];

  516.             try {
  517.                 for (int i = 0; i < iNumComp2; ++i) {
  518.                     org.drip.product.calib.ProductQuoteSet pqs = aCalibComp2[i].calibQuoteSet (aLSS);

  519.                     if (null == pqs || !pqs.set (astrManifestMeasure2[i], adblQuote2[i])) return null;

  520.                     aSegmentSpec[i] = new org.drip.state.inference.LatentStateSegmentSpec (aCalibComp2[i],
  521.                         pqs);
  522.                 }

  523.                 stretchSpec2 = new org.drip.state.inference.LatentStateStretchSpec (strName + "_COMP2",
  524.                     aSegmentSpec);
  525.             } catch (java.lang.Exception e) {
  526.                 e.printStackTrace();

  527.                 return null;
  528.             }
  529.         }

  530.         if (null == stretchSpec1 && null == stretchSpec2) return null;

  531.         if (null == stretchSpec1)
  532.             aStretchSpec = new org.drip.state.inference.LatentStateStretchSpec[] {stretchSpec2};
  533.         else if (null == stretchSpec2)
  534.             aStretchSpec = new org.drip.state.inference.LatentStateStretchSpec[] {stretchSpec1};
  535.         else
  536.             aStretchSpec = new org.drip.state.inference.LatentStateStretchSpec[] {stretchSpec1,
  537.                 stretchSpec2};

  538.         try {
  539.             llsc = new org.drip.state.inference.LinearLatentStateCalibrator (new
  540.                 org.drip.spline.params.SegmentCustomBuilderControl (strBasisType, fsbp,
  541.                     org.drip.spline.params.SegmentInelasticDesignControl.Create (2, 2), new
  542.                         org.drip.spline.params.ResponseScalingShapeControl (true, new
  543.                             org.drip.function.r1tor1.QuadraticRationalShapeControl (0.)), null),
  544.                                 org.drip.spline.stretch.BoundarySettings.NaturalStandard(),
  545.                                     org.drip.spline.stretch.MultiSegmentSequence.CALIBRATE, null, null);

  546.             dcShapePreserving = ShapePreservingDFBuild (strCurrency, llsc, aStretchSpec, valParams,
  547.                 pricerParam, csqs, quotingParam, dblEpochResponse);
  548.         } catch (java.lang.Exception e) {
  549.             e.printStackTrace();

  550.             return null;
  551.         }

  552.         if (!bZeroSmooth) return dcShapePreserving;

  553.         try {
  554.             lccp = new org.drip.state.estimator.LocalControlCurveParams
  555.                 (org.drip.spline.pchip.LocalMonotoneCkGenerator.C1_HYMAN83,
  556.                     org.drip.analytics.definition.LatentStateStatic.DISCOUNT_QM_ZERO_RATE, new
  557.                         org.drip.spline.params.SegmentCustomBuilderControl
  558.                             (org.drip.spline.stretch.MultiSegmentSequenceBuilder.BASIS_SPLINE_POLYNOMIAL, new
  559.                                 org.drip.spline.basis.PolynomialFunctionSetParams (4),
  560.                                     org.drip.spline.params.SegmentInelasticDesignControl.Create (2, 2), new
  561.                                         org.drip.spline.params.ResponseScalingShapeControl (true, new
  562.                                             org.drip.function.r1tor1.QuadraticRationalShapeControl (0.)),
  563.                                                 null),
  564.                                                     org.drip.spline.stretch.MultiSegmentSequence.CALIBRATE,
  565.                                                         null, null, true, true);
  566.         } catch (java.lang.Exception e) {
  567.             e.printStackTrace();

  568.             return null;
  569.         }

  570.         return SmoothingLocalControlBuild (dcShapePreserving, llsc, lccp, valParams, null, null, null);
  571.     }

  572.     /**
  573.      * Construct an instance of the Shape Preserver of the KLK Hyperbolic Tension Type, using the specified
  574.      *  basis set builder parameters.
  575.      *
  576.      * @param strName Curve Name
  577.      * @param valParams Valuation Parameters
  578.      * @param aCalibComp1 Array of Calibration Components #1
  579.      * @param adblQuote1 Array of Calibration Quotes #1
  580.      * @param astrManifestMeasure1 Array of Manifest Measures for component Array #1
  581.      * @param aCalibComp2 Array of Calibration Components #2
  582.      * @param adblQuote2 Array of Calibration Quotes #2
  583.      * @param astrManifestMeasure2 Array of Manifest Measures for component Array #2
  584.      * @param bZeroSmooth TRUE - Turn on the Zero Rate Smoothing
  585.      *
  586.      * @return Instance of the Shape Preserver of the desired basis type
  587.      */

  588.     public static final org.drip.state.discount.MergedDiscountForwardCurve CubicKLKHyperbolicDFRateShapePreserver (
  589.         final java.lang.String strName,
  590.         final org.drip.param.valuation.ValuationParams valParams,
  591.         final org.drip.product.definition.CalibratableComponent[] aCalibComp1,
  592.         final double[] adblQuote1,
  593.         final java.lang.String[] astrManifestMeasure1,
  594.         final org.drip.product.definition.CalibratableComponent[] aCalibComp2,
  595.         final double[] adblQuote2,
  596.         final java.lang.String[] astrManifestMeasure2,
  597.         final boolean bZeroSmooth)
  598.     {
  599.         try {
  600.             return DFRateShapePreserver (strName, valParams, null, null, null,
  601.                 org.drip.spline.stretch.MultiSegmentSequenceBuilder.BASIS_SPLINE_KLK_HYPERBOLIC_TENSION, new
  602.                     org.drip.spline.basis.ExponentialTensionSetParams (1.), aCalibComp1, adblQuote1,
  603.                         astrManifestMeasure1, aCalibComp2, adblQuote2, astrManifestMeasure2, 1.,
  604.                             bZeroSmooth);
  605.         } catch (java.lang.Exception e) {
  606.             e.printStackTrace();
  607.         }

  608.         return null;
  609.     }

  610.     /**
  611.      * Construct an instance of the Shape Preserver of the Cubic Polynomial Type, using the specified
  612.      *  basis set builder parameters.
  613.      *
  614.      * @param strName Curve Name
  615.      * @param valParams Valuation Parameters
  616.      * @param aCalibComp1 Array of Calibration Components #1
  617.      * @param adblQuote1 Array of Calibration Quotes #1
  618.      * @param astrManifestMeasure1 Array of Manifest Measures for component Array #1
  619.      * @param aCalibComp2 Array of Calibration Components #2
  620.      * @param adblQuote2 Array of Calibration Quotes #2
  621.      * @param astrManifestMeasure2 Array of Manifest Measures for component Array #2
  622.      * @param bZeroSmooth TRUE - Turn on the Zero Rate Smoothing
  623.      *
  624.      * @return Instance of the Shape Preserver of the desired basis type
  625.      */

  626.     public static final org.drip.state.discount.MergedDiscountForwardCurve CubicPolyDFRateShapePreserver (
  627.         final java.lang.String strName,
  628.         final org.drip.param.valuation.ValuationParams valParams,
  629.         final org.drip.product.definition.CalibratableComponent[] aCalibComp1,
  630.         final double[] adblQuote1,
  631.         final java.lang.String[] astrManifestMeasure1,
  632.         final org.drip.product.definition.CalibratableComponent[] aCalibComp2,
  633.         final double[] adblQuote2,
  634.         final java.lang.String[] astrManifestMeasure2,
  635.         final boolean bZeroSmooth)
  636.     {
  637.         try {
  638.             return DFRateShapePreserver (strName, valParams, null, null, null,
  639.                 org.drip.spline.stretch.MultiSegmentSequenceBuilder.BASIS_SPLINE_POLYNOMIAL, new
  640.                     org.drip.spline.basis.PolynomialFunctionSetParams (4), aCalibComp1, adblQuote1,
  641.                         astrManifestMeasure1, aCalibComp2, adblQuote2, astrManifestMeasure2, 1.,
  642.                             bZeroSmooth);
  643.         } catch (java.lang.Exception e) {
  644.             e.printStackTrace();
  645.         }

  646.         return null;
  647.     }

  648.     /**
  649.      * Customizable DENSE Curve Creation Methodology - the references are:
  650.      *
  651.      *  - Sankar, L. (1997): OFUTS – An Alternative Yield Curve Interpolator F. A. S. T. Research
  652.      *      Documentation Bear Sterns.
  653.      *  
  654.      *  - Nahum, E. (2004): Changes to Yield Curve Construction – Linear Stripping of the Short End of the
  655.      *      Curve F. A. S. T. Research Documentation Bear Sterns.
  656.      *  
  657.      *  - Kinlay, J., and X. Bai (2009): Yield Curve Construction Models – Tools and Techniques
  658.      *      (http://www.jonathankinlay.com/Articles/Yield Curve Construction Models.pdf)
  659.      *  
  660.      * @param strName The Curve Name
  661.      * @param valParams Valuation Parameters
  662.      * @param aCalibComp1 Array of Stretch #1 Calibration Components
  663.      * @param adblQuote1 Array of Stretch #1 Calibration Quotes
  664.      * @param strTenor1 Stretch #1 Instrument set re-construction Tenor
  665.      * @param astrManifestMeasure1 Array of Manifest Measures for component Array #1
  666.      * @param aCalibComp2 Array of Stretch #2 Calibration Components
  667.      * @param adblQuote2 Array of Stretch #2 Calibration Quotes
  668.      * @param strTenor2 Stretch #2 Instrument set re-construction Tenor
  669.      * @param astrManifestMeasure2 Array of Manifest Measures for component Array #2
  670.      * @param tldf The Turns List
  671.      *
  672.      * @return The Customized DENSE Curve.
  673.      */

  674.     public static final org.drip.state.discount.MergedDiscountForwardCurve CustomDENSE (
  675.         final java.lang.String strName,
  676.         final org.drip.param.valuation.ValuationParams valParams,
  677.         final org.drip.product.definition.CalibratableComponent[] aCalibComp1,
  678.         final double[] adblQuote1,
  679.         final java.lang.String strTenor1,
  680.         final java.lang.String[] astrManifestMeasure1,
  681.         final org.drip.product.definition.CalibratableComponent[] aCalibComp2,
  682.         final double[] adblQuote2,
  683.         final java.lang.String strTenor2,
  684.         final java.lang.String[] astrManifestMeasure2,
  685.         final org.drip.state.discount.TurnListDiscountFactor tldf)
  686.     {
  687.         org.drip.state.discount.MergedDiscountForwardCurve dcShapePreserver = CubicKLKHyperbolicDFRateShapePreserver
  688.             (strName, valParams, aCalibComp1, adblQuote1, astrManifestMeasure1, aCalibComp2, adblQuote2,
  689.                 astrManifestMeasure2, false);

  690.         if (null == dcShapePreserver || (null != tldf && !dcShapePreserver.setTurns (tldf))) return null;

  691.         org.drip.param.market.CurveSurfaceQuoteContainer csqs = org.drip.param.creator.MarketParamsBuilder.Create
  692.             (dcShapePreserver, null, null, null, null, null, null);

  693.         if (null == csqs) return null;

  694.         CompQuote[] aCQ1 = null;

  695.         java.lang.String strCurrency = aCalibComp1[0].payCurrency();

  696.         if (null == strTenor1 || strTenor1.isEmpty()) {
  697.             if (null != aCalibComp1) {
  698.                 int iNumComp1 = aCalibComp1.length;

  699.                 if (0 != iNumComp1) {
  700.                     aCQ1 = new CompQuote[iNumComp1];

  701.                     for (int i = 0; i < iNumComp1; ++i)
  702.                         aCQ1[i] = new CompQuote (aCalibComp1[i], adblQuote1[i]);
  703.                 }
  704.             }
  705.         } else
  706.             aCQ1 = CompQuote (valParams, csqs, strCurrency, aCalibComp1[0].effectiveDate(),
  707.                 aCalibComp1[0].maturityDate(), aCalibComp1[aCalibComp1.length - 1].maturityDate(), strTenor1,
  708.                     false);

  709.         if (null == strTenor2 || strTenor2.isEmpty()) return dcShapePreserver;

  710.         CompQuote[] aCQ2 = CompQuote (valParams, csqs, strCurrency, aCalibComp2[0].effectiveDate(),
  711.             aCalibComp2[0].maturityDate(), aCalibComp2[aCalibComp2.length - 1].maturityDate(), strTenor2,
  712.                 true);

  713.         int iNumDENSEComp1 = null == aCQ1 ? 0 : aCQ1.length;
  714.         int iNumDENSEComp2 = null == aCQ2 ? 0 : aCQ2.length;
  715.         int iTotalNumDENSEComp = iNumDENSEComp1 + iNumDENSEComp2;

  716.         if (0 == iTotalNumDENSEComp) return null;

  717.         double[] adblCalibQuote = new double[iTotalNumDENSEComp];
  718.         java.lang.String[] astrCalibMeasure = new java.lang.String[iTotalNumDENSEComp];
  719.         org.drip.product.definition.CalibratableComponent[] aCalibComp = new
  720.             org.drip.product.definition.CalibratableComponent[iTotalNumDENSEComp];

  721.         for (int i = 0; i < iNumDENSEComp1; ++i) {
  722.             astrCalibMeasure[i] = "Rate";
  723.             aCalibComp[i] = aCQ1[i]._comp;
  724.             adblCalibQuote[i] = aCQ1[i]._dblQuote;
  725.         }

  726.         for (int i = iNumDENSEComp1; i < iTotalNumDENSEComp; ++i) {
  727.             astrCalibMeasure[i] = "Rate";
  728.             aCalibComp[i] = aCQ2[i - iNumDENSEComp1]._comp;
  729.             adblCalibQuote[i] = aCQ2[i - iNumDENSEComp1]._dblQuote;
  730.         }

  731.         try {
  732.             return ScenarioDiscountCurveBuilder.NonlinearBuild (new org.drip.analytics.date.JulianDate
  733.                 (valParams.valueDate()), strCurrency, aCalibComp, adblCalibQuote, astrCalibMeasure, null);
  734.         } catch (java.lang.Exception e) {
  735.             e.printStackTrace();
  736.         }

  737.         return null;
  738.     }

  739.     /**
  740.      * The Standard DENSE Curve Creation Methodology - this uses no re-construction set for the short term,
  741.      *  and uses 3M dense re-construction for the Swap Set. The references are:
  742.      *
  743.      *  - Sankar, L. (1997): OFUTS – An Alternative Yield Curve Interpolator F. A. S. T. Research
  744.      *      Documentation Bear Sterns.
  745.      *  
  746.      *  - Nahum, E. (2004): Changes to Yield Curve Construction – Linear Stripping of the Short End of the
  747.      *      Curve F. A. S. T. Research Documentation Bear Sterns.
  748.      *  
  749.      *  - Kinlay, J., and X. Bai (2009): Yield Curve Construction Models – Tools and Techniques
  750.      *      (http://www.jonathankinlay.com/Articles/Yield Curve Construction Models.pdf)
  751.      *  
  752.      * @param strName The Curve Name
  753.      * @param valParams Valuation Parameters
  754.      * @param aCalibComp1 Array of Stretch #1 Calibration Components
  755.      * @param adblQuote1 Array of Stretch #1 Calibration Quotes
  756.      * @param astrManifestMeasure1 Array of Manifest Measures for component Array #1
  757.      * @param aCalibComp2 Array of Stretch #2 Calibration Components
  758.      * @param adblQuote2 Array of Stretch #2 Calibration Quotes
  759.      * @param astrManifestMeasure2 Array of Manifest Measures for component Array #2
  760.      * @param tldf The Turns List
  761.      *
  762.      * @return The Customized DENSE Curve.
  763.      */

  764.     public static final org.drip.state.discount.MergedDiscountForwardCurve DENSE (
  765.         final java.lang.String strName,
  766.         final org.drip.param.valuation.ValuationParams valParams,
  767.         final org.drip.product.definition.CalibratableComponent[] aCalibComp1,
  768.         final double[] adblQuote1,
  769.         final java.lang.String[] astrManifestMeasure1,
  770.         final org.drip.product.definition.CalibratableComponent[] aCalibComp2,
  771.         final double[] adblQuote2,
  772.         final java.lang.String[] astrManifestMeasure2,
  773.         final org.drip.state.discount.TurnListDiscountFactor tldf)
  774.     {
  775.         return CustomDENSE (strName, valParams, aCalibComp1, adblQuote1, null, astrManifestMeasure1,
  776.             aCalibComp2, adblQuote2, "3M", astrManifestMeasure2, tldf);
  777.     }

  778.     /**
  779.      * The DUAL DENSE Curve Creation Methodology - this uses configurable re-construction set for the short
  780.      *  term, and another configurable re-construction for the Swap Set. 1D re-construction tenor for the
  781.      *  short end will result in CDF (Constant Daily Forward) Discount Curve. The references are:
  782.      *
  783.      *  - Sankar, L. (1997): OFUTS – An Alternative Yield Curve Interpolator F. A. S. T. Research
  784.      *      Documentation Bear Sterns.
  785.      *  
  786.      *  - Nahum, E. (2004): Changes to Yield Curve Construction – Linear Stripping of the Short End of the
  787.      *      Curve F. A. S. T. Research Documentation Bear Sterns.
  788.      *  
  789.      *  - Kinlay, J., and X. Bai (2009): Yield Curve Construction Models – Tools and Techniques
  790.      *      (http://www.jonathankinlay.com/Articles/Yield Curve Construction Models.pdf)
  791.      *  
  792.      * @param strName The Curve Name
  793.      * @param valParams Valuation Parameters
  794.      * @param aCalibComp1 Array of Stretch #1 Calibration Components
  795.      * @param adblQuote1 Array of Stretch #1 Calibration Quotes
  796.      * @param strTenor1 Stretch #1 Instrument set re-construction Tenor
  797.      * @param astrManifestMeasure1 Array of Manifest Measures for component Array #1
  798.      * @param aCalibComp2 Array of Stretch #2 Calibration Components
  799.      * @param adblQuote2 Array of Stretch #2 Calibration Quotes
  800.      * @param strTenor2 Stretch #2 Instrument set re-construction Tenor
  801.      * @param astrManifestMeasure2 Array of Manifest Measures for component Array #2
  802.      * @param tldf The Turns List
  803.      *
  804.      * @return The Customized DENSE Curve.
  805.      */

  806.     public static final org.drip.state.discount.MergedDiscountForwardCurve DUALDENSE (
  807.         final java.lang.String strName,
  808.         final org.drip.param.valuation.ValuationParams valParams,
  809.         final org.drip.product.definition.CalibratableComponent[] aCalibComp1,
  810.         final double[] adblQuote1,
  811.         final java.lang.String strTenor1,
  812.         final java.lang.String[] astrManifestMeasure1,
  813.         final org.drip.product.definition.CalibratableComponent[] aCalibComp2,
  814.         final double[] adblQuote2,
  815.         final java.lang.String strTenor2,
  816.         final java.lang.String[] astrManifestMeasure2,
  817.         final org.drip.state.discount.TurnListDiscountFactor tldf)
  818.     {
  819.         return CustomDENSE (strName, valParams, aCalibComp1, adblQuote1, strTenor1, astrManifestMeasure1,
  820.             aCalibComp2, adblQuote2, strTenor2, astrManifestMeasure2, tldf);
  821.     }

  822.     /**
  823.      * Create an Instance of the Custom Splined Discount Curve
  824.      *
  825.      * @param strName Curve Name
  826.      * @param dtStart Tenor Start Date
  827.      * @param strCurrency The Currency
  828.      * @param aiDate Array of Dates
  829.      * @param adblDF Array of Discount Factors
  830.      * @param scbc The Segment Custom Builder Control
  831.      *
  832.      * @return The Instance of the Basis Curve
  833.      */

  834.     public static final org.drip.state.discount.MergedDiscountForwardCurve CustomSplineDiscountCurve (
  835.         final java.lang.String strName,
  836.         final org.drip.analytics.date.JulianDate dtStart,
  837.         final java.lang.String strCurrency,
  838.         final int[] aiDate,
  839.         final double[] adblDF,
  840.         final org.drip.spline.params.SegmentCustomBuilderControl scbc)
  841.     {
  842.         if (null == strName || strName.isEmpty() || null == aiDate || null == dtStart) return null;

  843.         int iNumDate = aiDate.length;

  844.         if (0 == iNumDate) return null;

  845.         double[] adblResponseValue = new double[iNumDate + 1];
  846.         double[] adblPredictorOrdinate = new double[iNumDate + 1];
  847.         org.drip.spline.params.SegmentCustomBuilderControl[] aSCBC = new
  848.             org.drip.spline.params.SegmentCustomBuilderControl[iNumDate];

  849.         for (int i = 0; i <= iNumDate; ++i) {
  850.             adblPredictorOrdinate[i] = 0 == i ? dtStart.julian() : aiDate[i - 1];

  851.             adblResponseValue[i] = 0 == i ? 1. : adblDF[i - 1];

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

  854.         try {
  855.             return new org.drip.state.curve.DiscountFactorDiscountCurve (strCurrency, new
  856.                 org.drip.spline.grid.OverlappingStretchSpan
  857.                     (org.drip.spline.stretch.MultiSegmentSequenceBuilder.CreateCalibratedStretchEstimator
  858.                         (strName, adblPredictorOrdinate, adblResponseValue, aSCBC, null,
  859.                             org.drip.spline.stretch.BoundarySettings.NaturalStandard(),
  860.                                 org.drip.spline.stretch.MultiSegmentSequence.CALIBRATE)));
  861.         } catch (java.lang.Exception e) {
  862.             e.printStackTrace();
  863.         }

  864.         return null;
  865.     }

  866.     /**
  867.      * Create an Instance of the Cubic Polynomial Splined DF Discount Curve
  868.      *
  869.      * @param strName Curve Name
  870.      * @param dtStart Tenor Start Date
  871.      * @param strCurrency The Currency
  872.      * @param aiDate Array of Dates
  873.      * @param adblDF Array of Discount Factors
  874.      *
  875.      * @return The Instance of the Discount Curve
  876.      */

  877.     public static final org.drip.state.discount.MergedDiscountForwardCurve CubicPolynomialDiscountCurve (
  878.         final java.lang.String strName,
  879.         final org.drip.analytics.date.JulianDate dtStart,
  880.         final java.lang.String strCurrency,
  881.         final int[] aiDate,
  882.         final double[] adblDF)
  883.     {
  884.         try {
  885.             return CustomSplineDiscountCurve (strName, dtStart, strCurrency, aiDate, adblDF, new
  886.                 org.drip.spline.params.SegmentCustomBuilderControl
  887.                     (org.drip.spline.stretch.MultiSegmentSequenceBuilder.BASIS_SPLINE_POLYNOMIAL, new
  888.                         org.drip.spline.basis.PolynomialFunctionSetParams (4),
  889.                             org.drip.spline.params.SegmentInelasticDesignControl.Create (2, 2), null, null));
  890.         } catch (java.lang.Exception e) {
  891.             e.printStackTrace();
  892.         }

  893.         return null;
  894.     }

  895.     /**
  896.      * Create an Instance of the Quartic Polynomial Splined DF Discount Curve
  897.      *
  898.      * @param strName Curve Name
  899.      * @param dtStart Tenor Start Date
  900.      * @param strCurrency The Currency
  901.      * @param aiDate Array of Dates
  902.      * @param adblDF Array of Discount Factors
  903.      *
  904.      * @return The Instance of the Discount Curve
  905.      */

  906.     public static final org.drip.state.discount.MergedDiscountForwardCurve QuarticPolynomialDiscountCurve (
  907.         final java.lang.String strName,
  908.         final org.drip.analytics.date.JulianDate dtStart,
  909.         final java.lang.String strCurrency,
  910.         final int[] aiDate,
  911.         final double[] adblDF)
  912.     {
  913.         try {
  914.             return CustomSplineDiscountCurve (strName, dtStart, strCurrency, aiDate, adblDF, new
  915.                 org.drip.spline.params.SegmentCustomBuilderControl
  916.                     (org.drip.spline.stretch.MultiSegmentSequenceBuilder.BASIS_SPLINE_POLYNOMIAL, new
  917.                         org.drip.spline.basis.PolynomialFunctionSetParams (5),
  918.                             org.drip.spline.params.SegmentInelasticDesignControl.Create (2, 2), null, null));
  919.         } catch (java.lang.Exception e) {
  920.             e.printStackTrace();
  921.         }

  922.         return null;
  923.     }

  924.     /**
  925.      * Create an Instance of the Kaklis-Pandelis Splined DF Discount Curve
  926.      *
  927.      * @param strName Curve Name
  928.      * @param dtStart Tenor Start Date
  929.      * @param strCurrency The Currency
  930.      * @param aiDate Array of Dates
  931.      * @param adblDF Array of Discount Factors
  932.      *
  933.      * @return The Instance of the Discount Curve
  934.      */

  935.     public static final org.drip.state.discount.MergedDiscountForwardCurve KaklisPandelisDiscountCurve (
  936.         final java.lang.String strName,
  937.         final org.drip.analytics.date.JulianDate dtStart,
  938.         final java.lang.String strCurrency,
  939.         final int[] aiDate,
  940.         final double[] adblDF)
  941.     {
  942.         try {
  943.             return CustomSplineDiscountCurve (strName, dtStart, strCurrency, aiDate, adblDF, new
  944.                 org.drip.spline.params.SegmentCustomBuilderControl
  945.                     (org.drip.spline.stretch.MultiSegmentSequenceBuilder.BASIS_SPLINE_KAKLIS_PANDELIS, new
  946.                         org.drip.spline.basis.KaklisPandelisSetParams (2),
  947.                             org.drip.spline.params.SegmentInelasticDesignControl.Create (2, 2), null, null));
  948.         } catch (java.lang.Exception e) {
  949.             e.printStackTrace();
  950.         }

  951.         return null;
  952.     }

  953.     /**
  954.      * Create an Instance of the KLK Hyperbolic Splined DF Discount Curve
  955.      *
  956.      * @param strName Curve Name
  957.      * @param dtStart Tenor Start Date
  958.      * @param strCurrency The Currency
  959.      * @param aiDate Array of Dates
  960.      * @param adblDF Array of Discount Factors
  961.      * @param dblTension The Tension Parameter
  962.      *
  963.      * @return The Instance of the Discount Curve
  964.      */

  965.     public static final org.drip.state.discount.MergedDiscountForwardCurve KLKHyperbolicDiscountCurve (
  966.         final java.lang.String strName,
  967.         final org.drip.analytics.date.JulianDate dtStart,
  968.         final java.lang.String strCurrency,
  969.         final int[] aiDate,
  970.         final double[] adblDF,
  971.         final double dblTension)
  972.     {
  973.         try {
  974.             return CustomSplineDiscountCurve (strName, dtStart, strCurrency, aiDate, adblDF, new
  975.                 org.drip.spline.params.SegmentCustomBuilderControl
  976.                     (org.drip.spline.stretch.MultiSegmentSequenceBuilder.BASIS_SPLINE_KLK_HYPERBOLIC_TENSION,
  977.                         new org.drip.spline.basis.ExponentialTensionSetParams (dblTension),
  978.                             org.drip.spline.params.SegmentInelasticDesignControl.Create (2, 2), null, null));
  979.         } catch (java.lang.Exception e) {
  980.             e.printStackTrace();
  981.         }

  982.         return null;
  983.     }

  984.     /**
  985.      * Create an Instance of the KLK Exponential Splined DF Discount Curve
  986.      *
  987.      * @param strName Curve Name
  988.      * @param dtStart Tenor Start Date
  989.      * @param strCurrency The Currency
  990.      * @param aiDate Array of Dates
  991.      * @param adblDF Array of Discount Factors
  992.      * @param dblTension The Tension Parameter
  993.      *
  994.      * @return The Instance of the Discount Curve
  995.      */

  996.     public static final org.drip.state.discount.MergedDiscountForwardCurve KLKExponentialDiscountCurve (
  997.         final java.lang.String strName,
  998.         final org.drip.analytics.date.JulianDate dtStart,
  999.         final java.lang.String strCurrency,
  1000.         final int[] aiDate,
  1001.         final double[] adblDF,
  1002.         final double dblTension)
  1003.     {
  1004.         try {
  1005.             return CustomSplineDiscountCurve (strName, dtStart, strCurrency, aiDate, adblDF, new
  1006.             org.drip.spline.params.SegmentCustomBuilderControl
  1007.                     (org.drip.spline.stretch.MultiSegmentSequenceBuilder.BASIS_SPLINE_KLK_EXPONENTIAL_TENSION,
  1008.                 new org.drip.spline.basis.ExponentialTensionSetParams (dblTension),
  1009.                     org.drip.spline.params.SegmentInelasticDesignControl.Create (2, 2), null, null));
  1010.         } catch (java.lang.Exception e) {
  1011.             e.printStackTrace();
  1012.         }

  1013.         return null;
  1014.     }

  1015.     /**
  1016.      * Create an Instance of the KLK Linear Rational Splined DF Discount Curve
  1017.      *
  1018.      * @param strName Curve Name
  1019.      * @param dtStart Tenor Start Date
  1020.      * @param strCurrency The Currency
  1021.      * @param aiDate Array of Dates
  1022.      * @param adblDF Array of Discount Factors
  1023.      * @param dblTension The Tension Parameter
  1024.      *
  1025.      * @return The Instance of the Discount Curve
  1026.      */

  1027.     public static final org.drip.state.discount.MergedDiscountForwardCurve KLKRationalLinearDiscountCurve (
  1028.         final java.lang.String strName,
  1029.         final org.drip.analytics.date.JulianDate dtStart,
  1030.         final java.lang.String strCurrency,
  1031.         final int[] aiDate,
  1032.         final double[] adblDF,
  1033.         final double dblTension)
  1034.     {
  1035.         try {
  1036.             return CustomSplineDiscountCurve (strName, dtStart, strCurrency, aiDate, adblDF, new
  1037.                 org.drip.spline.params.SegmentCustomBuilderControl
  1038.                     (org.drip.spline.stretch.MultiSegmentSequenceBuilder.BASIS_SPLINE_KLK_RATIONAL_LINEAR_TENSION,
  1039.                 new org.drip.spline.basis.ExponentialTensionSetParams (dblTension),
  1040.                     org.drip.spline.params.SegmentInelasticDesignControl.Create (2, 2), null, null));
  1041.         } catch (java.lang.Exception e) {
  1042.             e.printStackTrace();
  1043.         }

  1044.         return null;
  1045.     }

  1046.     /**
  1047.      * Create an Instance of the KLK Quadratic Rational Splined DF Discount Curve
  1048.      *
  1049.      * @param strName Curve Name
  1050.      * @param dtStart Tenor Start Date
  1051.      * @param strCurrency The Currency
  1052.      * @param aiDate Array of Dates
  1053.      * @param adblDF Array of Discount Factors
  1054.      * @param dblTension The Tension Parameter
  1055.      *
  1056.      * @return The Instance of the Discount Curve
  1057.      */

  1058.     public static final org.drip.state.discount.MergedDiscountForwardCurve KLKRationalQuadraticDiscountCurve (
  1059.         final java.lang.String strName,
  1060.         final org.drip.analytics.date.JulianDate dtStart,
  1061.         final java.lang.String strCurrency,
  1062.         final int[] aiDate,
  1063.         final double[] adblDF,
  1064.         final double dblTension)
  1065.     {
  1066.         try {
  1067.             return CustomSplineDiscountCurve (strName, dtStart, strCurrency, aiDate, adblDF, new
  1068.                 org.drip.spline.params.SegmentCustomBuilderControl
  1069.                     (org.drip.spline.stretch.MultiSegmentSequenceBuilder.BASIS_SPLINE_KLK_RATIONAL_QUADRATIC_TENSION,
  1070.                 new org.drip.spline.basis.ExponentialTensionSetParams (dblTension),
  1071.                     org.drip.spline.params.SegmentInelasticDesignControl.Create (2, 2), null, null));
  1072.         } catch (java.lang.Exception e) {
  1073.             e.printStackTrace();
  1074.         }

  1075.         return null;
  1076.     }

  1077.     /**
  1078.      * Build a Discount Curve from an array of discount factors
  1079.      *
  1080.      * @param dtStart Start Date
  1081.      * @param strCurrency Currency
  1082.      * @param aiDate Array of dates
  1083.      * @param adblDF array of discount factors
  1084.      *
  1085.      * @return Discount Curve
  1086.      */

  1087.     public static final org.drip.state.discount.MergedDiscountForwardCurve BuildFromDF (
  1088.         final org.drip.analytics.date.JulianDate dtStart,
  1089.         final java.lang.String strCurrency,
  1090.         final int aiDate[],
  1091.         final double adblDF[])
  1092.     {
  1093.         if (null == aiDate || 0 == aiDate.length || null == adblDF || aiDate.length != adblDF.length ||
  1094.             null == dtStart || null == strCurrency || strCurrency.isEmpty())
  1095.             return null;

  1096.         double dblDFBegin = 1.;
  1097.         double[] adblRate = new double[aiDate.length];

  1098.         double dblPeriodBegin = dtStart.julian();

  1099.         for (int i = 0; i < aiDate.length; ++i) {
  1100.             if (aiDate[i] <= dblPeriodBegin) return null;

  1101.             adblRate[i] = 365.25 / (aiDate[i] - dblPeriodBegin) * java.lang.Math.log (dblDFBegin /
  1102.                 adblDF[i]);

  1103.             dblDFBegin = adblDF[i];
  1104.             dblPeriodBegin = aiDate[i];
  1105.         }

  1106.         try {
  1107.             return new org.drip.state.nonlinear.FlatForwardDiscountCurve (dtStart, strCurrency, aiDate,
  1108.                 adblRate, false, "", -1);
  1109.         } catch (java.lang.Exception e) {
  1110.             e.printStackTrace();
  1111.         }

  1112.         return null;
  1113.     }

  1114.     /**
  1115.      * Create a Discount Curve from the Exponentially Compounded Flat Rate
  1116.      *
  1117.      * @param dtStart Start Date
  1118.      * @param strCurrency Currency
  1119.      * @param dblRate Rate
  1120.      *
  1121.      * @return Discount Curve
  1122.      */

  1123.     public static final org.drip.state.discount.ExplicitBootDiscountCurve ExponentiallyCompoundedFlatRate (
  1124.         final org.drip.analytics.date.JulianDate dtStart,
  1125.         final java.lang.String strCurrency,
  1126.         final double dblRate)
  1127.     {
  1128.         if (null == dtStart) return null;

  1129.         try {
  1130.             return new org.drip.state.nonlinear.FlatForwardDiscountCurve (dtStart, strCurrency, new int[]
  1131.                 {dtStart.julian()}, new double[] {dblRate}, false, "", -1);
  1132.         } catch (java.lang.Exception e) {
  1133.             e.printStackTrace();
  1134.         }

  1135.         return null;
  1136.     }

  1137.     /**
  1138.      * Create a Discount Curve from the Discretely Compounded Flat Rate
  1139.      *
  1140.      * @param dtStart Start Date
  1141.      * @param strCurrency Currency
  1142.      * @param dblRate Rate
  1143.      * @param strCompoundingDayCount Day Count Convention to be used for Discrete Compounding
  1144.      * @param iCompoundingFreq Frequency to be used for Discrete Compounding
  1145.      *
  1146.      * @return Discount Curve
  1147.      */

  1148.     public static final org.drip.state.discount.ExplicitBootDiscountCurve DiscretelyCompoundedFlatRate (
  1149.         final org.drip.analytics.date.JulianDate dtStart,
  1150.         final java.lang.String strCurrency,
  1151.         final double dblRate,
  1152.         final java.lang.String strCompoundingDayCount,
  1153.         final int iCompoundingFreq)
  1154.     {
  1155.         if (null == dtStart) return null;

  1156.         try {
  1157.             return new org.drip.state.nonlinear.FlatForwardDiscountCurve (dtStart, strCurrency, new int[]
  1158.                 {dtStart.julian()}, new double[] {dblRate}, true, strCompoundingDayCount, iCompoundingFreq);
  1159.         } catch (java.lang.Exception e) {
  1160.             e.printStackTrace();
  1161.         }

  1162.         return null;
  1163.     }

  1164.     /**
  1165.      * Create a Discount Curve from the Flat Yield
  1166.      *
  1167.      * @param dtStart Start Date
  1168.      * @param strCurrency Currency
  1169.      * @param dblYield Yield
  1170.      * @param strCompoundingDayCount Day Count Convention to be used for Discrete Compounding
  1171.      * @param iCompoundingFreq Frequency to be used for Discrete Compounding
  1172.      *
  1173.      * @return The Discount Curve Instance
  1174.      */

  1175.     public static final org.drip.state.discount.ExplicitBootDiscountCurve CreateFromFlatYield (
  1176.         final org.drip.analytics.date.JulianDate dtStart,
  1177.         final java.lang.String strCurrency,
  1178.         final double dblYield,
  1179.         final java.lang.String strCompoundingDayCount,
  1180.         final int iCompoundingFreq)
  1181.     {
  1182.         if (null == dtStart || !org.drip.numerical.common.NumberUtil.IsValid (dblYield)) return null;

  1183.         try {
  1184.             return new org.drip.state.nonlinear.FlatForwardDiscountCurve (dtStart, strCurrency, new int[]
  1185.                 {dtStart.julian()}, new double[] {dblYield}, true, strCompoundingDayCount, iCompoundingFreq);
  1186.         } catch (java.lang.Exception e) {
  1187.             e.printStackTrace();
  1188.         }

  1189.         return null;
  1190.     }

  1191.     /**
  1192.      * Create a discount curve from an array of dates/rates
  1193.      *
  1194.      * @param dtStart Start Date
  1195.      * @param strCurrency Currency
  1196.      * @param aiDate array of dates
  1197.      * @param adblRate array of rates
  1198.      *
  1199.      * @return Creates the discount curve
  1200.      */

  1201.     public static final org.drip.state.discount.ExplicitBootDiscountCurve PiecewiseForward (
  1202.         final org.drip.analytics.date.JulianDate dtStart,
  1203.         final java.lang.String strCurrency,
  1204.         final int[] aiDate,
  1205.         final double[] adblRate)
  1206.     {
  1207.         try {
  1208.             return new org.drip.state.nonlinear.FlatForwardDiscountCurve (dtStart, strCurrency, aiDate,
  1209.                 adblRate, false, "", -1);
  1210.         } catch (java.lang.Exception e) {
  1211.             e.printStackTrace();
  1212.         }

  1213.         return null;
  1214.     }
  1215. }