FXRiskThresholdContainer21.java

  1. package org.drip.simm.fx;

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

  75. /**
  76.  * <i>FXRiskThresholdContainer21</i> holds the ISDA SIMM 2.1 FX Risk Thresholds - the FX Categories and the
  77.  * Delta/Vega Limits defined for the Concentration Thresholds. The References are:
  78.  *
  79.  * <br><br>
  80.  *  <ul>
  81.  *      <li>
  82.  *          Andersen, L. B. G., M. Pykhtin, and A. Sokol (2017): Credit Exposure in the Presence of Initial
  83.  *              Margin https://papers.ssrn.com/sol3/papers.cfm?abstract_id=2806156 <b>eSSRN</b>
  84.  *      </li>
  85.  *      <li>
  86.  *          Albanese, C., S. Caenazzo, and O. Frankel (2017): Regression Sensitivities for Initial Margin
  87.  *              Calculations https://papers.ssrn.com/sol3/papers.cfm?abstract_id=2763488 <b>eSSRN</b>
  88.  *      </li>
  89.  *      <li>
  90.  *          Anfuso, F., D. Aziz, P. Giltinan, and K. Loukopoulus (2017): A Sound Modeling and Back-testing
  91.  *              Framework for Forecasting Initial Margin Requirements
  92.  *                  https://papers.ssrn.com/sol3/papers.cfm?abstract_id=2716279 <b>eSSRN</b>
  93.  *      </li>
  94.  *      <li>
  95.  *          Caspers, P., P. Giltinan, R. Lichters, and N. Nowaczyk (2017): Forecasting Initial Margin
  96.  *              Requirements - A Model Evaluation https://papers.ssrn.com/sol3/papers.cfm?abstract_id=2911167
  97.  *                  <b>eSSRN</b>
  98.  *      </li>
  99.  *      <li>
  100.  *          International Swaps and Derivatives Association (2017): SIMM v2.0 Methodology
  101.  *              https://www.isda.org/a/oFiDE/isda-simm-v2.pdf
  102.  *      </li>
  103.  *  </ul>
  104.  *
  105.  * <br><br>
  106.  *  <ul>
  107.  *      <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/PortfolioCore.md">Portfolio Core Module</a></li>
  108.  *      <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/MarginAnalyticsLibrary.md">Initial and Variation Margin Analytics</a></li>
  109.  *      <li><b>Project</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/simm/README.md">Initial Margin Analytics based on ISDA SIMM and its Variants</a></li>
  110.  *      <li><b>Package</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/simm/fx/README.md">FX Risk Factor Calibration Settings</a></li>
  111.  *  </ul>
  112.  * <br><br>
  113.  *
  114.  * @author Lakshmi Krishnamurthy
  115.  */

  116. public class FXRiskThresholdContainer21
  117. {
  118.     private static final java.util.Map<java.lang.Integer, org.drip.simm.fx.FXRiskGroup> s_FXRiskGroupMap =
  119.         new java.util.TreeMap<java.lang.Integer, org.drip.simm.fx.FXRiskGroup>();

  120.     private static final java.util.Map<java.lang.Integer, java.lang.Double> s_CategoryDelta = new
  121.         java.util.TreeMap<java.lang.Integer, java.lang.Double>();

  122.     private static final java.util.Map<java.lang.String, java.lang.Double> s_CategoryVega = new
  123.         java.util.HashMap<java.lang.String, java.lang.Double>();

  124.     /**
  125.      * Initialize the FX Risk Threshold Container
  126.      *
  127.      * @return TRUE - The FX Risk Threshold Container
  128.      */

  129.     public static final boolean Init()
  130.     {
  131.         try
  132.         {
  133.             s_FXRiskGroupMap.put (
  134.                 1,
  135.                 new org.drip.simm.fx.FXRiskGroup (
  136.                     1,
  137.                     "Significantly Material",
  138.                     new java.lang.String[]
  139.                     {
  140.                         "USD",
  141.                         "EUR",
  142.                         "JPY",
  143.                         "GBP",
  144.                         "AUD",
  145.                         "CHF",
  146.                         "CAD"
  147.                     }
  148.                 )
  149.             );

  150.             s_FXRiskGroupMap.put (
  151.                 2,
  152.                 new org.drip.simm.fx.FXRiskGroup (
  153.                     2,
  154.                     "Frequently Traded",
  155.                     new java.lang.String[]
  156.                     {
  157.                         "BRL",
  158.                         "CNY",
  159.                         "HKD",
  160.                         "INR",
  161.                         "KRW",
  162.                         "MXN",
  163.                         "NOK",
  164.                         "NZD",
  165.                         "RUB",
  166.                         "SEK",
  167.                         "SGD",
  168.                         "TRY",
  169.                         "ZAR"
  170.                     }
  171.                 )
  172.             );

  173.             s_FXRiskGroupMap.put (
  174.                 3,
  175.                 new org.drip.simm.fx.FXRiskGroup (
  176.                     3,
  177.                     "Others",
  178.                     new java.lang.String[]
  179.                     {
  180.                         "Other"
  181.                     }
  182.                 )
  183.             );

  184.             s_CategoryDelta.put (
  185.                 1,
  186.                 9700.
  187.             );

  188.             s_CategoryDelta.put (
  189.                 2,
  190.                 2900.
  191.             );

  192.             s_CategoryDelta.put (
  193.                 3,
  194.                 450.
  195.             );

  196.             s_CategoryVega.put (
  197.                 "1__1",
  198.                 2000.
  199.             );

  200.             s_CategoryVega.put (
  201.                 "1__2",
  202.                 1000.
  203.             );

  204.             s_CategoryVega.put (
  205.                 "1__3",
  206.                 320.
  207.             );

  208.             s_CategoryVega.put (
  209.                 "2__1",
  210.                 1000.
  211.             );

  212.             s_CategoryVega.put (
  213.                 "2__2",
  214.                 410.
  215.             );

  216.             s_CategoryVega.put (
  217.                 "2__3",
  218.                 210.
  219.             );

  220.             s_CategoryVega.put (
  221.                 "3__1",
  222.                 320.
  223.             );

  224.             s_CategoryVega.put (
  225.                 "3__2",
  226.                 210.
  227.             );

  228.             s_CategoryVega.put (
  229.                 "3__3",
  230.                 150.
  231.             );
  232.         }
  233.         catch (java.lang.Exception e)
  234.         {
  235.             e.printStackTrace();

  236.             return false;
  237.         }

  238.         return true;
  239.     }

  240.     /**
  241.      * Retrieve the Category for the specified Currency
  242.      *
  243.      * @param currency Currency
  244.      *
  245.      * @return The Category
  246.      *
  247.      * @throws java.lang.Exception Thrown if the Inputs are Invalid
  248.      */

  249.     public static final int CurrencyCategory (
  250.         final java.lang.String currency)
  251.         throws java.lang.Exception
  252.     {
  253.         if (null == currency || currency.isEmpty())
  254.         {
  255.             throw new java.lang.Exception ("FXRiskThresholdContainer::CurrencyCategory => Invalid Input");
  256.         }

  257.         for (java.util.Map.Entry<java.lang.Integer, org.drip.simm.fx.FXRiskGroup> fxRiskGroupEntry :
  258.             s_FXRiskGroupMap.entrySet())
  259.         {
  260.             java.lang.String[] currencyArray = fxRiskGroupEntry.getValue().currencyArray();

  261.             for (java.lang.String currencyEntry : currencyArray)
  262.             {
  263.                 if (currencyEntry.equalsIgnoreCase (currency))
  264.                 {
  265.                     return fxRiskGroupEntry.getKey();
  266.                 }
  267.             }
  268.         }

  269.         return s_FXRiskGroupMap.get (3).category();
  270.     }

  271.     /**
  272.      * Retrieve the Category Set
  273.      *
  274.      * @return The Category Set
  275.      */

  276.     public static final java.util.Set<java.lang.Integer> CategorySet()
  277.     {
  278.         return s_FXRiskGroupMap.keySet();
  279.     }

  280.     /**
  281.      * Indicate if the Category identified by the Number is available in the Map
  282.      *
  283.      * @param categoryNumber The Category Number
  284.      *
  285.      * @return TRUE - The Category identified by the Number is available in the Map
  286.      */

  287.     public static final boolean ContainsCategory (
  288.         final int categoryNumber)
  289.     {
  290.         return s_FXRiskGroupMap.containsKey (categoryNumber);
  291.     }

  292.     /**
  293.      * Retrieve the Risk Group identified by the Category Number
  294.      *
  295.      * @param categoryNumber The Category Number
  296.      *
  297.      * @return The Risk Group identified by the Category Number
  298.      */

  299.     public static final org.drip.simm.fx.FXRiskGroup FXRiskGroup (
  300.         final int categoryNumber)
  301.     {
  302.         return ContainsCategory (categoryNumber) ? s_FXRiskGroupMap.get (categoryNumber) : null;
  303.     }

  304.     /**
  305.      * Retrieve the Delta Threshold for the Category specified
  306.      *
  307.      * @param categoryNumber The specified Category
  308.      *
  309.      * @return Delta Threshold for the Category specified
  310.      *
  311.      * @throws java.lang.Exception Thrown if the Inputs are Invalid
  312.      */

  313.     public static final double CategoryDeltaThreshold (
  314.         final int categoryNumber)
  315.         throws java.lang.Exception
  316.     {
  317.         if (!s_CategoryDelta.containsKey (categoryNumber))
  318.         {
  319.             throw new java.lang.Exception
  320.                 ("FXRiskThresholdContainer::CategoryDeltaThreshold => Invalid Category");
  321.         }

  322.         return s_CategoryDelta.get (categoryNumber);
  323.     }

  324.     /**
  325.      * Retrieve the Vega Threshold for the Category Pair specified
  326.      *
  327.      * @param categoryNumber1 The specified Category #1
  328.      * @param categoryNumber2 The specified Category #2
  329.      *
  330.      * @return Vega Threshold for the Category Pair specified
  331.      *
  332.      * @throws java.lang.Exception Thrown if the Inputs are Invalid
  333.      */

  334.     public static final double CategoryVegaThreshold (
  335.         final int categoryNumber1,
  336.         final int categoryNumber2)
  337.         throws java.lang.Exception
  338.     {
  339.         java.lang.String categoryVegaThresholdKey = categoryNumber1 + "__" + categoryNumber2;

  340.         if (!s_CategoryVega.containsKey (categoryVegaThresholdKey))
  341.         {
  342.             throw new java.lang.Exception
  343.                 ("FXRiskThresholdContainer::CategoryVegaThreshold => Invalid Category");
  344.         }

  345.         return s_CategoryVega.get (categoryVegaThresholdKey);
  346.     }

  347.     /**
  348.      * Retrieve the FX Risk Group Map
  349.      *
  350.      * @return The FX Risk Group Map
  351.      */

  352.     public static final java.util.Map<java.lang.Integer, org.drip.simm.fx.FXRiskGroup>
  353.         FXRiskGroupMap()
  354.     {
  355.         return s_FXRiskGroupMap;
  356.     }

  357.     /**
  358.      * Retrieve the Category Delta Concentration Threshold Map
  359.      *
  360.      * @return The Category Delta Concentration Threshold Map
  361.      */

  362.     public static final java.util.Map<java.lang.Integer, java.lang.Double> CategoryDeltaMap()
  363.     {
  364.         return s_CategoryDelta;
  365.     }

  366.     /**
  367.      * Retrieve the Category Vega Concentration Threshold Map
  368.      *
  369.      * @return The Category Vega Concentration Threshold Map
  370.      */

  371.     public static final java.util.Map<java.lang.String, java.lang.Double> CategoryVegaMap()
  372.     {
  373.         return s_CategoryVega;
  374.     }

  375.     /**
  376.      * Retrieve the Cross Risk Group Co-variance Matrix
  377.      *
  378.      * @return The Cross Risk Group Co-variance Matrix
  379.      */

  380.     public static final org.drip.simm.foundation.RiskGroupPrincipalCovariance CrossGroupPrincipalCovariance()
  381.     {
  382.         java.util.Set<java.lang.Integer> fxBucketSet = s_FXRiskGroupMap.keySet();

  383.         int fxRiskGroupCount = fxBucketSet.size();

  384.         double[][] crossGroupCorrelation = new double[fxRiskGroupCount][fxRiskGroupCount];

  385.         for (int fxRiskGroupIndexI = 0; fxRiskGroupIndexI < fxRiskGroupCount; ++fxRiskGroupIndexI)
  386.         {
  387.             for (int fxRiskGroupIndexJ = 0; fxRiskGroupIndexJ < fxRiskGroupCount; ++fxRiskGroupIndexJ)
  388.             {
  389.                 crossGroupCorrelation[fxRiskGroupIndexI][fxRiskGroupIndexJ] =
  390.                     fxRiskGroupIndexI == fxRiskGroupIndexJ ? 1. :
  391.                     org.drip.simm.fx.FXSystemics21.CORRELATION;
  392.             }
  393.         }

  394.         return org.drip.simm.foundation.RiskGroupPrincipalCovariance.Standard (
  395.             crossGroupCorrelation,
  396.             1.
  397.         );
  398.     }
  399. }