LatentStateFixingsContainer.java

  1. package org.drip.param.market;

  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>LatentStateFixingsContainer</i> holds the explicit fixings for a specified Latent State Quantification
  81.  * along the date ordinate.
  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/param/README.md">Product Cash Flow, Valuation, Market, Pricing, and Quoting Parameters</a></li>
  88.  *      <li><b>Package</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/param/market/README.md">Curves Surfaces Quotes Fixings Container</a></li>
  89.  *  </ul>
  90.  *
  91.  * @author Lakshmi Krishnamurthy
  92.  */

  93. public class LatentStateFixingsContainer {
  94.     private java.util.Map<org.drip.analytics.date.JulianDate,
  95.         org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double>> _mmForwardFixing = new
  96.             java.util.TreeMap<org.drip.analytics.date.JulianDate,
  97.                 org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double>>();

  98.     private java.util.Map<org.drip.analytics.date.JulianDate,
  99.         org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double>> _mmOTCFixFloatFixing = new
  100.             java.util.TreeMap<org.drip.analytics.date.JulianDate,
  101.                 org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double>>();

  102.     private java.util.Map<org.drip.analytics.date.JulianDate,
  103.         org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double>> _mmFXFixing = new
  104.             java.util.TreeMap<org.drip.analytics.date.JulianDate,
  105.                 org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double>>();

  106.     /**
  107.      * Empty LatentStateFixingsContainer Instance Constructor
  108.      */

  109.     public LatentStateFixingsContainer()
  110.     {
  111.     }

  112.     /**
  113.      * Add the Fixing corresponding to the Date/Label Pair
  114.      *
  115.      * @param dt The Fixing Date
  116.      * @param lsl The Latent State Label
  117.      * @param dblFixing The Fixing Amount
  118.      *
  119.      * @return TRUE - Entry successfully added
  120.      */

  121.     public boolean add (
  122.         final org.drip.analytics.date.JulianDate dt,
  123.         final org.drip.state.identifier.LatentStateLabel lsl,
  124.         final double dblFixing)
  125.     {
  126.         if (null == dt || null == lsl || !org.drip.numerical.common.NumberUtil.IsValid (dblFixing)) return false;

  127.         if (lsl instanceof org.drip.state.identifier.OTCFixFloatLabel) {
  128.             if (!_mmOTCFixFloatFixing.containsKey (dt))
  129.                 _mmOTCFixFloatFixing.put (dt, new
  130.                     org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double>());

  131.             org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double> mapOTCFixFloatFixing =
  132.                 _mmOTCFixFloatFixing.get (dt);

  133.             mapOTCFixFloatFixing.put (lsl.fullyQualifiedName(), dblFixing);

  134.             return true;
  135.         }

  136.         if (lsl instanceof org.drip.state.identifier.ForwardLabel) {
  137.             if (!_mmForwardFixing.containsKey (dt))
  138.                 _mmForwardFixing.put (dt, new
  139.                     org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double>());

  140.             org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double> mapForwardFixing =
  141.                 _mmForwardFixing.get (dt);

  142.             mapForwardFixing.put (lsl.fullyQualifiedName(), dblFixing);

  143.             return true;
  144.         }

  145.         if (lsl instanceof org.drip.state.identifier.FXLabel) {
  146.             if (!_mmFXFixing.containsKey (dt))
  147.                 _mmFXFixing.put (dt, new
  148.                     org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double>());

  149.             org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double> mapFXFixing = _mmFXFixing.get
  150.                 (dt);

  151.             mapFXFixing.put (lsl.fullyQualifiedName(), dblFixing);

  152.             return true;
  153.         }

  154.         return false;
  155.     }

  156.     /**
  157.      * Add the Latent State Fixing corresponding to the Date/Label Pair
  158.      *
  159.      * @param iDate The Fixing Date
  160.      * @param lsl The Latent State Fixing Label
  161.      * @param dblFixing The Fixing Amount
  162.      *
  163.      * @return TRUE - Entry successfully added
  164.      */

  165.     public boolean add (
  166.         final int iDate,
  167.         final org.drip.state.identifier.LatentStateLabel lsl,
  168.         final double dblFixing)
  169.     {
  170.         return add (new org.drip.analytics.date.JulianDate (iDate), lsl, dblFixing);
  171.     }

  172.     /**
  173.      * Remove the Latent State Fixing corresponding to the Date/Label Pair it if exists
  174.      *
  175.      * @param dt The Fixing Date
  176.      * @param lsl The Latent State Fixing Label
  177.      *
  178.      * @return TRUE - Entry successfully removed if it existed
  179.      */

  180.     public boolean remove (
  181.         final org.drip.analytics.date.JulianDate dt,
  182.         final org.drip.state.identifier.LatentStateLabel lsl)
  183.     {
  184.         if (null == dt || null == lsl) return false;

  185.         if (lsl instanceof org.drip.state.identifier.OTCFixFloatLabel) {
  186.             if (!_mmOTCFixFloatFixing.containsKey (dt)) return true;

  187.             _mmOTCFixFloatFixing.get (dt).remove (lsl.fullyQualifiedName());

  188.             return true;
  189.         }

  190.         if (lsl instanceof org.drip.state.identifier.ForwardLabel) {
  191.             if (!_mmForwardFixing.containsKey (dt)) return true;

  192.             _mmForwardFixing.get (dt).remove (lsl.fullyQualifiedName());

  193.             return true;
  194.         }

  195.         if (lsl instanceof org.drip.state.identifier.FXLabel) {
  196.             if (!_mmFXFixing.containsKey (dt)) return true;

  197.             _mmFXFixing.get (dt).remove (lsl.fullyQualifiedName());

  198.             return true;
  199.         }

  200.         return false;
  201.     }

  202.     /**
  203.      * Remove the Latent State Fixing corresponding to the Date/Label Pair it if exists
  204.      *
  205.      * @param iDate The Fixing Date
  206.      * @param lsl The Latent State Fixing Label
  207.      *
  208.      * @return TRUE - Entry successfully removed if it existed
  209.      */

  210.     public boolean remove (
  211.         final int iDate,
  212.         final org.drip.state.identifier.LatentStateLabel lsl)
  213.     {
  214.         return remove (new org.drip.analytics.date.JulianDate (iDate), lsl);
  215.     }

  216.     /**
  217.      * Retrieve the Latent State Fixing for the Specified Date/LSL Combination
  218.      *
  219.      * @param dt Date
  220.      * @param lsl The Latent State Latent State Label
  221.      *
  222.      * @return The Latent State Fixing for the Specified Date
  223.      *
  224.      * @throws java.lang.Exception Thrown if the Fixing cannot be found
  225.      */

  226.     public double fixing (
  227.         final org.drip.analytics.date.JulianDate dt,
  228.         final org.drip.state.identifier.LatentStateLabel lsl)
  229.         throws java.lang.Exception
  230.     {
  231.         if (null == dt || null == lsl)
  232.             throw new java.lang.Exception
  233.                 ("LatentStateFixingsContainer::fixing => Cannot locate Latent State Fixing for the Date");

  234.         if (lsl instanceof org.drip.state.identifier.OTCFixFloatLabel) {
  235.             if (!_mmOTCFixFloatFixing.containsKey (dt))
  236.                 throw new java.lang.Exception
  237.                     ("LatentStateFixingsContainer::fixing => Cannot locate OTC Fix/Float Fixing for the Date");

  238.             org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double> mapOTCFixFloatFixing =
  239.                 _mmOTCFixFloatFixing.get (dt);

  240.             java.lang.String strLabel = lsl.fullyQualifiedName();

  241.             if (!mapOTCFixFloatFixing.containsKey (strLabel))
  242.                 throw new java.lang.Exception
  243.                     ("LatentStateFixingsContainer::fixing => Cannot locate the OTC Fix/Float Label Entry for the Date!");

  244.             return mapOTCFixFloatFixing.get (strLabel);
  245.         }

  246.         if (lsl instanceof org.drip.state.identifier.ForwardLabel) {
  247.             if (!_mmForwardFixing.containsKey (dt))
  248.                 throw new java.lang.Exception
  249.                     ("LatentStateFixingsContainer::fixing => Cannot locate Forward Fixing for the Date");

  250.             org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double> mapForwardFixing =
  251.                 _mmForwardFixing.get (dt);

  252.             java.lang.String strLabel = lsl.fullyQualifiedName();

  253.             if (!mapForwardFixing.containsKey (strLabel))
  254.                 throw new java.lang.Exception
  255.                     ("LatentStateFixingsContainer::fixing => Cannot locate the Forward Label Entry for the Date!");

  256.             return mapForwardFixing.get (strLabel);
  257.         }

  258.         if (lsl instanceof org.drip.state.identifier.FXLabel) {
  259.             if (!_mmFXFixing.containsKey (dt))
  260.                 throw new java.lang.Exception
  261.                     ("LatentStateFixingsContainer::fixing => Cannot locate FX Fixing for the Date");

  262.             org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double> mapFXFixing = _mmFXFixing.get
  263.                 (dt);

  264.             java.lang.String strLabel = lsl.fullyQualifiedName();

  265.             if (!mapFXFixing.containsKey (strLabel))
  266.                 throw new java.lang.Exception
  267.                     ("LatentStateFixingsContainer::fixing => Cannot locate the FX Label Entry for the Date!");

  268.             return mapFXFixing.get (strLabel);
  269.         }

  270.         throw new java.lang.Exception
  271.             ("LatentStateFixingsContainer::fixing => No Fixings available for the Latent State");
  272.     }

  273.     /**
  274.      * Retrieve the Latent State Fixing for the Specified Date
  275.      *
  276.      * @param iDate Date
  277.      * @param lsl The Latent State Label
  278.      *
  279.      * @return The Fixing for the Specified Date
  280.      *
  281.      * @throws java.lang.Exception Thrown if the Fixing cannot be found
  282.      */

  283.     public double fixing (
  284.         final int iDate,
  285.         final org.drip.state.identifier.LatentStateLabel lsl)
  286.         throws java.lang.Exception
  287.     {
  288.         return fixing (new org.drip.analytics.date.JulianDate (iDate), lsl);
  289.     }

  290.     /**
  291.      * Indicate the Availability of the Fixing for the Specified LSL Label on the specified Date
  292.      *
  293.      * @param dt The Date
  294.      * @param lsl The Label
  295.      *
  296.      * @return TRUE - The Fixing for the Specified LSL Label on the specified Date
  297.      */

  298.     public boolean available (
  299.         final org.drip.analytics.date.JulianDate dt,
  300.         final org.drip.state.identifier.LatentStateLabel lsl)
  301.     {
  302.         if (null == dt || null == lsl) return false;

  303.         if (lsl instanceof org.drip.state.identifier.OTCFixFloatLabel) {
  304.             if (!_mmOTCFixFloatFixing.containsKey (dt)) return false;

  305.             return _mmOTCFixFloatFixing.get (dt).containsKey (lsl.fullyQualifiedName());
  306.         }

  307.         if (lsl instanceof org.drip.state.identifier.ForwardLabel) {
  308.             if (!_mmForwardFixing.containsKey (dt)) return false;

  309.             return _mmForwardFixing.get (dt).containsKey (lsl.fullyQualifiedName());
  310.         }

  311.         if (lsl instanceof org.drip.state.identifier.FXLabel) {
  312.             if (!_mmFXFixing.containsKey (dt)) return false;

  313.             return _mmFXFixing.get (dt).containsKey (lsl.fullyQualifiedName());
  314.         }

  315.         return false;
  316.     }

  317.     /**
  318.      * Indicate the Availability of the Fixing for the Specified LSL on the specified Date
  319.      *
  320.      * @param iDate The Date
  321.      * @param lsl The Label
  322.      *
  323.      * @return TRUE - The Fixing for the Specified LSL on the specified Date
  324.      */

  325.     public boolean available (
  326.         final int iDate,
  327.         final org.drip.state.identifier.LatentStateLabel lsl)
  328.     {
  329.         return available (new org.drip.analytics.date.JulianDate (iDate), lsl);
  330.     }
  331. }