FXSettingContainer.java

  1. package org.drip.market.definition;

  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>FXSettingContainer</i> contains the Parameters related to the FX Settings.
  80.  *
  81.  *  <br><br>
  82.  *  <ul>
  83.  *      <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/ProductCore.md">Product Core Module</a></li>
  84.  *      <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/FixedIncomeAnalyticsLibrary.md">Fixed Income Analytics Library</a></li>
  85.  *      <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>
  86.  *      <li><b>Package</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/market/definition">IBOR, FX, Overnight Index Container</a></li>
  87.  *  </ul>
  88.  *
  89.  * @author Lakshmi Krishnamurthy
  90.  */

  91. public class FXSettingContainer {
  92.     private static java.util.Map<java.lang.String, java.lang.Integer> _mapCurrencyOrder = null;
  93.     private static java.util.Map<java.lang.String, org.drip.product.params.CurrencyPair> _mapCurrencyPair =
  94.         null;

  95.     private static final void SetUpCurrencyPair (
  96.         final java.lang.String strCurrency1,
  97.         final java.lang.String strCurrency2,
  98.         final org.drip.product.params.CurrencyPair cp)
  99.     {
  100.         _mapCurrencyPair.put (strCurrency1 + strCurrency2, cp);
  101.        
  102.         _mapCurrencyPair.put (strCurrency2 + strCurrency1, cp);
  103.     }

  104.     /**
  105.      * Initialize the FXSettingContainer
  106.      *
  107.      * @return TRUE - FXSettingsContainer successfully initialized
  108.      */

  109.     public static final boolean Init()
  110.     {
  111.         if (null != _mapCurrencyOrder) return true;

  112.         _mapCurrencyOrder = new java.util.TreeMap<java.lang.String, java.lang.Integer>();

  113.         _mapCurrencyPair = new java.util.TreeMap<java.lang.String, org.drip.product.params.CurrencyPair>();

  114.         _mapCurrencyOrder.put ("EUR", 1);

  115.         _mapCurrencyOrder.put ("GBP", 2);

  116.         _mapCurrencyOrder.put ("AUD", 3);

  117.         _mapCurrencyOrder.put ("NZD", 4);

  118.         _mapCurrencyOrder.put ("USD", 5);

  119.         _mapCurrencyOrder.put ("CAD", 6);

  120.         _mapCurrencyOrder.put ("CHF", 7);

  121.         _mapCurrencyOrder.put ("JPY", 8);

  122.         try {
  123.             SetUpCurrencyPair ("AUD", "EUR", new org.drip.product.params.CurrencyPair ("AUD", "EUR", "EUR",
  124.                 10000.));

  125.             SetUpCurrencyPair ("AUD", "USD", new org.drip.product.params.CurrencyPair ("AUD", "USD", "USD",
  126.                 10000.));

  127.             SetUpCurrencyPair ("EUR", "GBP", new org.drip.product.params.CurrencyPair ("EUR", "GBP", "GBP",
  128.                 10000.));

  129.             SetUpCurrencyPair ("EUR", "JPY", new org.drip.product.params.CurrencyPair ("EUR", "JPY", "JPY",
  130.                 100.));

  131.             SetUpCurrencyPair ("EUR", "USD", new org.drip.product.params.CurrencyPair ("EUR", "USD", "USD",
  132.                 10000.));

  133.             SetUpCurrencyPair ("GBP", "JPY", new org.drip.product.params.CurrencyPair ("GBP", "JPY", "JPY",
  134.                 100.));

  135.             SetUpCurrencyPair ("GBP", "USD", new org.drip.product.params.CurrencyPair ("GBP", "USD", "USD",
  136.                 10000.));

  137.             SetUpCurrencyPair ("USD", "BRL", new org.drip.product.params.CurrencyPair ("USD", "BRL", "BRL",
  138.                 10000.));

  139.             SetUpCurrencyPair ("USD", "CAD", new org.drip.product.params.CurrencyPair ("USD", "CAD", "CAD",
  140.                 10000.));

  141.             SetUpCurrencyPair ("USD", "CHF", new org.drip.product.params.CurrencyPair ("USD", "CHF", "CHF",
  142.                 10000.));

  143.             SetUpCurrencyPair ("USD", "CNY", new org.drip.product.params.CurrencyPair ("USD", "CNY", "CNY",
  144.                 1.));

  145.             SetUpCurrencyPair ("USD", "EGP", new org.drip.product.params.CurrencyPair ("USD", "EGP", "EGP",
  146.                 10000.));

  147.             SetUpCurrencyPair ("USD", "HUF", new org.drip.product.params.CurrencyPair ("USD", "HUF", "HUF",
  148.                 100.));

  149.             SetUpCurrencyPair ("USD", "INR", new org.drip.product.params.CurrencyPair ("USD", "INR", "INR",
  150.                 100.));

  151.             SetUpCurrencyPair ("USD", "JPY", new org.drip.product.params.CurrencyPair ("USD", "JPY", "JPY",
  152.                 100.));

  153.             SetUpCurrencyPair ("USD", "KRW", new org.drip.product.params.CurrencyPair ("USD", "KRW", "KRW",
  154.                 1.));

  155.             SetUpCurrencyPair ("USD", "MXN", new org.drip.product.params.CurrencyPair ("USD", "MXN", "MXN",
  156.                 10000.));

  157.             SetUpCurrencyPair ("USD", "PLN", new org.drip.product.params.CurrencyPair ("USD", "PLN", "PLN",
  158.                 100.));

  159.             SetUpCurrencyPair ("USD", "TRY", new org.drip.product.params.CurrencyPair ("USD", "TRY", "TRY",
  160.                 100.));

  161.             SetUpCurrencyPair ("USD", "TWD", new org.drip.product.params.CurrencyPair ("USD", "TWD", "TWD",
  162.                 1.));

  163.             SetUpCurrencyPair ("USD", "ZAR", new org.drip.product.params.CurrencyPair ("USD", "ZAR", "ZAR",
  164.                 10000.));

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

  169.         return false;
  170.     }

  171.     /**
  172.      * Retrieve the Order corresponding to the specified Currency
  173.      *
  174.      * @param strCurrency The Currency
  175.      *
  176.      * @return The Order corresponding to the specified Currency
  177.      *
  178.      * @throws java.lang.Exception Thrown if Inputs of Invalid
  179.      */

  180.     public static final int CurrencyOrder (
  181.         final java.lang.String strCurrency)
  182.         throws java.lang.Exception
  183.     {
  184.         if (null == strCurrency || strCurrency.isEmpty())
  185.             throw new java.lang.Exception ("FXSettingsContainer::CurrencyOrder => Invalid Input");

  186.         return _mapCurrencyOrder.containsKey (strCurrency) ? _mapCurrencyOrder.get (strCurrency) : 0;
  187.     }

  188.     /**
  189.      * Retrieve the Currency Pair Instance from the specified Currencies
  190.      *
  191.      * @param strCurrency1 Currency #1
  192.      * @param strCurrency2 Currency #2
  193.      *
  194.      * @return The Currency Pair Instance
  195.      */

  196.     public static final org.drip.product.params.CurrencyPair CurrencyPair (
  197.         final java.lang.String strCurrency1,
  198.         final java.lang.String strCurrency2)
  199.     {
  200.         if (null == strCurrency1 || strCurrency1.isEmpty() || null == strCurrency2 || strCurrency2.isEmpty())
  201.             return null;

  202.         java.lang.String strCurrencyPairCode = strCurrency1 + strCurrency2;

  203.         return _mapCurrencyPair.containsKey (strCurrencyPairCode) ? _mapCurrencyPair.get
  204.             (strCurrencyPairCode) : null;
  205.     }
  206. }