DiscountCurveRegressor.java

  1. package org.drip.regression.curve;

  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>DiscountCurveRegressor</i> implements the regression set analysis for the Discount Curve.
  83.  * DiscountCurveRegressor regresses 11 scenarios:
  84.  *
  85.  * <br><br>
  86.  *  <ul>
  87.  *      <li>
  88.  *          #1: Create the discount curve from a set 30 instruments (cash/future/swap).
  89.  *      </li>
  90.  *      <li>
  91.  *          #2: Create the discount curve from a flat discount rate.
  92.  *      </li>
  93.  *      <li>
  94.  *          #3: Create the discount curve from a set of discount factors.
  95.  *      </li>
  96.  *      <li>
  97.  *          #4: Create the discount curve from the implied discount rates.
  98.  *      </li>
  99.  *      <li>
  100.  *          #5: Extract the discount curve instruments and quotes.
  101.  *      </li>
  102.  *      <li>
  103.  *          #6: Create a parallel shifted discount curve.
  104.  *      </li>
  105.  *      <li>
  106.  *          #7: Create a rate shifted discount curve.
  107.  *      </li>
  108.  *      <li>
  109.  *          #8: Create a basis rate shifted discount curve.
  110.  *      </li>
  111.  *      <li>
  112.  *          #9: Create a node tweaked discount curve.
  113.  *      </li>
  114.  *      <li>
  115.  *          #10: Compute the effective discount factor between 2 dates.
  116.  *      </li>
  117.  *      <li>
  118.  *          #11: Compute the effective implied rate between 2 dates.
  119.  *      </li>
  120.  *  </ul>
  121.  *
  122.  * <br><br>
  123.  *  <ul>
  124.  *      <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/ComputationalCore.md">Computational Core Module</a></li>
  125.  *      <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/ComputationSupportLibrary.md">Computation Support</a></li>
  126.  *      <li><b>Project</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/regression/README.md">Regression Engine Core and the Unit Regressors</a></li>
  127.  *      <li><b>Package</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/regression/curve/README.md">Curve Construction/Reconciliation Regression Engine</a></li>
  128.  *  </ul>
  129.  * <br><br>
  130.  *
  131.  * @author Lakshmi Krishnamurthy
  132.  */

  133. public class DiscountCurveRegressor implements org.drip.regression.core.RegressorSet {
  134.     private java.lang.String _strCurrency = "";
  135.     private org.drip.state.discount.MergedDiscountForwardCurve _dc = null;
  136.     private org.drip.analytics.date.JulianDate _dtStart = null;
  137.     private org.drip.state.discount.ExplicitBootDiscountCurve _dcFromFlatRate = null;
  138.     private java.lang.String _strRegressionScenario = "org.drip.analytics.curve.DiscountCurve";

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

  141.     /**
  142.      * Do Nothing DiscountCurveRegressor constructor
  143.      */

  144.     public DiscountCurveRegressor()
  145.     {
  146.     }

  147.     /*
  148.      * Discount Curve Regressor set setup
  149.      */

  150.     @Override public boolean setupRegressors()
  151.     {
  152.         /*
  153.          * Testing creation of the Discount Curve from rates instruments - implements the pre-regression, the
  154.          *  post-regression, and the actual regression functionality of the UnitRegressorExecutor class.
  155.          */

  156.         try {
  157.             _setRegressors.add (new org.drip.regression.core.UnitRegressionExecutor
  158.                 ("CreateFromRatesInstruments", _strRegressionScenario)
  159.             {
  160.                 private static final int NUM_DC_INSTR = 30;

  161.                 private double _adblCompCalibValue[] = new double[NUM_DC_INSTR];
  162.                 private java.lang.String _astrCalibMeasure[] = new java.lang.String[NUM_DC_INSTR];
  163.                 private org.drip.product.definition.CalibratableComponent _aCompCalib[] = new
  164.                     org.drip.product.definition.CalibratableComponent[NUM_DC_INSTR];

  165.                 private org.drip.param.market.LatentStateFixingsContainer _lsfc = new
  166.                     org.drip.param.market.LatentStateFixingsContainer();

  167.                 @Override public boolean preRegression()
  168.                 {
  169.                     _strCurrency = "CHF";
  170.                     int aiDate[] = new int[NUM_DC_INSTR];
  171.                     double adblRate[] = new double[NUM_DC_INSTR];

  172.                     if (null == (_dtStart = org.drip.analytics.date.DateUtil.CreateFromYMD (2010,
  173.                         org.drip.analytics.date.DateUtil.MAY, 12)))
  174.                         return false;

  175.                     aiDate[0] = _dtStart.addDays (3).julian(); // ON

  176.                     aiDate[1] = _dtStart.addDays (4).julian(); // 1D (TN)

  177.                     aiDate[2] = _dtStart.addDays (9).julian(); // 1W

  178.                     aiDate[3] = _dtStart.addDays (16).julian(); // 2W

  179.                     aiDate[4] = _dtStart.addDays (32).julian(); // 1M

  180.                     aiDate[5] = _dtStart.addDays (62).julian(); // 2M

  181.                     aiDate[6] = _dtStart.addDays (92).julian(); // 3M

  182.                     _adblCompCalibValue[0] = .0013;
  183.                     _adblCompCalibValue[1] = .0017;
  184.                     _adblCompCalibValue[2] = .0017;
  185.                     _adblCompCalibValue[3] = .0018;
  186.                     _adblCompCalibValue[4] = .0020;
  187.                     _adblCompCalibValue[5] = .0023;
  188.                     _adblCompCalibValue[6] = .0026;

  189.                     for (int i = 0; i < 7; ++i) {
  190.                         _astrCalibMeasure[i] = "Rate";
  191.                         adblRate[i] = java.lang.Double.NaN;

  192.                         try {
  193.                             _aCompCalib[i] = org.drip.product.creator.SingleStreamComponentBuilder.Deposit
  194.                                 (_dtStart.addDays (2), new org.drip.analytics.date.JulianDate (aiDate[i]),
  195.                                     org.drip.state.identifier.ForwardLabel.Create (_strCurrency, "3M"));
  196.                         } catch (java.lang.Exception e) {
  197.                             e.printStackTrace();

  198.                             return false;
  199.                         }
  200.                     }

  201.                     _adblCompCalibValue[7] = .0027;
  202.                     _adblCompCalibValue[8] = .0032;
  203.                     _adblCompCalibValue[9] = .0041;
  204.                     _adblCompCalibValue[10] = .0054;
  205.                     _adblCompCalibValue[11] = .0077;
  206.                     _adblCompCalibValue[12] = .0104;
  207.                     _adblCompCalibValue[13] = .0134;
  208.                     _adblCompCalibValue[14] = .0160;
  209.                     org.drip.analytics.date.JulianDate dtEDFStart = _dtStart;

  210.                     org.drip.product.definition.CalibratableComponent[] aEDF =
  211.                         org.drip.product.creator.SingleStreamComponentBuilder.ForwardRateFuturesPack
  212.                             (_dtStart, 8, _strCurrency);

  213.                     for (int i = 0; i < 8; ++i) {
  214.                         _aCompCalib[i + 7] = aEDF[i];
  215.                         _astrCalibMeasure[i + 7] = "Rate";
  216.                         adblRate[i + 7] = java.lang.Double.NaN;

  217.                         aiDate[i + 7] = dtEDFStart.addDays ((i + 1) * 91).julian();
  218.                     }

  219.                     aiDate[15] = _dtStart.addDays ((int)(365.25 * 4 + 2)).julian(); // 4Y

  220.                     aiDate[16] = _dtStart.addDays ((int)(365.25 * 5 + 2)).julian(); // 5Y

  221.                     aiDate[17] = _dtStart.addDays ((int)(365.25 * 6 + 2)).julian(); // 6Y

  222.                     aiDate[18] = _dtStart.addDays ((int)(365.25 * 7 + 2)).julian(); // 7Y

  223.                     aiDate[19] = _dtStart.addDays ((int)(365.25 * 8 + 2)).julian(); // 8Y

  224.                     aiDate[20] = _dtStart.addDays ((int)(365.25 * 9 + 2)).julian(); // 9Y

  225.                     aiDate[21] = _dtStart.addDays ((int)(365.25 * 10 + 2)).julian(); // 10Y

  226.                     aiDate[22] = _dtStart.addDays ((int)(365.25 * 11 + 2)).julian(); // 11Y

  227.                     aiDate[23] = _dtStart.addDays ((int)(365.25 * 12 + 2)).julian(); // 12Y

  228.                     aiDate[24] = _dtStart.addDays ((int)(365.25 * 15 + 2)).julian(); // 15Y

  229.                     aiDate[25] = _dtStart.addDays ((int)(365.25 * 20 + 2)).julian(); // 20Y

  230.                     aiDate[26] = _dtStart.addDays ((int)(365.25 * 25 + 2)).julian(); // 25Y

  231.                     aiDate[27] = _dtStart.addDays ((int)(365.25 * 30 + 2)).julian(); // 30Y

  232.                     aiDate[28] = _dtStart.addDays ((int)(365.25 * 40 + 2)).julian(); // 40Y

  233.                     aiDate[29] = _dtStart.addDays ((int)(365.25 * 50 + 2)).julian(); // 50Y

  234.                     _adblCompCalibValue[15] = .0166;
  235.                     _adblCompCalibValue[16] = .0206;
  236.                     _adblCompCalibValue[17] = .0241;
  237.                     _adblCompCalibValue[18] = .0269;
  238.                     _adblCompCalibValue[19] = .0292;
  239.                     _adblCompCalibValue[20] = .0311;
  240.                     _adblCompCalibValue[21] = .0326;
  241.                     _adblCompCalibValue[22] = .0340;
  242.                     _adblCompCalibValue[23] = .0351;
  243.                     _adblCompCalibValue[24] = .0375;
  244.                     _adblCompCalibValue[25] = .0393;
  245.                     _adblCompCalibValue[26] = .0402;
  246.                     _adblCompCalibValue[27] = .0407;
  247.                     _adblCompCalibValue[28] = .0409;
  248.                     _adblCompCalibValue[29] = .0409;
  249.                     org.drip.param.period.CompositePeriodSetting cpsFixed = null;
  250.                     org.drip.param.period.CompositePeriodSetting cpsFloating = null;
  251.                     org.drip.param.period.UnitCouponAccrualSetting ucasFixed = null;
  252.                     org.drip.param.period.ComposableFixedUnitSetting cfusFixed = null;
  253.                     org.drip.param.period.ComposableFloatingUnitSetting cfusFloating = null;

  254.                     try {
  255.                         ucasFixed = new org.drip.param.period.UnitCouponAccrualSetting (2, "Act/360", false,
  256.                             "Act/360", false, _strCurrency, true,
  257.                                 org.drip.analytics.support.CompositePeriodBuilder.ACCRUAL_COMPOUNDING_RULE_GEOMETRIC);

  258.                         cfusFloating = new org.drip.param.period.ComposableFloatingUnitSetting ("3M",
  259.                             org.drip.analytics.support.CompositePeriodBuilder.EDGE_DATE_SEQUENCE_SINGLE,
  260.                                 null, org.drip.state.identifier.ForwardLabel.Standard (_strCurrency + "-3M"),
  261.                                     org.drip.analytics.support.CompositePeriodBuilder.REFERENCE_PERIOD_IN_ADVANCE,
  262.                             0.);

  263.                         cfusFixed = new org.drip.param.period.ComposableFixedUnitSetting ("6M",
  264.                             org.drip.analytics.support.CompositePeriodBuilder.EDGE_DATE_SEQUENCE_REGULAR,
  265.                                 null, 0., 0., _strCurrency);

  266.                         cpsFloating = new org.drip.param.period.CompositePeriodSetting (4, "3M",
  267.                             _strCurrency, null, -1., null, null, null, null);

  268.                         cpsFixed = new org.drip.param.period.CompositePeriodSetting (2, "6M", _strCurrency,
  269.                             null, 1., null, null, null, null);
  270.                     } catch (java.lang.Exception e) {
  271.                         e.printStackTrace();

  272.                         return false;
  273.                     }

  274.                     for (int i = 0; i < 15; ++i) {
  275.                         _astrCalibMeasure[i + 15] = "Rate";
  276.                         adblRate[i + 15] = java.lang.Double.NaN;

  277.                         try {
  278.                             org.drip.analytics.date.JulianDate dtMaturity = new
  279.                                 org.drip.analytics.date.JulianDate (aiDate[i + 15]);

  280.                             java.util.List<java.lang.Integer> lsFixedStreamEdgeDate =
  281.                                 org.drip.analytics.support.CompositePeriodBuilder.BackwardEdgeDates
  282.                                     (_dtStart, dtMaturity, "6M", null,
  283.                                         org.drip.analytics.support.CompositePeriodBuilder.SHORT_STUB);

  284.                             java.util.List<java.lang.Integer> lsFloatingStreamEdgeDate =
  285.                                 org.drip.analytics.support.CompositePeriodBuilder.BackwardEdgeDates
  286.                                     (_dtStart, dtMaturity, "3M", null,
  287.                                         org.drip.analytics.support.CompositePeriodBuilder.SHORT_STUB);

  288.                             org.drip.product.rates.Stream floatingStream = new org.drip.product.rates.Stream
  289.                                 (org.drip.analytics.support.CompositePeriodBuilder.FloatingCompositeUnit
  290.                                     (lsFloatingStreamEdgeDate, cpsFloating, cfusFloating));

  291.                             org.drip.product.rates.Stream fixedStream = new org.drip.product.rates.Stream
  292.                                 (org.drip.analytics.support.CompositePeriodBuilder.FixedCompositeUnit
  293.                                     (lsFixedStreamEdgeDate, cpsFixed, ucasFixed, cfusFixed));

  294.                             _aCompCalib[i + 15] = new org.drip.product.rates.FixFloatComponent (fixedStream,
  295.                                 floatingStream, null);
  296.                         } catch (java.lang.Exception e) {
  297.                             e.printStackTrace();

  298.                             return false;
  299.                         }
  300.                     }

  301.                     _lsfc.add (_dtStart.addDays (2), org.drip.state.identifier.ForwardLabel.Standard
  302.                         (_strCurrency + "-6M"), 0.0042);

  303.                     return true;
  304.                 }

  305.                 @Override public boolean execRegression()
  306.                 {
  307.                     return null != (_dc = org.drip.state.creator.ScenarioDiscountCurveBuilder.NonlinearBuild
  308.                         (_dtStart, _strCurrency, _aCompCalib, _adblCompCalibValue, _astrCalibMeasure,
  309.                             _lsfc));
  310.                 }
  311.             });

  312.             /*
  313.              * Testing creation of the Discount Curve from a flat rate - implements the pre-regression, the
  314.              *  post-regression, and the actual regression functionality of the UnitRegressorExecutor class.
  315.              */

  316.             _setRegressors.add (new org.drip.regression.core.UnitRegressionExecutor ("CreateFromFlatRate",
  317.                 _strRegressionScenario)
  318.             {
  319.                 @Override public boolean execRegression()
  320.                 {
  321.                     return null != (_dcFromFlatRate =
  322.                         org.drip.state.creator.ScenarioDiscountCurveBuilder.ExponentiallyCompoundedFlatRate
  323.                             (_dtStart, _strCurrency, 0.04));
  324.                 }

  325.                 @Override public boolean postRegression (
  326.                     final org.drip.regression.core.RegressionRunDetail rnvd)
  327.                 {
  328.                     final int NUM_DC_INSTRUMENTS = 5;
  329.                     int aiDate[] = new int[NUM_DC_INSTRUMENTS];
  330.                     double adblDiscountFactorFlatRate[] = new double[NUM_DC_INSTRUMENTS];

  331.                     for (int i = 0; i < NUM_DC_INSTRUMENTS; ++i) {
  332.                         try {
  333.                             if (!org.drip.numerical.common.NumberUtil.IsValid (adblDiscountFactorFlatRate[i] =
  334.                                 _dcFromFlatRate.df (aiDate[i] = _dtStart.addYears (i + 1).julian())))
  335.                                 return false;

  336.                             rnvd.set ("DiscountFactor[" + new org.drip.analytics.date.JulianDate
  337.                                 (aiDate[i]) + "]", "" + adblDiscountFactorFlatRate[i]);
  338.                         } catch (java.lang.Exception e) {
  339.                             e.printStackTrace();

  340.                             return false;
  341.                         }
  342.                     }

  343.                     return true;
  344.                 }
  345.             });

  346.             /*
  347.              * Testing creation of the Discount Curve from discount factors - implements the pre-regression,
  348.              *  the post-regression, and the actual regression functionality of the UnitRegressorExecutor
  349.              *      class.
  350.              */

  351.             _setRegressors.add (new org.drip.regression.core.UnitRegressionExecutor ("BuildFromDF",
  352.                 _strRegressionScenario)
  353.             {
  354.                 private static final int NUM_DC_INSTRUMENTS = 5;

  355.                 private int _aiDate[] = new int[NUM_DC_INSTRUMENTS];
  356.                 private org.drip.state.discount.MergedDiscountForwardCurve _dcFromDF = null;
  357.                 private double _adblDiscountFactorFlatRate[] = new double[NUM_DC_INSTRUMENTS];

  358.                 @Override public boolean preRegression()
  359.                 {
  360.                     for (int i = 0; i < NUM_DC_INSTRUMENTS; ++i) {
  361.                         try {
  362.                             if (!org.drip.numerical.common.NumberUtil.IsValid (_adblDiscountFactorFlatRate[i] =
  363.                                 _dc.df (_aiDate[i] = _dtStart.addYears (i + 1).julian())))
  364.                                 return false;
  365.                         } catch (java.lang.Exception e) {
  366.                             e.printStackTrace();

  367.                             return false;
  368.                         }
  369.                     }

  370.                     return true;
  371.                 }

  372.                 @Override public boolean execRegression()
  373.                 {
  374.                     return null != (_dcFromDF =
  375.                         org.drip.state.creator.ScenarioDiscountCurveBuilder.BuildFromDF (_dtStart,
  376.                             _strCurrency, _aiDate, _adblDiscountFactorFlatRate));
  377.                 }

  378.                 @Override public boolean postRegression (
  379.                     final org.drip.regression.core.RegressionRunDetail rnvd)
  380.                 {
  381.                     for (int i = 0; i < NUM_DC_INSTRUMENTS; ++i) {
  382.                         try {
  383.                             double dblDiscountFactorDFCurve = _dcFromDF.df (_aiDate[i]);

  384.                             rnvd.set ("DiscountFactorFlatRate[" + new org.drip.analytics.date.JulianDate
  385.                                 (_aiDate[i]) + "]", org.drip.numerical.common.FormatUtil.FormatDouble
  386.                                     (_adblDiscountFactorFlatRate[i], 1, 3, 1));

  387.                             rnvd.set ("DiscountFactorDFCurve[" + new org.drip.analytics.date.JulianDate
  388.                                 (_aiDate[i]) + "]", org.drip.numerical.common.FormatUtil.FormatDouble
  389.                                     (dblDiscountFactorDFCurve, 1, 3, 1));

  390.                             if (!org.drip.numerical.common.NumberUtil.WithinTolerance (dblDiscountFactorDFCurve,
  391.                                 _adblDiscountFactorFlatRate[i]))
  392.                                 return false;
  393.                         } catch (java.lang.Exception e) {
  394.                             e.printStackTrace();

  395.                             return false;
  396.                         }
  397.                     }

  398.                     return true;
  399.                 }
  400.             });

  401.             /*
  402.              * Testing creation of the Discount Curve from rates nodes - implements the pre-regression, the
  403.              *  post-regression, and the actual regression functionality of the UnitRegressorExecutor class.
  404.              */

  405.             _setRegressors.add (new org.drip.regression.core.UnitRegressionExecutor ("CreateDC",
  406.                 _strRegressionScenario)
  407.             {
  408.                 private static final int NUM_DC_INSTRUMENTS = 5;

  409.                 private int _aiDate[] = new int[NUM_DC_INSTRUMENTS];
  410.                 private double _adblRate[] = new double[NUM_DC_INSTRUMENTS];
  411.                 private org.drip.state.discount.MergedDiscountForwardCurve _dcFromRates = null;

  412.                 @Override public boolean preRegression()
  413.                 {
  414.                     for (int i = 0; i < NUM_DC_INSTRUMENTS; ++i) {
  415.                         try {
  416.                             if (!org.drip.numerical.common.NumberUtil.IsValid (_adblRate[i] = _dc.zero
  417.                                 (_aiDate[i] = _dtStart.addYears (i + 1).julian())))
  418.                                 return false;
  419.                         } catch (java.lang.Exception e) {
  420.                             e.printStackTrace();

  421.                             return false;
  422.                         }
  423.                     }

  424.                     return true;
  425.                 }

  426.                 @Override public boolean execRegression()
  427.                 {
  428.                     return null != (_dcFromRates =
  429.                         org.drip.state.creator.ScenarioDiscountCurveBuilder.PiecewiseForward (_dtStart,
  430.                             _strCurrency, _aiDate, _adblRate));
  431.                 }

  432.                 @Override public boolean postRegression (
  433.                     final org.drip.regression.core.RegressionRunDetail rnvd)
  434.                 {
  435.                     for (int i = 0; i < NUM_DC_INSTRUMENTS; ++i) {
  436.                         try {
  437.                             int iStartDate = _dtStart.julian();

  438.                             if (0 != i) iStartDate = _aiDate[i - 1];

  439.                             double dblRate = _dcFromRates.forward (iStartDate, _aiDate[i]);

  440.                             rnvd.set ("DiscountFactorOriginalDC[" + new org.drip.analytics.date.JulianDate
  441.                                 (_aiDate[i]) + "]", org.drip.numerical.common.FormatUtil.FormatDouble
  442.                                     (_adblRate[i], 1, 3, 1));

  443.                             rnvd.set ("DiscountFactoRateImplied[" + new org.drip.analytics.date.JulianDate
  444.                                 (_aiDate[i]) + "]", org.drip.numerical.common.FormatUtil.FormatDouble (dblRate,
  445.                                     1, 3, 1));

  446.                             if (!org.drip.numerical.common.NumberUtil.WithinTolerance (dblRate, _adblRate[i]))
  447.                                 return false;
  448.                         } catch (java.lang.Exception e) {
  449.                             e.printStackTrace();

  450.                             return false;
  451.                         }
  452.                     }

  453.                     return true;
  454.                 }
  455.             });

  456.             /*
  457.              * Testing the extraction of the components and quotes - implements the pre-regression, the
  458.              *  post-regression, and the actual regression functionality of the UnitRegressorExecutor class.
  459.              */

  460.             _setRegressors.add (new org.drip.regression.core.UnitRegressionExecutor ("CompAndQuotes",
  461.                 _strRegressionScenario)
  462.             {
  463.                 private org.drip.product.definition.CalibratableComponent[] _aCalibComp = null;

  464.                 @Override public boolean execRegression()
  465.                 {
  466.                     return null != (_aCalibComp = _dc.calibComp()) && 0 != _aCalibComp.length;
  467.                 }

  468.                 @Override public boolean postRegression (
  469.                     final org.drip.regression.core.RegressionRunDetail rnvd)
  470.                 {
  471.                     for (int i = 0; i < _aCalibComp.length; ++i) {
  472.                         java.lang.String strCalibCompCode = _aCalibComp[i].primaryCode();

  473.                         try {
  474.                             double dblQuote = _dc.manifestMeasure (strCalibCompCode).get ("Rate");

  475.                             org.drip.analytics.date.JulianDate dt = _aCalibComp[i].maturityDate();

  476.                             rnvd.set ("CompQuote" + "_" + strCalibCompCode + "{" + dt + "}",
  477.                                 org.drip.numerical.common.FormatUtil.FormatDouble (dblQuote, 1, 4, 1));
  478.                         } catch (java.lang.Exception e) {
  479.                             e.printStackTrace();

  480.                             return false;
  481.                         }
  482.                     }

  483.                     return true;
  484.                 }
  485.             });

  486.             /*
  487.              * Testing creation of the Parallel-shifted Discount Curve - implements the pre-regression, the
  488.              *  post-regression, and the actual regression functionality of the UnitRegressorExecutor class.
  489.              */

  490.             _setRegressors.add (new org.drip.regression.core.UnitRegressionExecutor ("ParallelShiftedCurve",
  491.                 _strRegressionScenario)
  492.             {
  493.                 private org.drip.state.discount.MergedDiscountForwardCurve _dcShifted = null;

  494.                 @Override public boolean execRegression()
  495.                 {
  496.                     return null != (_dcShifted = (org.drip.state.discount.MergedDiscountForwardCurve)
  497.                         _dc.parallelShiftManifestMeasure ("Rate", 0.0004));
  498.                 }

  499.                 @Override public boolean postRegression (
  500.                     final org.drip.regression.core.RegressionRunDetail rnvd)
  501.                 {
  502.                     org.drip.product.definition.CalibratableComponent[] aCalibComp =
  503.                         _dc.calibComp();

  504.                     for (int i = 0; i < aCalibComp.length; ++i) {
  505.                         java.lang.String strCalibCompCode = aCalibComp[i].primaryCode();

  506.                         try {
  507.                             double dblQuote = _dc.manifestMeasure (strCalibCompCode).get ("Rate");

  508.                             double dblQuoteShifted = _dcShifted.manifestMeasure (strCalibCompCode).get
  509.                                 ("Rate");

  510.                             rnvd.set ("BaseCurve" + "_" + strCalibCompCode,
  511.                                 org.drip.numerical.common.FormatUtil.FormatDouble (dblQuote, 1, 4, 1));

  512.                             rnvd.set ("ParallelShiftedCurve" + "_" + strCalibCompCode,
  513.                                 org.drip.numerical.common.FormatUtil.FormatDouble (dblQuoteShifted, 1, 4, 1));
  514.                         } catch (java.lang.Exception e) {
  515.                             e.printStackTrace();

  516.                             return false;
  517.                         }
  518.                     }

  519.                     return true;
  520.                 }
  521.             });

  522.             /*
  523.              * Testing creation of the Rate-shifted Discount Curve - implements the pre-regression, the
  524.              *  post-regression, and the actual regression functionality of the UnitRegressorExecutor class.
  525.              */

  526.             _setRegressors.add (new org.drip.regression.core.UnitRegressionExecutor ("RateShiftedCurve",
  527.                 _strRegressionScenario)
  528.             {
  529.                 private org.drip.state.discount.MergedDiscountForwardCurve _dcShifted = null;

  530.                 @Override public boolean execRegression()
  531.                 {
  532.                     return null != (_dcShifted = (org.drip.state.discount.MergedDiscountForwardCurve)
  533.                         _dcFromFlatRate.parallelShiftManifestMeasure ("Rate", 0.0004));
  534.                 }

  535.                 @Override public boolean postRegression (
  536.                     final org.drip.regression.core.RegressionRunDetail rnvd)
  537.                 {
  538.                     final int NUM_DC_INSTRUMENTS = 5;
  539.                     int aiDate[] = new int[NUM_DC_INSTRUMENTS];
  540.                     double adblRate[] = new double[NUM_DC_INSTRUMENTS];
  541.                     double adblRateShifted[] = new double[NUM_DC_INSTRUMENTS];

  542.                     for (int i = 0; i < NUM_DC_INSTRUMENTS; ++i) {
  543.                         try {
  544.                             if (!org.drip.numerical.common.NumberUtil.IsValid (adblRate[i] = _dcFromFlatRate.zero
  545.                                 (aiDate[i] = _dtStart.addYears (i + 1).julian())))
  546.                                 return false;

  547.                             if (!org.drip.numerical.common.NumberUtil.IsValid (adblRateShifted[i] =
  548.                                 _dcShifted.zero (aiDate[i] = _dtStart.addYears (i + 1).julian())))
  549.                                 return false;

  550.                             org.drip.analytics.date.JulianDate dt = new org.drip.analytics.date.JulianDate
  551.                                 (aiDate[i]);

  552.                             rnvd.set ("RateBase[" + dt + "]", org.drip.numerical.common.FormatUtil.FormatDouble
  553.                                 (adblRate[i], 1, 4, 1));

  554.                             rnvd.set ("RateShifted[" + dt + "]",
  555.                                 org.drip.numerical.common.FormatUtil.FormatDouble (adblRateShifted[i], 1, 4, 1));

  556.                             if (!org.drip.numerical.common.NumberUtil.WithinTolerance (adblRate[i] + 0.0004,
  557.                                 adblRateShifted[i]))
  558.                                 return false;
  559.                         } catch (java.lang.Exception e) {
  560.                             e.printStackTrace();

  561.                             return false;
  562.                         }
  563.                     }

  564.                     return true;
  565.                 }
  566.             });

  567.             /*
  568.              * Testing creation of the basis rate-shifted Discount Curve - implements the pre-regression, the
  569.              *  post-regression, and the actual regression functionality of the UnitRegressorExecutor class.
  570.              */

  571.             _setRegressors.add (new org.drip.regression.core.UnitRegressionExecutor ("BasisRateShiftedCurve",
  572.                 _strRegressionScenario)
  573.             {
  574.                 private static final int NUM_DC_INSTRUMENTS = 5;

  575.                 private int _aiDate[] = new int[NUM_DC_INSTRUMENTS];
  576.                 private double _adblBasis[] = new double[NUM_DC_INSTRUMENTS];
  577.                 private org.drip.state.discount.MergedDiscountForwardCurve _dcBasisShifted = null;

  578.                 @Override public boolean preRegression()
  579.                 {
  580.                     for (int i = 0; i < NUM_DC_INSTRUMENTS; ++i) {
  581.                         _adblBasis[i] = (i + 1) * 0.0001;

  582.                         _aiDate[i] = _dtStart.addYears (i + 1).julian();
  583.                     }

  584.                     return true;
  585.                 }

  586.                 @Override public boolean execRegression()
  587.                 {
  588.                     return null != (_dcBasisShifted = _dcFromFlatRate.createBasisRateShiftedCurve (_aiDate,
  589.                         _adblBasis));
  590.                 }

  591.                 @Override public boolean postRegression (
  592.                     final org.drip.regression.core.RegressionRunDetail rnvd)
  593.                 {
  594.                     double adblRate[] = new double[NUM_DC_INSTRUMENTS];
  595.                     double adblRateShifted[] = new double[NUM_DC_INSTRUMENTS];

  596.                     for (int i = 0; i < NUM_DC_INSTRUMENTS; ++i) {
  597.                         try {
  598.                             if (!org.drip.numerical.common.NumberUtil.IsValid (adblRate[i] = _dcFromFlatRate.zero
  599.                                 (_aiDate[i])))
  600.                                 return false;

  601.                             if (!org.drip.numerical.common.NumberUtil.IsValid (adblRateShifted[i] =
  602.                                 _dcBasisShifted.zero (_aiDate[i])))
  603.                                 return false;

  604.                             org.drip.analytics.date.JulianDate dt = new org.drip.analytics.date.JulianDate
  605.                                 (_aiDate[i]);

  606.                             rnvd.set ("RateBasisEmpty[" + dt + "]",
  607.                                 org.drip.numerical.common.FormatUtil.FormatDouble (adblRate[i], 1, 4, 1));

  608.                             rnvd.set ("RateBasisShifted[" + dt + "]",
  609.                                 org.drip.numerical.common.FormatUtil.FormatDouble (adblRateShifted[i], 1, 4, 1));
  610.                         } catch (java.lang.Exception e) {
  611.                             e.printStackTrace();

  612.                             return false;
  613.                         }
  614.                     }

  615.                     return true;
  616.                 }
  617.             });

  618.             /*
  619.              * Testing creation of the Tweaked Discount Curve - implements the pre-regression, the
  620.              *  post-regression, and the actual regression functionality of the UnitRegressorExecutor class.
  621.              */

  622.             _setRegressors.add (new org.drip.regression.core.UnitRegressionExecutor ("CreateTweakedCurve",
  623.                 _strRegressionScenario)
  624.             {
  625.                 private static final int NUM_DC_INSTRUMENTS = 5;

  626.                 private int _aiDate[] = new int[NUM_DC_INSTRUMENTS];
  627.                 private org.drip.state.discount.MergedDiscountForwardCurve _dcNTP = null;
  628.                 private org.drip.param.definition.ManifestMeasureTweak _ntp = null;

  629.                 @Override public boolean preRegression()
  630.                 {
  631.                     for (int i = 0; i < NUM_DC_INSTRUMENTS; ++i)
  632.                         _aiDate[i] = _dtStart.addYears (i + 1).julian();

  633.                     try {
  634.                         _ntp = new org.drip.param.definition.ManifestMeasureTweak (0, false, 0.0005);
  635.                     } catch (java.lang.Exception e) {
  636.                         e.printStackTrace();

  637.                         return false;
  638.                     }

  639.                     return true;
  640.                 }

  641.                 @Override public boolean execRegression()
  642.                 {
  643.                     return null != (_dcNTP = (org.drip.state.discount.MergedDiscountForwardCurve)
  644.                         _dcFromFlatRate.customTweakManifestMeasure ("Rate", _ntp));
  645.                 }

  646.                 @Override public boolean postRegression (
  647.                     final org.drip.regression.core.RegressionRunDetail rnvd)
  648.                 {
  649.                     double adblRate[] = new double[NUM_DC_INSTRUMENTS];
  650.                     double adblRateNTP[] = new double[NUM_DC_INSTRUMENTS];

  651.                     for (int i = 0; i < NUM_DC_INSTRUMENTS; ++i) {
  652.                         try {
  653.                             if (!org.drip.numerical.common.NumberUtil.IsValid (adblRate[i] = _dcFromFlatRate.zero
  654.                                 (_aiDate[i])))
  655.                                 return false;

  656.                             if (!org.drip.numerical.common.NumberUtil.IsValid (adblRateNTP[i] = _dcNTP.zero
  657.                                 (_aiDate[i])))
  658.                                 return false;

  659.                             org.drip.analytics.date.JulianDate dt = new org.drip.analytics.date.JulianDate
  660.                                 (_aiDate[i]);

  661.                             rnvd.set ("RateUnTweaked[" + dt + "]",
  662.                                 org.drip.numerical.common.FormatUtil.FormatDouble (adblRate[i], 1, 4, 1));

  663.                             rnvd.set ("RateTweaked[" + dt + "]",
  664.                                 org.drip.numerical.common.FormatUtil.FormatDouble (adblRateNTP[i], 1, 4, 1));

  665.                             if (!org.drip.numerical.common.NumberUtil.WithinTolerance (adblRate[i] + 0.0005,
  666.                                 adblRateNTP[i]))
  667.                                 return false;
  668.                         } catch (java.lang.Exception e) {
  669.                             e.printStackTrace();

  670.                             return false;
  671.                         }
  672.                     }

  673.                     return true;
  674.                 }
  675.             });

  676.             /*
  677.              * Testing calc of Effective DF for the Discount Curve - implements the pre-regression, the
  678.              *  post-regression, and the actual regression functionality of the UnitRegressorExecutor class.
  679.              */

  680.             _setRegressors.add (new org.drip.regression.core.UnitRegressionExecutor ("EffectiveDF",
  681.                 _strRegressionScenario)
  682.             {
  683.                 private static final int NUM_DC_INSTRUMENTS = 5;

  684.                 private int _aiDate[] = new int[NUM_DC_INSTRUMENTS];
  685.                 private double _adblDiscountFactor[] = new double[NUM_DC_INSTRUMENTS];

  686.                 @Override public boolean preRegression()
  687.                 {
  688.                     for (int i = 0; i < NUM_DC_INSTRUMENTS; ++i)
  689.                         _aiDate[i] = _dtStart.addYears (i + 1).julian();

  690.                     return true;
  691.                 }

  692.                 @Override public boolean execRegression()
  693.                 {
  694.                     for (int i = 0; i < NUM_DC_INSTRUMENTS; ++i) {
  695.                         try {
  696.                             if (!org.drip.numerical.common.NumberUtil.IsValid (_adblDiscountFactor[i] =
  697.                                 _dc.effectiveDF ((i + 1) + "Y", (i + 2) + "Y")))
  698.                                 return false;
  699.                         } catch (java.lang.Exception e) {
  700.                             e.printStackTrace();

  701.                             return false;
  702.                         }
  703.                     }

  704.                     return true;
  705.                 }

  706.                 @Override public boolean postRegression (
  707.                     final org.drip.regression.core.RegressionRunDetail rnvd)
  708.                 {
  709.                     for (int i = 0; i < NUM_DC_INSTRUMENTS; ++i) {
  710.                         try {
  711.                             rnvd.set ("Effective[" + new org.drip.analytics.date.JulianDate (_aiDate[i]) +
  712.                                 "]", org.drip.numerical.common.FormatUtil.FormatDouble (_adblDiscountFactor[i],
  713.                                     1, 4, 1));
  714.                         } catch (java.lang.Exception e) {
  715.                             e.printStackTrace();

  716.                             return false;
  717.                         }
  718.                     }

  719.                     return true;
  720.                 }
  721.             });

  722.             /*
  723.              * Testing calc of Effective Rate for the Discount Curve - implements the pre-regression, the
  724.              *  post-regression, and the actual regression functionality of the UnitRegressorExecutor class.
  725.              */

  726.             _setRegressors.add (new org.drip.regression.core.UnitRegressionExecutor ("CalcImpliedRate",
  727.                 _strRegressionScenario)
  728.             {
  729.                 private static final int NUM_DC_INSTRUMENTS = 5;

  730.                 private int _aiDate[] = new int[NUM_DC_INSTRUMENTS];
  731.                 private double _adblImpliedRate[] = new double[NUM_DC_INSTRUMENTS];

  732.                 @Override public boolean preRegression()
  733.                 {
  734.                     for (int i = 0; i < NUM_DC_INSTRUMENTS; ++i)
  735.                         _aiDate[i] = _dtStart.addYears (i + 1).julian();

  736.                     return true;
  737.                 }

  738.                 @Override public boolean execRegression()
  739.                 {
  740.                     for (int i = 0; i < NUM_DC_INSTRUMENTS; ++i) {
  741.                         try {
  742.                             if (!org.drip.numerical.common.NumberUtil.IsValid (_adblImpliedRate[i] = _dc.forward
  743.                                 ((i + 1) + "Y", (i + 2) + "Y")))
  744.                                 return false;
  745.                         } catch (java.lang.Exception e) {
  746.                             e.printStackTrace();

  747.                             return false;
  748.                         }
  749.                     }

  750.                     return true;
  751.                 }

  752.                 @Override public boolean postRegression (
  753.                     final org.drip.regression.core.RegressionRunDetail rnvd)
  754.                 {
  755.                     for (int i = 0; i < NUM_DC_INSTRUMENTS; ++i) {
  756.                         try {
  757.                             rnvd.set ("ImpliedRate[" + new org.drip.analytics.date.JulianDate (_aiDate[i])
  758.                                 + "]", org.drip.numerical.common.FormatUtil.FormatDouble (_adblImpliedRate[i], 1,
  759.                                     4, 1));
  760.                         } catch (java.lang.Exception e) {
  761.                             e.printStackTrace();

  762.                             return false;
  763.                         }
  764.                     }

  765.                     return true;
  766.                 }
  767.             });
  768.         } catch (java.lang.Exception e) {
  769.             e.printStackTrace();

  770.             return false;
  771.         }

  772.         return true;
  773.     }

  774.     @Override public java.util.List<org.drip.regression.core.UnitRegressor> getRegressorSet()
  775.     {
  776.         return _setRegressors;
  777.     }

  778.     @Override public java.lang.String getSetName()
  779.     {
  780.         return _strRegressionScenario;
  781.     }
  782. }