ProductQuoteSet.java

  1. package org.drip.product.calib;

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

  79. /**
  80.  * <i>ProductQuoteSet</i> implements the Calibratable type-free Product Quote Shell. The derived calibration
  81.  * sets provide custom accessors.
  82.  *
  83.  *  <br><br>
  84.  *  <ul>
  85.  *      <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/ProductCore.md">Product Core Module</a></li>
  86.  *      <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/FixedIncomeAnalyticsLibrary.md">Fixed Income Analytics</a></li>
  87.  *      <li><b>Project</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/product/README.md">Product Components/Baskets for Credit, FRA, FX, Govvie, Rates, and Option AssetClasses</a></li>
  88.  *      <li><b>Package</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/product/calib/README.md">Curve/Surface Calibration Quote Sets</a></li>
  89.  *  </ul>
  90.  * <br><br>
  91.  *
  92.  * @author Lakshmi Krishnamurthy
  93.  */

  94. public class ProductQuoteSet {
  95.     private org.drip.state.representation.LatentStateSpecification[] _aLSS = null;

  96.     private org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double> _mapQuote = new
  97.         org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double>();

  98.     /**
  99.      * Product Quote Set Constructor
  100.      *
  101.      * @param aLSS Array of Latent State Specifications
  102.      *
  103.      * @throws java.lang.Exception Thrown if the Inputs are Invalid
  104.      */

  105.     public ProductQuoteSet (
  106.         final org.drip.state.representation.LatentStateSpecification[] aLSS)
  107.         throws java.lang.Exception
  108.     {
  109.         if (null == (_aLSS = aLSS)) throw new java.lang.Exception ("ProductQuoteSet ctr: Invalid Inputs");

  110.         int iNumLSS = _aLSS.length;

  111.         if (0 == iNumLSS) throw new java.lang.Exception ("ProductQuoteSet ctr: Invalid Inputs");

  112.         for (int i = 0; i < iNumLSS; ++i) {
  113.             if (null == _aLSS[i]) throw new java.lang.Exception ("ProductQuoteSet ctr: Invalid Inputs");
  114.         }
  115.     }

  116.     /**
  117.      * Retrieve the Array of Latent State Specification
  118.      *
  119.      * @return The Array of Latent State Specification
  120.      */

  121.     public org.drip.state.representation.LatentStateSpecification[] lss()
  122.     {
  123.         return _aLSS;
  124.     }

  125.     /**
  126.      * Indicate if the requested Latent State Type is contained in the Quote Set
  127.      *
  128.      * @param strLatentStateType The Requested Latent State Type
  129.      *
  130.      * @return TRUE - The requested Latent State Type is contained in the Quote Set
  131.      */

  132.     public boolean containsLatentStateType (
  133.         final java.lang.String strLatentStateType)
  134.     {
  135.         if (null == strLatentStateType || strLatentStateType.isEmpty()) return false;

  136.         for (org.drip.state.representation.LatentStateSpecification lss : _aLSS) {
  137.             if (lss.latentState().equalsIgnoreCase (strLatentStateType)) return true;
  138.         }

  139.         return false;
  140.     }

  141.     /**
  142.      * Retrieve the Forward Latent State Label, if it exists
  143.      *
  144.      * @return The Forward Latent State Label
  145.      */

  146.     public org.drip.state.identifier.ForwardLabel forwardLabel()
  147.     {
  148.         for (org.drip.state.representation.LatentStateSpecification lss : _aLSS) {
  149.             if (lss.latentState().equalsIgnoreCase
  150.                 (org.drip.analytics.definition.LatentStateStatic.LATENT_STATE_FORWARD))
  151.                 return (org.drip.state.identifier.ForwardLabel) lss.label();
  152.         }

  153.         return null;
  154.     }

  155.     /**
  156.      * Retrieve the Funding Latent State Label, if it exists
  157.      *
  158.      * @return The Funding Latent State Label
  159.      */

  160.     public org.drip.state.identifier.FundingLabel fundingLabel()
  161.     {
  162.         for (org.drip.state.representation.LatentStateSpecification lss : _aLSS) {
  163.             if (lss.latentState().equalsIgnoreCase
  164.                 (org.drip.analytics.definition.LatentStateStatic.LATENT_STATE_FUNDING))
  165.                 return (org.drip.state.identifier.FundingLabel) lss.label();
  166.         }

  167.         return null;
  168.     }

  169.     /**
  170.      * Retrieve the FX Latent State Label, if it exists
  171.      *
  172.      * @return The FX Latent State Label
  173.      */

  174.     public org.drip.state.identifier.FXLabel fxLabel()
  175.     {
  176.         for (org.drip.state.representation.LatentStateSpecification lss : _aLSS) {
  177.             if (lss.latentState().equalsIgnoreCase
  178.                 (org.drip.analytics.definition.LatentStateStatic.LATENT_STATE_FX))
  179.                 return (org.drip.state.identifier.FXLabel) lss.label();
  180.         }

  181.         return null;
  182.     }

  183.     /**
  184.      * Retrieve the Govvie Latent State Label, if it exists
  185.      *
  186.      * @return The Govvie Latent State Label
  187.      */

  188.     public org.drip.state.identifier.GovvieLabel govvieLabel()
  189.     {
  190.         for (org.drip.state.representation.LatentStateSpecification lss : _aLSS) {
  191.             if (lss.latentState().equalsIgnoreCase
  192.                 (org.drip.analytics.definition.LatentStateStatic.LATENT_STATE_GOVVIE))
  193.                 return (org.drip.state.identifier.GovvieLabel) lss.label();
  194.         }

  195.         return null;
  196.     }

  197.     /**
  198.      * Retrieve the Volatility Latent State Label, if it exists
  199.      *
  200.      * @return The Volatility Latent State Label
  201.      */

  202.     public org.drip.state.identifier.VolatilityLabel volatilityLabel()
  203.     {
  204.         for (org.drip.state.representation.LatentStateSpecification lss : _aLSS) {
  205.             if (lss.latentState().equalsIgnoreCase
  206.                 (org.drip.analytics.definition.LatentStateStatic.LATENT_STATE_VOLATILITY))
  207.                 return (org.drip.state.identifier.VolatilityLabel) lss.label();
  208.         }

  209.         return null;
  210.     }

  211.     /**
  212.      * Indicate if the requested Latent State Quantification Metric is contained in the Quote Set
  213.      *
  214.      * @param strLatentStateQuantificationMetric The Requested Latent State Quantification Metric
  215.      *
  216.      * @return TRUE - The requested Latent State Quantification Metric is contained in the Quote Set
  217.      */

  218.     public boolean containsLatentStateQuantificationMetric (
  219.         final java.lang.String strLatentStateQuantificationMetric)
  220.     {
  221.         if (null == strLatentStateQuantificationMetric || strLatentStateQuantificationMetric.isEmpty())
  222.             return false;

  223.         for (org.drip.state.representation.LatentStateSpecification lss : _aLSS) {
  224.             if (lss.latentStateQuantificationMetric().equalsIgnoreCase (strLatentStateQuantificationMetric))
  225.                 return true;
  226.         }

  227.         return false;
  228.     }

  229.     /**
  230.      * Indicate if the Specified External Latent State Specification is contained in the Array
  231.      *
  232.      * @param strLatentState The Latent State
  233.      * @param strLatentStateQuantificationMetric The Latent State Quantification Metric
  234.      * @param label The Specific Latent State Label
  235.      *
  236.      * @return TRUE - The Specified External Latent State Specification is contained in the Array
  237.      */

  238.     public boolean contains (
  239.         final java.lang.String strLatentState,
  240.         final java.lang.String strLatentStateQuantificationMetric,
  241.         final org.drip.state.identifier.LatentStateLabel label)
  242.     {
  243.         org.drip.state.representation.LatentStateSpecification lssExternal = null;

  244.         try {
  245.             lssExternal = new org.drip.state.representation.LatentStateSpecification (strLatentState,
  246.                 strLatentStateQuantificationMetric, label);
  247.         } catch (java.lang.Exception e) {
  248.             e.printStackTrace();

  249.             return false;
  250.         }

  251.         for (org.drip.state.representation.LatentStateSpecification lss : _aLSS) {
  252.             if (lss.match (lssExternal)) return true;
  253.         }

  254.         return false;
  255.     }

  256.     /**
  257.      * Set the named Manifest Measure Quote Value
  258.      *
  259.      * @param strManifestMeasure The Manifest Measure
  260.      * @param dblManifestMeasureQuote The Quote Value
  261.      *
  262.      * @return TRUE - The Manifest Measure Quote Value successfully set
  263.      */

  264.     public boolean set (
  265.         final java.lang.String strManifestMeasure,
  266.         final double dblManifestMeasureQuote)
  267.     {
  268.         if (null == strManifestMeasure || strManifestMeasure.isEmpty() ||
  269.             !org.drip.numerical.common.NumberUtil.IsValid (dblManifestMeasureQuote))
  270.             return false;

  271.         _mapQuote.put (strManifestMeasure, dblManifestMeasureQuote);

  272.         return true;
  273.     }

  274.     /**
  275.      * Retrieve the Quote corresponding to the Specified Manifest Measure
  276.      *
  277.      * @param strManifestMeasure The Manifest Measure
  278.      *
  279.      * @return The Corresponding Quote
  280.      *
  281.      * @throws java.lang.Exception Thrown if the Quote cannot be extracted
  282.      */

  283.     public double get (
  284.         final java.lang.String strManifestMeasure)
  285.         throws java.lang.Exception
  286.     {
  287.         if (null == strManifestMeasure || strManifestMeasure.isEmpty() || !_mapQuote.containsKey
  288.             (strManifestMeasure))
  289.             throw new java.lang.Exception ("ProductQuoteSet::get - Invalid Inputs");

  290.         return _mapQuote.get (strManifestMeasure);
  291.     }

  292.     /**
  293.      * Indicate if the Manifest Measure is available
  294.      *
  295.      * @param strManifestMeasure The Manifest Measure
  296.      *
  297.      * @return TRUE - The Manifest Measure is Available
  298.      */

  299.     public boolean contains (
  300.         final java.lang.String strManifestMeasure)
  301.     {
  302.         return null != strManifestMeasure && !strManifestMeasure.isEmpty() && _mapQuote.containsKey
  303.             (strManifestMeasure);
  304.     }

  305.     /**
  306.      * Return the Set of Fields Available
  307.      *
  308.      * @return The Set of Fields Available
  309.      */

  310.     public java.util.Set<java.lang.String> fields()
  311.     {
  312.         return _mapQuote.keySet();
  313.     }
  314. }