TenorDurationNodeMetrics.java

  1. package org.drip.historical.sensitivity;

  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>TenorDurationNodeMetrics</i> holds the KRD Duration Nodes and associated Metrics.
  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/historical/README.md">Historical State Processing Utilities</a></li>
  85.  *      <li><b>Package</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/historical/sensitivity/README.md">Product Horizon Change Tenor Sensitivity</a></li>
  86.  *  </ul>
  87.  *
  88.  * @author Lakshmi Krishnamurthy
  89.  */

  90. public class TenorDurationNodeMetrics {
  91.     private org.drip.analytics.date.JulianDate _dtSnap = null;

  92.     private java.util.Map<java.lang.String, java.lang.String> _mapCustomC1 = new
  93.         org.drip.analytics.support.CaseInsensitiveHashMap<java.lang.String>();

  94.     private java.util.Map<java.lang.String, java.lang.Double> _mapCustomR1 = new
  95.         org.drip.analytics.support.CaseInsensitiveHashMap<java.lang.Double>();

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

  98.     private java.util.Map<java.lang.String, org.drip.analytics.date.JulianDate> _mapCustomDate = new
  99.         org.drip.analytics.support.CaseInsensitiveHashMap<org.drip.analytics.date.JulianDate>();

  100.     /**
  101.      * TenorDurationNodeMetrics Constructor
  102.      *
  103.      * @param dtSnap The Date Snap
  104.      *
  105.      * @throws java.lang.Exception Thrown if the Inputs are Invalid
  106.      */

  107.     public TenorDurationNodeMetrics (
  108.         final org.drip.analytics.date.JulianDate dtSnap)
  109.         throws java.lang.Exception
  110.     {
  111.         if (null == (_dtSnap = dtSnap))
  112.             throw new java.lang.Exception ("TenorDurationNodeMetrics ctr: Invalid Inputs");
  113.     }

  114.     /**
  115.      * Retrieve the KRD Date Snap
  116.      *
  117.      * @return The KRD Date Snap
  118.      */

  119.     public org.drip.analytics.date.JulianDate dateSnap()
  120.     {
  121.         return _dtSnap;
  122.     }

  123.     /**
  124.      * Insert a KRD Node
  125.      *
  126.      * @param strKRDNode KRD Node Key
  127.      * @param dblKRDValue KRD Node Value
  128.      *
  129.      * @return TRUE - The KRD Entry successfully inserted
  130.      */

  131.     public boolean addKRDNode (
  132.         final java.lang.String strKRDNode,
  133.         final double dblKRDValue)
  134.     {
  135.         if (null == strKRDNode || strKRDNode.isEmpty() || !org.drip.numerical.common.NumberUtil.IsValid
  136.             (dblKRDValue))
  137.             return false;

  138.         _mapKRD.put (strKRDNode, dblKRDValue);

  139.         return true;
  140.     }

  141.     /**
  142.      * Retrieve the KRD Map
  143.      *
  144.      * @return The KRD Map
  145.      */

  146.     public org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double> krdMap()
  147.     {
  148.         return _mapKRD;
  149.     }

  150.     /**
  151.      * Set the Custom Date Entry corresponding to the Specified Key
  152.      *
  153.      * @param strKey The Key
  154.      * @param dtCustom The Custom Date Entry
  155.      *
  156.      * @return TRUE - Custom Date successfully set
  157.      */

  158.     public boolean setDate (
  159.         final java.lang.String strKey,
  160.         final org.drip.analytics.date.JulianDate dtCustom)
  161.     {
  162.         if (null == strKey || strKey.isEmpty() || null == dtCustom) return false;

  163.         _mapCustomDate.put (strKey, dtCustom);

  164.         return true;
  165.     }

  166.     /**
  167.      * Retrieve the Custom Date Entry corresponding to the Specified Key
  168.      *
  169.      * @param strKey The Key
  170.      *
  171.      * @return The Custom Date Entry
  172.      */

  173.     public org.drip.analytics.date.JulianDate date (
  174.         final java.lang.String strKey)
  175.     {
  176.         return null == strKey || !_mapCustomDate.containsKey (strKey) ? null : _mapCustomDate.get (strKey);
  177.     }

  178.     /**
  179.      * Set the Custom C^1 Entry corresponding to the Specified Key
  180.      *
  181.      * @param strKey The Key
  182.      * @param strC1 The Custom C^1 Entry
  183.      *
  184.      * @return TRUE - Custom C^1 Entry successfully set
  185.      */

  186.     public boolean setC1 (
  187.         final java.lang.String strKey,
  188.         final java.lang.String strC1)
  189.     {
  190.         if (null == strKey || strKey.isEmpty() || null == strC1 || strC1.isEmpty()) return false;

  191.         _mapCustomC1.put (strKey, strC1);

  192.         return true;
  193.     }

  194.     /**
  195.      * Retrieve the Custom C^1 Entry corresponding to the Specified Key
  196.      *
  197.      * @param strKey The Key
  198.      *
  199.      * @return The Custom C^1 Entry
  200.      */

  201.     public java.lang.String c1 (
  202.         final java.lang.String strKey)
  203.     {
  204.         return null == strKey || !_mapCustomC1.containsKey (strKey) ? null : _mapCustomC1.get (strKey);
  205.     }

  206.     /**
  207.      * Set the Custom R^1 Entry corresponding to the Specified Key
  208.      *
  209.      * @param strKey The Key
  210.      * @param dblR1 The Custom R^1 Entry
  211.      *
  212.      * @return TRUE - Custom Number successfully set
  213.      */

  214.     public boolean setR1 (
  215.         final java.lang.String strKey,
  216.         final double dblR1)
  217.     {
  218.         if (null == strKey || strKey.isEmpty() || !org.drip.numerical.common.NumberUtil.IsValid (dblR1))
  219.             return false;

  220.         _mapCustomR1.put (strKey, dblR1);

  221.         return true;
  222.     }

  223.     /**
  224.      * Retrieve the Custom R^1 Entry corresponding to the Specified Key
  225.      *
  226.      * @param strKey The Key
  227.      *
  228.      * @return The Custom R^1 Entry
  229.      *
  230.      * @throws java.lang.Exception Thrown if the Inputs are Invalid
  231.      */

  232.     public double r1 (
  233.         final java.lang.String strKey)
  234.         throws java.lang.Exception
  235.     {
  236.         if (null == strKey || !_mapCustomR1.containsKey (strKey))
  237.             throw new java.lang.Exception ("PositionMarketSnap::r1 => Invalid Inputs");

  238.         return _mapCustomR1.get (strKey);
  239.     }
  240. }