CrossFloatConventionContainer.java

  1. package org.drip.market.otc;

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

  78. /**
  79.  * <i>CrossFloatConventionContainer</i> contains the Conventions of Standard OTC Cross-Currency Float-Float
  80.  * Swaps.
  81.  *
  82.  *  <br><br>
  83.  *  <ul>
  84.  *      <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/ProductCore.md">Product Core Module</a></li>
  85.  *      <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/FixedIncomeAnalyticsLibrary.md">Fixed Income Analytics Library</a></li>
  86.  *      <li><b>Project</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/market">Static Market Fields - the Definitions, the OTC/Exchange Traded Products, and Treasury Settings</a></li>
  87.  *      <li><b>Package</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/market/otc">OTC Dual Stream Option Container</a></li>
  88.  *  </ul>
  89.  *
  90.  * @author Lakshmi Krishnamurthy
  91.  */

  92. public class CrossFloatConventionContainer {
  93.     private static java.util.Map<java.lang.String, org.drip.market.otc.CrossFloatSwapConvention>
  94.         _mapConvention = null;

  95.     private static final boolean AddCrossCurrencyConvention (
  96.         final org.drip.market.otc.CrossFloatStreamConvention referenceConvention,
  97.         final org.drip.market.otc.CrossFloatStreamConvention derivedConvention)
  98.     {
  99.         org.drip.market.otc.CrossFloatSwapConvention xccyConvention = null;

  100.         try {
  101.             xccyConvention = new org.drip.market.otc.CrossFloatSwapConvention (referenceConvention,
  102.                 derivedConvention, org.drip.param.period.FixingSetting.FIXING_PRESET_STATIC, false, 2);
  103.         } catch (java.lang.Exception e) {
  104.             e.printStackTrace();

  105.             return false;
  106.         }

  107.         java.lang.String strDerivedCurrency = derivedConvention.currency();

  108.         java.lang.String strReferenceCurrency = referenceConvention.currency();

  109.         _mapConvention.put (strReferenceCurrency + "_" + strDerivedCurrency, xccyConvention);

  110.         _mapConvention.put (strDerivedCurrency + "_" + strReferenceCurrency, xccyConvention);

  111.         return true;
  112.     }

  113.     /**
  114.      * Initialize the Cross-Currency Float-Float Conventions Container with the pre-set Floating Stream
  115.      *  Contracts
  116.      *
  117.      * @return TRUE - The Cross-Currency Float-Float Conventions Container successfully initialized
  118.      */

  119.     public static final boolean Init()
  120.     {
  121.         if (null != _mapConvention) return true;

  122.         _mapConvention = new java.util.TreeMap<java.lang.String,
  123.             org.drip.market.otc.CrossFloatSwapConvention>();

  124.         try {
  125.             org.drip.market.otc.CrossFloatStreamConvention referenceConventionDerivedQuote = new
  126.                 org.drip.market.otc.CrossFloatStreamConvention ("USD", "3M", false);

  127.             if (!AddCrossCurrencyConvention (referenceConventionDerivedQuote, new
  128.                 org.drip.market.otc.CrossFloatStreamConvention ("AUD", "3M", true)))
  129.                 return false;

  130.             if (!AddCrossCurrencyConvention (referenceConventionDerivedQuote, new
  131.                 org.drip.market.otc.CrossFloatStreamConvention ("CAD", "3M", true)))
  132.                 return false;

  133.             if (!AddCrossCurrencyConvention (referenceConventionDerivedQuote, new
  134.                 org.drip.market.otc.CrossFloatStreamConvention ("CHF", "3M", true)))
  135.                 return false;

  136.             if (!AddCrossCurrencyConvention (referenceConventionDerivedQuote, new
  137.                 org.drip.market.otc.CrossFloatStreamConvention ("DKK", "3M", true)))
  138.                 return false;

  139.             if (!AddCrossCurrencyConvention (referenceConventionDerivedQuote, new
  140.                 org.drip.market.otc.CrossFloatStreamConvention ("EUR", "3M", true)))
  141.                 return false;

  142.             if (!AddCrossCurrencyConvention (referenceConventionDerivedQuote, new
  143.                 org.drip.market.otc.CrossFloatStreamConvention ("GBP", "3M", true)))
  144.                 return false;

  145.             if (!AddCrossCurrencyConvention (referenceConventionDerivedQuote, new
  146.                 org.drip.market.otc.CrossFloatStreamConvention ("JPY", "3M", true)))
  147.                 return false;

  148.             if (!AddCrossCurrencyConvention (referenceConventionDerivedQuote, new
  149.                 org.drip.market.otc.CrossFloatStreamConvention ("NOK", "3M", true)))
  150.                 return false;

  151.             if (!AddCrossCurrencyConvention (referenceConventionDerivedQuote, new
  152.                 org.drip.market.otc.CrossFloatStreamConvention ("PLN", "3M", true)))
  153.                 return false;

  154.             if (!AddCrossCurrencyConvention (referenceConventionDerivedQuote, new
  155.                 org.drip.market.otc.CrossFloatStreamConvention ("SEK", "3M", true)))
  156.                 return false;

  157.             org.drip.market.otc.CrossFloatStreamConvention referenceConventionReferenceQuote = new
  158.                 org.drip.market.otc.CrossFloatStreamConvention ("USD", "3M", true);

  159.             if (!AddCrossCurrencyConvention (referenceConventionReferenceQuote, new
  160.                 org.drip.market.otc.CrossFloatStreamConvention ("CLP", "3M", false)))
  161.                 return false;

  162.             if (!AddCrossCurrencyConvention (referenceConventionReferenceQuote, new
  163.                 org.drip.market.otc.CrossFloatStreamConvention ("MXN", "3M", false)))
  164.                 return false;

  165.             return true;
  166.         } catch (java.lang.Exception e) {
  167.             e.printStackTrace();
  168.         }

  169.         return false;
  170.     }

  171.     /**
  172.      * Retrieve the Cross-Currency Float-Float Convention Instance from the Jurisdiction Name
  173.      *
  174.      * @param strCurrency The Jurisdiction Name
  175.      *
  176.      * @return The Float-Float Convention Instance
  177.      */

  178.     public static final org.drip.market.otc.CrossFloatSwapConvention ConventionFromJurisdiction (
  179.         final java.lang.String strCurrency)
  180.     {
  181.         if (null == strCurrency || strCurrency.isEmpty()) return null;

  182.         java.lang.String strKey = "USD_" + strCurrency;

  183.         return !_mapConvention.containsKey (strKey) ? null : _mapConvention.get (strKey);
  184.     }

  185.     /**
  186.      * Retrieve the Cross-Currency Float-Float Convention Instance from the Reference/Derived Jurisdiction
  187.      *  Names
  188.      *
  189.      * @param strReferenceCurrency The Reference Jurisdiction Name
  190.      * @param strDerivedCurrency The Derived Jurisdiction Name
  191.      *
  192.      * @return The Float-Float Convention Instance
  193.      */

  194.     public static final org.drip.market.otc.CrossFloatSwapConvention ConventionFromJurisdiction (
  195.         final java.lang.String strReferenceCurrency,
  196.         final java.lang.String strDerivedCurrency)
  197.     {
  198.         if (null == strReferenceCurrency || strReferenceCurrency.isEmpty() || null == strDerivedCurrency ||
  199.             strDerivedCurrency.isEmpty())
  200.             return null;

  201.         java.lang.String strKey = strReferenceCurrency + "_" + strDerivedCurrency;

  202.         return !_mapConvention.containsKey (strKey) ? null : _mapConvention.get (strKey);
  203.     }
  204. }