AdditionalInitialMargin.java

  1. package org.drip.simm.estimator;

  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>AdditionalInitialMargin</i> holds the Additional Initial Margin along with the Product Specific Add-On
  77.  * Components. 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/estimator/README.md">ISDA SIMM Core + Add-On Estimator</a></li>
  111.  *  </ul>
  112.  * <br><br>
  113.  *
  114.  * @author Lakshmi Krishnamurthy
  115.  */

  116. public class AdditionalInitialMargin
  117. {
  118.     private double _addOnFixed = java.lang.Double.NaN;
  119.     private double _creditMultiplicativeScale = java.lang.Double.NaN;
  120.     private double _equityMultiplicativeScale = java.lang.Double.NaN;
  121.     private double _ratesFXMultiplicativeScale = java.lang.Double.NaN;
  122.     private double _commodityMultiplicativeScale = java.lang.Double.NaN;
  123.     private java.util.Map<java.lang.String, java.lang.Double> _productAddOnFactorMap = null;

  124.     /**
  125.      * Construct a Standard Instance of AdditionalInitialMargin
  126.      *
  127.      * @param addOnFixed The Fixed Add-On
  128.      * @param productAddOnFactorMap The Product Add-On Factor Map
  129.      *
  130.      * @return The Standard AdditionalInitialMargin Instance
  131.      */

  132.     public static final AdditionalInitialMargin Standard (
  133.         final double addOnFixed,
  134.         final java.util.Map<java.lang.String, java.lang.Double> productAddOnFactorMap)
  135.     {
  136.         try
  137.         {
  138.             return new AdditionalInitialMargin (
  139.                 org.drip.simm.common.ProductClassMultiplicativeScale.MS_RATESFX_DEFAULT,
  140.                 org.drip.simm.common.ProductClassMultiplicativeScale.MS_CREDIT_QUALIFYING_DEFAULT,
  141.                 org.drip.simm.common.ProductClassMultiplicativeScale.MS_EQUITY_DEFAULT,
  142.                 org.drip.simm.common.ProductClassMultiplicativeScale.MS_COMMODITY_DEFAULT,
  143.                 addOnFixed,
  144.                 productAddOnFactorMap
  145.             );
  146.         }
  147.         catch (java.lang.Exception e)
  148.         {
  149.             e.printStackTrace();
  150.         }

  151.         return null;
  152.     }

  153.     /**
  154.      * AdditionalInitialMargin Constructor
  155.      *
  156.      * @param ratesFXMultiplicativeScale The RatesFX Multiplicative Scale
  157.      * @param creditMultiplicativeScale The Credit Multiplicative Scale
  158.      * @param equityMultiplicativeScale The Equity Multiplicative Scale
  159.      * @param commodityMultiplicativeScale The Commodity Multiplicative Scale
  160.      * @param addOnFixed The Fixed Add-On
  161.      * @param productAddOnFactorMap The Product Add-On Factor Map
  162.      *
  163.      * @throws java.lang.Exception Thrown if the Inputs are Invalid
  164.      */

  165.     public AdditionalInitialMargin (
  166.         final double ratesFXMultiplicativeScale,
  167.         final double creditMultiplicativeScale,
  168.         final double equityMultiplicativeScale,
  169.         final double commodityMultiplicativeScale,
  170.         final double addOnFixed,
  171.         final java.util.Map<java.lang.String, java.lang.Double> productAddOnFactorMap)
  172.         throws java.lang.Exception
  173.     {
  174.         if (!org.drip.numerical.common.NumberUtil.IsValid (_ratesFXMultiplicativeScale =
  175.                 ratesFXMultiplicativeScale) || 1. > _ratesFXMultiplicativeScale ||
  176.             !org.drip.numerical.common.NumberUtil.IsValid (_creditMultiplicativeScale =
  177.                 creditMultiplicativeScale) || 1. > _creditMultiplicativeScale ||
  178.             !org.drip.numerical.common.NumberUtil.IsValid (_equityMultiplicativeScale =
  179.                 equityMultiplicativeScale) || 1. > _equityMultiplicativeScale ||
  180.             !org.drip.numerical.common.NumberUtil.IsValid (_commodityMultiplicativeScale =
  181.                 commodityMultiplicativeScale) || 1. > _commodityMultiplicativeScale ||
  182.             !org.drip.numerical.common.NumberUtil.IsValid (_addOnFixed = addOnFixed) || 0. > _addOnFixed)
  183.         {
  184.             throw new java.lang.Exception ("AdditionalInitialMargin Constructor => Invalid Inputs");
  185.         }

  186.         _productAddOnFactorMap = productAddOnFactorMap;
  187.     }

  188.     /**
  189.      * Retrieve the RatesFX Multiplicative Scale
  190.      *
  191.      * @return The RatesFX Multiplicative Scale
  192.      */

  193.     public double ratesFXMultiplicativeScale()
  194.     {
  195.         return _ratesFXMultiplicativeScale;
  196.     }

  197.     /**
  198.      * Retrieve the Credit Multiplicative Scale
  199.      *
  200.      * @return The Credit Multiplicative Scale
  201.      */

  202.     public double creditMultiplicativeScale()
  203.     {
  204.         return _creditMultiplicativeScale;
  205.     }

  206.     /**
  207.      * Retrieve the Equity Multiplicative Scale
  208.      *
  209.      * @return The Equity Multiplicative Scale
  210.      */

  211.     public double equityMultiplicativeScale()
  212.     {
  213.         return _equityMultiplicativeScale;
  214.     }

  215.     /**
  216.      * Retrieve the Commodity Multiplicative Scale
  217.      *
  218.      * @return The Commodity Multiplicative Scale
  219.      */

  220.     public double commodityMultiplicativeScale()
  221.     {
  222.         return _commodityMultiplicativeScale;
  223.     }

  224.     /**
  225.      * Retrieve the Fixed Add-On
  226.      *
  227.      * @return The Fixed Add-On
  228.      */

  229.     public double addOnFixed()
  230.     {
  231.         return _addOnFixed;
  232.     }

  233.     /**
  234.      * Retrieve the Product Add-On Factor Map
  235.      *
  236.      * @return The Product Add-On Factor Map
  237.      */

  238.     public java.util.Map<java.lang.String, java.lang.Double> productAddOnFactorMap()
  239.     {
  240.         return _productAddOnFactorMap;
  241.     }

  242.     /**
  243.      * Compute the Product Add On Estimate
  244.      *
  245.      * @param productNotionalMap The Product Notional Map
  246.      *
  247.      * @return The Product Add On Estimate
  248.      */

  249.     public double productAddOn (
  250.         final java.util.Map<java.lang.String, java.lang.Double> productNotionalMap)
  251.     {
  252.         if (null == productNotionalMap || 0 == productNotionalMap.size() ||
  253.             null == _productAddOnFactorMap || 0 == _productAddOnFactorMap.size())
  254.         {
  255.             return 0.;
  256.         }

  257.         double productAddOn = 0.;

  258.         for (java.util.Map.Entry<java.lang.String, java.lang.Double> productAddOnFactorEntry :
  259.             _productAddOnFactorMap.entrySet())
  260.         {
  261.             java.lang.String productID = productAddOnFactorEntry.getKey();

  262.             if (productNotionalMap.containsKey (productID))
  263.             {
  264.                 productAddOn = productAddOn + productAddOnFactorEntry.getValue() * productNotionalMap.get
  265.                     (productID);
  266.             }
  267.         }

  268.         return productAddOn;
  269.     }

  270.     /**
  271.      * Compute the Total IM Add On
  272.      *
  273.      * @param productNotionalMap The Product Notional Map
  274.      *
  275.      * @return The Total IM Add On
  276.      */

  277.     public double total (
  278.         final java.util.Map<java.lang.String, java.lang.Double> productNotionalMap)
  279.     {
  280.         return _addOnFixed + productAddOn (productNotionalMap);
  281.     }
  282. }