InstrumentSetTenorQuote.java

  1. package org.drip.feed.loader;

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

  77. /**
  78.  * <i>InstrumentSetTenorQuote</i> holds the Instrument Set Tenor and Closing Quote Group.
  79.  *
  80.  *  <br><br>
  81.  *  <ul>
  82.  *      <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/ComputationalCore.md">Computational Core Module</a></li>
  83.  *      <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/ComputationSupportLibrary.md">Computation Support</a></li>
  84.  *      <li><b>Project</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/feed/README.md">Load, Transform, and compute Target Metrics across Feeds</a></li>
  85.  *      <li><b>Package</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/feed/loader/README.md">Reference/Market Data Feed Loader</a></li>
  86.  *  </ul>
  87.  *
  88.  * @author Lakshmi Krishnamurthy
  89.  */

  90. public class InstrumentSetTenorQuote {
  91.     private org.drip.analytics.support.CaseInsensitiveHashMap<java.util.Map<java.lang.Integer,
  92.         org.drip.feed.loader.TenorQuote>> _mapOrderedInstrumentTenorQuote = new
  93.             org.drip.analytics.support.CaseInsensitiveHashMap<java.util.Map<java.lang.Integer,
  94.                 org.drip.feed.loader.TenorQuote>>();

  95.     /**
  96.      * Empty InstrumentSetTenorQuote Constructor
  97.      */

  98.     public InstrumentSetTenorQuote()
  99.     {
  100.     }

  101.     /**
  102.      * Add the Instrument/Tenor/Quote/Scale Field Set
  103.      *
  104.      * @param strInstrument Quote Instrument
  105.      * @param strTenor Quote Tenor
  106.      * @param dblQuote Quote Value
  107.      * @param dblScale Quote Scale
  108.      *
  109.      * @return TRUE - Group Set successfully added
  110.      */

  111.     public boolean add (
  112.         final java.lang.String strInstrument,
  113.         final java.lang.String strTenor,
  114.         final double dblQuote,
  115.         final double dblScale)
  116.     {
  117.         int iTenorDays = -1;
  118.         org.drip.feed.loader.TenorQuote tq = null;

  119.         try {
  120.             tq = new org.drip.feed.loader.TenorQuote (strTenor, dblQuote * dblScale);

  121.             if (0 >= (iTenorDays = org.drip.analytics.support.Helper.TenorToDays (strTenor))) return false;
  122.         } catch (java.lang.Exception e) {
  123.             return false;
  124.         }

  125.         java.util.Map<java.lang.Integer, org.drip.feed.loader.TenorQuote> mapOrderedTenorQuote =
  126.             _mapOrderedInstrumentTenorQuote.containsKey (strInstrument) ? _mapOrderedInstrumentTenorQuote.get
  127.                 (strInstrument) : new java.util.TreeMap<java.lang.Integer,
  128.                     org.drip.feed.loader.TenorQuote>();

  129.         mapOrderedTenorQuote.put (iTenorDays, tq);

  130.         _mapOrderedInstrumentTenorQuote.put (strInstrument, mapOrderedTenorQuote);

  131.         return true;
  132.     }

  133.     /**
  134.      * Retrieve the Named Instrument Group Quote Map
  135.      *
  136.      * @param strInstrument The Instrument Group Name
  137.      *
  138.      * @return The Named Instrument Group Quote Map
  139.      */

  140.     public java.util.Map<java.lang.Integer, org.drip.feed.loader.TenorQuote> instrumentTenorQuote (
  141.         final java.lang.String strInstrument)
  142.     {
  143.         return null == strInstrument || !_mapOrderedInstrumentTenorQuote.containsKey (strInstrument) ? null :
  144.             _mapOrderedInstrumentTenorQuote.get (strInstrument);
  145.     }

  146.     /**
  147.      * Retrieve the Named Instrument Tenors
  148.      *
  149.      * @param strInstrument The Instrument Group Name
  150.      *
  151.      * @return The Named Instrument Tenors
  152.      */

  153.     public java.lang.String[] instrumentTenor (
  154.         final java.lang.String strInstrument)
  155.     {
  156.         java.util.Map<java.lang.Integer, org.drip.feed.loader.TenorQuote> mapTenorQuote =
  157.             instrumentTenorQuote (strInstrument);

  158.         if (null == mapTenorQuote) return null;

  159.         int iNumTenor = mapTenorQuote.size();

  160.         if (0 == iNumTenor) return null;

  161.         int i = 0;
  162.         java.lang.String[] astrTenor = new java.lang.String[iNumTenor];

  163.         for (java.util.Map.Entry<java.lang.Integer, org.drip.feed.loader.TenorQuote> meTQ :
  164.             mapTenorQuote.entrySet())
  165.             astrTenor[i++] = meTQ.getValue().tenor();

  166.         return astrTenor;
  167.     }

  168.     /**
  169.      * Retrieve the Named Instrument Quotes
  170.      *
  171.      * @param strInstrument The Instrument Group Name
  172.      *
  173.      * @return The Named Instrument Quotes
  174.      */

  175.     public double[] instrumentQuote (
  176.         final java.lang.String strInstrument)
  177.     {
  178.         java.util.Map<java.lang.Integer, org.drip.feed.loader.TenorQuote> mapTenorQuote =
  179.             instrumentTenorQuote (strInstrument);

  180.         if (null == mapTenorQuote) return null;

  181.         int iNumTenor = mapTenorQuote.size();

  182.         if (0 == iNumTenor) return null;

  183.         int i = 0;
  184.         double[] adblQuote = new double[iNumTenor];

  185.         for (java.util.Map.Entry<java.lang.Integer, org.drip.feed.loader.TenorQuote> meTQ :
  186.             mapTenorQuote.entrySet())
  187.             adblQuote[i++] = meTQ.getValue().quote();

  188.         return adblQuote;
  189.     }

  190.     /**
  191.      * Indicates whether the ISTQ is Empty or not
  192.      *
  193.      * @return TRUE - ISTQ is Empty
  194.      */

  195.     public boolean isEmpty()
  196.     {
  197.         return 0 == _mapOrderedInstrumentTenorQuote.size();
  198.     }
  199. }