LatentStateStretchBuilder.java

  1. package org.drip.state.estimator;

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

  78. /**
  79.  * <i>LatentStateStretchBuilder</i> contains the Functionality to construct the Curve Latent State Stretch
  80.  * for the different Latent States.
  81.  *
  82.  *  <br><br>
  83.  *  <ul>
  84.  *      <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/ProductCore.md">Product Core Module</a></li>
  85.  *      <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/FixedIncomeAnalyticsLibrary.md">Fixed Income Analytics</a></li>
  86.  *      <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>
  87.  *      <li><b>Package</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/state/estimator/README.md">Multi-Pass Customized Stretch Curve</a></li>
  88.  *  </ul>
  89.  * <br><br>
  90.  *
  91.  * @author Lakshmi Krishnamurthy
  92.  */

  93. public class LatentStateStretchBuilder {

  94.     /**
  95.      * Construct a Forward Latent State Stretch Spec Instance
  96.      *
  97.      * @param strName Stretch Name
  98.      * @param aCalibComp Array of Calibration Components
  99.      * @param astrCalibMeasure Array of the Calibration Measures
  100.      * @param adblCalibQuote Array of the Calibration Quotes
  101.      *
  102.      * @return Forward Latent State Stretch Spec Instance
  103.      */

  104.     public static final org.drip.state.inference.LatentStateStretchSpec ForwardStretchSpec (
  105.         final java.lang.String strName,
  106.         final org.drip.product.definition.CalibratableComponent[] aCalibComp,
  107.         final java.lang.String[] astrCalibMeasure,
  108.         final double[] adblCalibQuote)
  109.     {
  110.         if (null == aCalibComp || null == astrCalibMeasure || null == adblCalibQuote) return null;

  111.         int iNumComp = aCalibComp.length;
  112.         org.drip.state.inference.LatentStateSegmentSpec[] aLSSS = new
  113.             org.drip.state.inference.LatentStateSegmentSpec[iNumComp];

  114.         if (0 == iNumComp || iNumComp != astrCalibMeasure.length || iNumComp != adblCalibQuote.length)
  115.             return null;

  116.         try {
  117.             for (int i = 0; i < iNumComp; ++i) {
  118.                 if (null == aCalibComp[i] || null == astrCalibMeasure[i] || astrCalibMeasure[i].isEmpty() ||
  119.                     !org.drip.numerical.common.NumberUtil.IsValid (adblCalibQuote[i]))
  120.                     return null;

  121.                 org.drip.analytics.support.CaseInsensitiveTreeMap<org.drip.state.identifier.ForwardLabel>
  122.                     mapForwardLabel = aCalibComp[i].forwardLabel();

  123.                 if (null == mapForwardLabel || 0 == mapForwardLabel.size()) return null;

  124.                 org.drip.product.calib.ProductQuoteSet pqs = aCalibComp[i].calibQuoteSet (new
  125.                     org.drip.state.representation.LatentStateSpecification[] {new
  126.                         org.drip.state.representation.LatentStateSpecification
  127.                             (org.drip.analytics.definition.LatentStateStatic.LATENT_STATE_FORWARD,
  128.                                 org.drip.analytics.definition.LatentStateStatic.FORWARD_QM_FORWARD_RATE,
  129.                                     mapForwardLabel.get ("DERIVED"))});

  130.                 if (null == pqs || !pqs.set (astrCalibMeasure[i], adblCalibQuote[i])) return null;

  131.                 aLSSS[i] = new org.drip.state.inference.LatentStateSegmentSpec (aCalibComp[i], pqs);
  132.             }

  133.             return new org.drip.state.inference.LatentStateStretchSpec (strName, aLSSS);
  134.         } catch (java.lang.Exception e) {
  135.             e.printStackTrace();
  136.         }

  137.         return null;
  138.     }

  139.     /**
  140.      * Construct a Merged Forward-Funding Latent State Stretch Spec Instance
  141.      *
  142.      * @param strName Stretch Name
  143.      * @param aCalibComp Array of Calibration Components
  144.      * @param astrCalibMeasure Array of the Calibration Measures
  145.      * @param adblCalibQuote Array of the Calibration Quotes
  146.      *
  147.      * @return Merged Forward-Funding Latent State Stretch Spec Instance
  148.      */

  149.     public static final org.drip.state.inference.LatentStateStretchSpec ForwardFundingStretchSpec (
  150.         final java.lang.String strName,
  151.         final org.drip.product.definition.CalibratableComponent[] aCalibComp,
  152.         final java.lang.String[] astrCalibMeasure,
  153.         final double[] adblCalibQuote)
  154.     {
  155.         if (null == aCalibComp || null == astrCalibMeasure || null == adblCalibQuote) return null;

  156.         int iNumComp = aCalibComp.length;
  157.         org.drip.state.inference.LatentStateSegmentSpec[] aLSSS = new
  158.             org.drip.state.inference.LatentStateSegmentSpec[iNumComp];

  159.         if (0 == iNumComp || iNumComp != astrCalibMeasure.length || iNumComp != adblCalibQuote.length)
  160.             return null;

  161.         try {
  162.             for (int i = 0; i < iNumComp; ++i) {
  163.                 if (null == aCalibComp[i] || null == astrCalibMeasure[i] || astrCalibMeasure[i].isEmpty() ||
  164.                     !org.drip.numerical.common.NumberUtil.IsValid (adblCalibQuote[i]))
  165.                     return null;

  166.                 org.drip.analytics.support.CaseInsensitiveTreeMap<org.drip.state.identifier.ForwardLabel>
  167.                     mapForwardLabel = aCalibComp[i].forwardLabel();

  168.                 if (null == mapForwardLabel || 0 == mapForwardLabel.size()) return null;

  169.                 org.drip.product.calib.ProductQuoteSet pqs = aCalibComp[i].calibQuoteSet (new
  170.                     org.drip.state.representation.LatentStateSpecification[] {new
  171.                         org.drip.state.representation.LatentStateSpecification
  172.                             (org.drip.analytics.definition.LatentStateStatic.LATENT_STATE_FUNDING,
  173.                                 org.drip.analytics.definition.LatentStateStatic.DISCOUNT_QM_DISCOUNT_FACTOR,
  174.                     org.drip.state.identifier.FundingLabel.Standard (aCalibComp[i].payCurrency())), new
  175.                         org.drip.state.representation.LatentStateSpecification
  176.                             (org.drip.analytics.definition.LatentStateStatic.LATENT_STATE_FORWARD,
  177.                                 org.drip.analytics.definition.LatentStateStatic.FORWARD_QM_FORWARD_RATE,
  178.                                     mapForwardLabel.get ("DERIVED"))});

  179.                 if (null == pqs || !pqs.set (astrCalibMeasure[i], adblCalibQuote[i])) return null;

  180.                 aLSSS[i] = new org.drip.state.inference.LatentStateSegmentSpec (aCalibComp[i], pqs);
  181.             }

  182.             return new org.drip.state.inference.LatentStateStretchSpec (strName, aLSSS);
  183.         } catch (java.lang.Exception e) {
  184.             e.printStackTrace();
  185.         }

  186.         return null;
  187.     }

  188.     /**
  189.      * Construct a Funding Latent State Stretch Spec Instance
  190.      *
  191.      * @param strName Stretch Name
  192.      * @param aCalibComp Array of Calibration Components
  193.      * @param astrCalibMeasure Array of the Calibration Measures
  194.      * @param adblCalibQuote Array of the Calibration Quotes
  195.      *
  196.      * @return Funding Latent State Stretch Spec Instance
  197.      */

  198.     public static final org.drip.state.inference.LatentStateStretchSpec FundingStretchSpec (
  199.         final java.lang.String strName,
  200.         final org.drip.product.definition.CalibratableComponent[] aCalibComp,
  201.         final java.lang.String[] astrCalibMeasure,
  202.         final double[] adblCalibQuote)
  203.     {
  204.         if (null == aCalibComp || null == astrCalibMeasure || null == adblCalibQuote) return null;

  205.         int iNumComp = aCalibComp.length;
  206.         org.drip.state.inference.LatentStateSegmentSpec[] aLSSS = new
  207.             org.drip.state.inference.LatentStateSegmentSpec[iNumComp];

  208.         if (0 == iNumComp || iNumComp != astrCalibMeasure.length || iNumComp != adblCalibQuote.length)
  209.             return null;

  210.         try {
  211.             for (int i = 0; i < iNumComp; ++i) {
  212.                 if (null == aCalibComp[i] || null == astrCalibMeasure[i] || astrCalibMeasure[i].isEmpty() ||
  213.                     !org.drip.numerical.common.NumberUtil.IsValid (adblCalibQuote[i]))
  214.                     return null;

  215.                 org.drip.analytics.support.CaseInsensitiveTreeMap<org.drip.state.identifier.ForwardLabel>
  216.                     mapForwardLabel = aCalibComp[i].forwardLabel();

  217.                 if (null == mapForwardLabel || 0 == mapForwardLabel.size()) return null;

  218.                 org.drip.product.calib.ProductQuoteSet pqs = aCalibComp[i].calibQuoteSet (new
  219.                     org.drip.state.representation.LatentStateSpecification[] {new
  220.                         org.drip.state.representation.LatentStateSpecification
  221.                             (org.drip.analytics.definition.LatentStateStatic.LATENT_STATE_FUNDING,
  222.                                 org.drip.analytics.definition.LatentStateStatic.DISCOUNT_QM_DISCOUNT_FACTOR,
  223.                                     org.drip.state.identifier.FundingLabel.Standard
  224.                                         (aCalibComp[i].payCurrency()))});

  225.                 if (null == pqs || !pqs.set (astrCalibMeasure[i], adblCalibQuote[i])) return null;

  226.                 aLSSS[i] = new org.drip.state.inference.LatentStateSegmentSpec (aCalibComp[i], pqs);
  227.             }

  228.             return new org.drip.state.inference.LatentStateStretchSpec (strName, aLSSS);
  229.         } catch (java.lang.Exception e) {
  230.             e.printStackTrace();
  231.         }

  232.         return null;
  233.     }

  234.     /**
  235.      * Construct a Forward Latent State Stretch Spec Instance
  236.      *
  237.      * @param strName Stretch Name
  238.      * @param aCalibComp Array of Calibration Components
  239.      * @param strCalibMeasure The Calibration Measure
  240.      * @param adblCalibQuote Array of the Calibration Quotes
  241.      *
  242.      * @return Forward Latent State Stretch Spec Instance
  243.      */

  244.     public static final org.drip.state.inference.LatentStateStretchSpec ForwardStretchSpec (
  245.         final java.lang.String strName,
  246.         final org.drip.product.definition.CalibratableComponent[] aCalibComp,
  247.         final java.lang.String strCalibMeasure,
  248.         final double[] adblCalibQuote)
  249.     {
  250.         if (null == strCalibMeasure || strCalibMeasure.isEmpty() || null == adblCalibQuote) return null;

  251.         int iNumComp = adblCalibQuote.length;
  252.         java.lang.String[] astrCalibMeasure = new java.lang.String[iNumComp];

  253.         for (int i = 0; i < iNumComp; ++i)
  254.             astrCalibMeasure[i] = strCalibMeasure;

  255.         return ForwardStretchSpec (strName, aCalibComp, astrCalibMeasure, adblCalibQuote);
  256.     }

  257.     /**
  258.      * Construct a Merged Forward-Funding Latent State Stretch Spec Instance
  259.      *
  260.      * @param strName Stretch Name
  261.      * @param aCalibComp Array of Calibration Components
  262.      * @param strCalibMeasure The Calibration Measure
  263.      * @param adblCalibQuote Array of the Calibration Quotes
  264.      *
  265.      * @return Merged Forward-Funding Latent State Stretch Spec Instance
  266.      */

  267.     public static final org.drip.state.inference.LatentStateStretchSpec ForwardFundingStretchSpec (
  268.         final java.lang.String strName,
  269.         final org.drip.product.definition.CalibratableComponent[] aCalibComp,
  270.         final java.lang.String strCalibMeasure,
  271.         final double[] adblCalibQuote)
  272.     {
  273.         if (null == strCalibMeasure || strCalibMeasure.isEmpty() || null == adblCalibQuote) return null;

  274.         int iNumComp = adblCalibQuote.length;
  275.         java.lang.String[] astrCalibMeasure = new java.lang.String[iNumComp];

  276.         for (int i = 0; i < iNumComp; ++i)
  277.             astrCalibMeasure[i] = strCalibMeasure;

  278.         return ForwardFundingStretchSpec (strName, aCalibComp, astrCalibMeasure, adblCalibQuote);
  279.     }

  280.     /**
  281.      * Construct a Funding Latent State Stretch Spec Instance
  282.      *
  283.      * @param strName Stretch Name
  284.      * @param aCalibComp Array of Calibration Components
  285.      * @param strCalibMeasure The Calibration Measure
  286.      * @param adblCalibQuote Array of the Calibration Quotes
  287.      *
  288.      * @return Funding Latent State Stretch Spec Instance
  289.      */

  290.     public static final org.drip.state.inference.LatentStateStretchSpec FundingStretchSpec (
  291.         final java.lang.String strName,
  292.         final org.drip.product.definition.CalibratableComponent[] aCalibComp,
  293.         final java.lang.String strCalibMeasure,
  294.         final double[] adblCalibQuote)
  295.     {
  296.         if (null == strCalibMeasure || strCalibMeasure.isEmpty() || null == adblCalibQuote) return null;

  297.         int iNumComp = adblCalibQuote.length;
  298.         java.lang.String[] astrCalibMeasure = new java.lang.String[iNumComp];

  299.         for (int i = 0; i < iNumComp; ++i)
  300.             astrCalibMeasure[i] = strCalibMeasure;

  301.         return FundingStretchSpec (strName, aCalibComp, astrCalibMeasure, adblCalibQuote);
  302.     }

  303.     /**
  304.      * Construct an instance of LatentStateStretchSpec for the Construction of the Forward Curve from the
  305.      *  specified Inputs
  306.      *
  307.      * @param strName Stretch Name
  308.      * @param aCCSP Array of Calibration Cross Currency Swap Pair Instances
  309.      * @param valParams The Valuation Parameters
  310.      * @param mktParams The Basket Market Parameters to imply the Market Quote Measure
  311.      * @param adblBasis Array of the Basis on either the Reference Component or the Derived Component
  312.      * @param bBasisOnDerivedComponent TRUE - Apply the Basis on the Derived Component
  313.      * @param bBasisOnDerivedStream TRUE - Apply the Basis on the Derived Stream (FALSE - Reference Stream)
  314.      *
  315.      * @return Instance of LatentStateStretchSpec
  316.      */

  317.     public static final org.drip.state.inference.LatentStateStretchSpec ComponentPairForwardStretch (
  318.         final java.lang.String strName,
  319.         final org.drip.product.fx.ComponentPair[] aCCSP,
  320.         final org.drip.param.valuation.ValuationParams valParams,
  321.         final org.drip.param.market.CurveSurfaceQuoteContainer mktParams,
  322.         final double[] adblBasis,
  323.         final boolean bBasisOnDerivedComponent,
  324.         final boolean bBasisOnDerivedStream)
  325.     {
  326.         if (null == aCCSP || null == mktParams || null == adblBasis) return null;

  327.         int iNumCCSP = aCCSP.length;

  328.         if (0 == iNumCCSP || adblBasis.length != iNumCCSP) return null;

  329.         org.drip.state.inference.LatentStateSegmentSpec[] aSegmentSpec = new
  330.             org.drip.state.inference.LatentStateSegmentSpec[iNumCCSP];

  331.         for (int i = 0; i < iNumCCSP; ++i) {
  332.             if (null == aCCSP[i]) return null;

  333.             try {
  334.                 if (null == (aSegmentSpec[i] = aCCSP[i].derivedForwardSpec (valParams, mktParams,
  335.                     adblBasis[i], bBasisOnDerivedComponent, bBasisOnDerivedStream)))
  336.                     return null;
  337.             } catch (java.lang.Exception e) {
  338.                 e.printStackTrace();

  339.                 return null;
  340.             }
  341.         }

  342.         try {
  343.             return new org.drip.state.inference.LatentStateStretchSpec (strName, aSegmentSpec);
  344.         } catch (java.lang.Exception e) {
  345.             e.printStackTrace();
  346.         }

  347.         return null;
  348.     }

  349.     /**
  350.      * Construct an instance of LatentStateStretchSpec for the Construction of the Discount Curve from the
  351.      *  specified Inputs
  352.      *
  353.      * @param strName Stretch Name
  354.      * @param aCCSP Array of Calibration Cross Currency Swap Pair Instances
  355.      * @param valParams The Valuation Parameters
  356.      * @param mktParams The Basket Market Parameters to imply the Market Quote Measure
  357.      * @param adblReferenceComponentBasis Array of the Reference Component Reference Leg Basis Spread
  358.      * @param adblSwapRate Array of the IRS Calibration Swap Rates
  359.      * @param bBasisOnDerivedLeg TRUE - Apply the Basis on the Derived Leg (FALSE - Reference Leg)
  360.      *
  361.      * @return Instance of LatentStateStretchSpec
  362.      */

  363.     public static final org.drip.state.inference.LatentStateStretchSpec ComponentPairDiscountStretch (
  364.         final java.lang.String strName,
  365.         final org.drip.product.fx.ComponentPair[] aCCSP,
  366.         final org.drip.param.valuation.ValuationParams valParams,
  367.         final org.drip.param.market.CurveSurfaceQuoteContainer mktParams,
  368.         final double[] adblReferenceComponentBasis,
  369.         final double[] adblSwapRate,
  370.         final boolean bBasisOnDerivedLeg)
  371.     {
  372.         if (null == aCCSP || null == mktParams || null == adblReferenceComponentBasis || null ==
  373.             adblSwapRate)
  374.             return null;

  375.         int iNumCCSP = aCCSP.length;

  376.         if (0 == iNumCCSP || adblReferenceComponentBasis.length != iNumCCSP || adblSwapRate.length !=
  377.             iNumCCSP)
  378.             return null;

  379.         org.drip.state.inference.LatentStateSegmentSpec[] aSegmentSpec = new
  380.             org.drip.state.inference.LatentStateSegmentSpec[iNumCCSP];

  381.         for (int i = 0; i < iNumCCSP; ++i) {
  382.             if (null == (aSegmentSpec[i] = aCCSP[i].derivedFundingForwardSpec (valParams, mktParams,
  383.                 adblReferenceComponentBasis[i], bBasisOnDerivedLeg, adblSwapRate[i])))
  384.                 return null;
  385.         }

  386.         try {
  387.             return new org.drip.state.inference.LatentStateStretchSpec (strName, aSegmentSpec);
  388.         } catch (java.lang.Exception e) {
  389.             e.printStackTrace();
  390.         }

  391.         return null;
  392.     }

  393.     /**
  394.      * Construct a FX Latent State Stretch Spec Instance
  395.      *
  396.      * @param strName Stretch Name
  397.      * @param aCalibComp Array of Calibration Components
  398.      * @param astrCalibMeasure Array of the Calibration Measures
  399.      * @param adblCalibQuote Array of the Calibration Quotes
  400.      *
  401.      * @return FX Latent State Stretch Spec Instance
  402.      */

  403.     public static final org.drip.state.inference.LatentStateStretchSpec FXStretchSpec (
  404.         final java.lang.String strName,
  405.         final org.drip.product.definition.CalibratableComponent[] aCalibComp,
  406.         final java.lang.String[] astrCalibMeasure,
  407.         final double[] adblCalibQuote)
  408.     {
  409.         if (null == aCalibComp || null == astrCalibMeasure || null == adblCalibQuote) return null;

  410.         int iNumComp = aCalibComp.length;
  411.         org.drip.state.inference.LatentStateSegmentSpec[] aLSSS = new
  412.             org.drip.state.inference.LatentStateSegmentSpec[iNumComp];

  413.         if (0 == iNumComp || iNumComp != astrCalibMeasure.length || iNumComp != adblCalibQuote.length)
  414.             return null;

  415.         try {
  416.             for (int i = 0; i < iNumComp; ++i) {
  417.                 if (null == aCalibComp[i] || null == astrCalibMeasure[i] || astrCalibMeasure[i].isEmpty() ||
  418.                     !org.drip.numerical.common.NumberUtil.IsValid (adblCalibQuote[i]))
  419.                     return null;

  420.                 org.drip.analytics.support.CaseInsensitiveTreeMap<org.drip.state.identifier.FXLabel>
  421.                     mapFXLabel = aCalibComp[i].fxLabel();

  422.                 if (null == mapFXLabel || 0 == mapFXLabel.size()) return null;

  423.                 org.drip.product.calib.ProductQuoteSet pqs = aCalibComp[i].calibQuoteSet (new
  424.                     org.drip.state.representation.LatentStateSpecification[] {new
  425.                         org.drip.state.representation.LatentStateSpecification
  426.                             (org.drip.analytics.definition.LatentStateStatic.LATENT_STATE_FX,
  427.                                 org.drip.analytics.definition.LatentStateStatic.FX_QM_FORWARD_OUTRIGHT,
  428.                                     mapFXLabel.get ("DERIVED"))});

  429.                 if (null == pqs || !pqs.set (astrCalibMeasure[i], adblCalibQuote[i])) return null;

  430.                 aLSSS[i] = new org.drip.state.inference.LatentStateSegmentSpec (aCalibComp[i], pqs);
  431.             }

  432.             return new org.drip.state.inference.LatentStateStretchSpec (strName, aLSSS);
  433.         } catch (java.lang.Exception e) {
  434.             e.printStackTrace();
  435.         }

  436.         return null;
  437.     }

  438.     /**
  439.      * Construct a FX Latent State Stretch Spec Instance
  440.      *
  441.      * @param strName Stretch Name
  442.      * @param aCalibComp Array of Calibration Components
  443.      * @param strCalibMeasure The Calibration Measure
  444.      * @param adblCalibQuote Array of the Calibration Quotes
  445.      *
  446.      * @return FX Latent State Stretch Spec Instance
  447.      */

  448.     public static final org.drip.state.inference.LatentStateStretchSpec FXStretchSpec (
  449.         final java.lang.String strName,
  450.         final org.drip.product.definition.CalibratableComponent[] aCalibComp,
  451.         final java.lang.String strCalibMeasure,
  452.         final double[] adblCalibQuote)
  453.     {
  454.         if (null == strCalibMeasure || strCalibMeasure.isEmpty() || null == adblCalibQuote) return null;

  455.         int iNumComp = adblCalibQuote.length;
  456.         java.lang.String[] astrCalibMeasure = new java.lang.String[iNumComp];

  457.         for (int i = 0; i < iNumComp; ++i)
  458.             astrCalibMeasure[i] = strCalibMeasure;

  459.         return FXStretchSpec (strName, aCalibComp, astrCalibMeasure, adblCalibQuote);
  460.     }
  461. }