MultiSided.java

  1. package org.drip.param.quote;

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

  82. /**
  83.  * <i>MultiSided</i> implements the Quote interface, which contains the stubs corresponding to a product
  84.  * quote. It contains the quote value, quote instant for the different quote sides (bid/ask/mid).
  85.  *
  86.  *  <br><br>
  87.  *  <ul>
  88.  *      <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/ProductCore.md">Product Core Module</a></li>
  89.  *      <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/FixedIncomeAnalyticsLibrary.md">Fixed Income Analytics</a></li>
  90.  *      <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>
  91.  *      <li><b>Package</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/param/quote/README.md">Multi-sided Multi-Measure Ticks Quotes</a></li>
  92.  *  </ul>
  93.  *  
  94.  * @author Lakshmi Krishnamurthy
  95.  */

  96. public class MultiSided extends org.drip.param.definition.Quote {
  97.     class SingleSided {
  98.         double _dblSize = java.lang.Double.NaN;
  99.         double _dblQuote = java.lang.Double.NaN;
  100.         org.drip.analytics.date.DateTime _dt = null;

  101.         SingleSided (
  102.             final double dblQuote,
  103.             final double dblSize)
  104.             throws java.lang.Exception
  105.         {
  106.             if (!org.drip.numerical.common.NumberUtil.IsValid (_dblQuote = dblQuote))
  107.                 throw new java.lang.Exception ("MultiSided::SingleSided ctr: Invalid Inputs!");

  108.             _dblSize = dblSize;

  109.             _dt = new org.drip.analytics.date.DateTime();
  110.         }

  111.         double quote()
  112.         {
  113.             return _dblQuote;
  114.         }

  115.         double size()
  116.         {
  117.             return _dblSize;
  118.         }

  119.         org.drip.analytics.date.DateTime time()
  120.         {
  121.             return _dt;
  122.         }

  123.         boolean setQuote (
  124.             final double dblQuote)
  125.         {
  126.             if (!org.drip.numerical.common.NumberUtil.IsValid (dblQuote)) return false;

  127.             _dblQuote = dblQuote;
  128.             return true;
  129.         }

  130.         boolean setSize (
  131.             final double dblSize)
  132.         {
  133.             if (!org.drip.numerical.common.NumberUtil.IsValid (dblSize)) return false;

  134.             _dblSize = dblSize;
  135.             return true;
  136.         }
  137.     };

  138.     private org.drip.analytics.support.CaseInsensitiveTreeMap<SingleSided> _mapSingleSidedQuote = new
  139.         org.drip.analytics.support.CaseInsensitiveTreeMap<SingleSided>();

  140.     /**
  141.      * MultiSidedQuote Constructor: Constructs a Quote object from the quote value and the side string.
  142.      *
  143.      * @param strSide bid/ask/mid
  144.      * @param dblQuote Quote Value
  145.      *
  146.      * @throws java.lang.Exception Thrown on invalid inputs
  147.      */

  148.     public MultiSided (
  149.         final java.lang.String strSide,
  150.         final double dblQuote)
  151.         throws java.lang.Exception
  152.     {
  153.         if (null == strSide || strSide.isEmpty() || !org.drip.numerical.common.NumberUtil.IsValid (dblQuote))
  154.             throw new java.lang.Exception ("MultiSided ctr: Invalid Side/Quote/Size!");

  155.         _mapSingleSidedQuote.put (strSide, new SingleSided (dblQuote, java.lang.Double.NaN));
  156.     }

  157.     /**
  158.      * MultiSided Constructor: Constructs a Quote object from the quote size/value and the side string.
  159.      *
  160.      * @param strSide bid/ask/mid
  161.      * @param dblQuote Quote Value
  162.      * @param dblSize Size
  163.      *
  164.      * @throws java.lang.Exception Thrown on invalid inputs
  165.      */

  166.     public MultiSided (
  167.         final java.lang.String strSide,
  168.         final double dblQuote,
  169.         final double dblSize)
  170.         throws java.lang.Exception
  171.     {
  172.         if (null == strSide || strSide.isEmpty() || !org.drip.numerical.common.NumberUtil.IsValid (dblQuote))
  173.             throw new java.lang.Exception ("MultiSided ctr: Invalid Side/Quote/Size!");

  174.         _mapSingleSidedQuote.put (strSide, new SingleSided (dblQuote, dblSize));
  175.     }

  176.     @Override public double value (
  177.         final java.lang.String strSide)
  178.     {
  179.         if (null == strSide || strSide.isEmpty()) return java.lang.Double.NaN;

  180.         return _mapSingleSidedQuote.get (strSide).quote();
  181.     }

  182.     @Override public double size (
  183.         final java.lang.String strSide)
  184.     {
  185.         if (null == strSide || strSide.isEmpty()) return java.lang.Double.NaN;

  186.         return _mapSingleSidedQuote.get (strSide).size();
  187.     }

  188.     @Override public org.drip.analytics.date.DateTime time (
  189.         final java.lang.String strSide)
  190.     {
  191.         if (null == strSide || strSide.isEmpty()) return null;

  192.         return _mapSingleSidedQuote.get (strSide).time();
  193.     }

  194.     @Override public boolean setSide (
  195.         final java.lang.String strSide,
  196.         final double dblQuote,
  197.         final double dblSize)
  198.     {
  199.         if (null != strSide && !strSide.isEmpty() && !org.drip.numerical.common.NumberUtil.IsValid (dblQuote))
  200.             return false;

  201.         try {
  202.             _mapSingleSidedQuote.put (strSide, new SingleSided (dblQuote, dblSize));
  203.         } catch (java.lang.Exception e) {
  204.             e.printStackTrace();

  205.             return false;
  206.         }

  207.         return true;
  208.     }
  209. }