DynamicsContainer.java

  1. package org.drip.exposure.evolver;

  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>DynamicsContainer</i> holds the Dynamics of the Economy with the following Traded Assets - the
  77.  * Numeraire Evolver Dynamics, the Terminal Latent State Evolver Dynamics, and the Primary Security Evolver
  78.  * Dynamics. The References are:
  79.  *  
  80.  * <br><br>
  81.  *      <ul>
  82.  *          <li>
  83.  *              Albanese, C., and L. Andersen (2014): Accounting for OTC Derivatives: Funding Adjustments and
  84.  *                  the Re-Hypothecation Option https://papers.ssrn.com/sol3/papers.cfm?abstract_id=2482955
  85.  *                  <b>eSSRN</b>
  86.  *          </li>
  87.  *          <li>
  88.  *              Burgard, C., and M. Kjaer (2013): Funding Costs, Funding Strategies <i>Risk</i> <b>23
  89.  *                  (12)</b> 82-87
  90.  *          </li>
  91.  *          <li>
  92.  *              Burgard, C., and M. Kjaer (2014): In the Balance <i>Risk</i> <b>24 (11)</b> 72-75
  93.  *          </li>
  94.  *          <li>
  95.  *              Burgard, C., and M. Kjaer (2017): Derivatives Funding, Netting, and Accounting
  96.  *                  https://papers.ssrn.com/sol3/papers.cfm?abstract_id=2534011 <b>eSSRN</b>
  97.  *          </li>
  98.  *          <li>
  99.  *              Piterbarg, V. (2010): Funding Beyond Discounting: Collateral Agreements and Derivatives
  100.  *                  Pricing <i>Risk</i> <b>21 (2)</b> 97-102
  101.  *          </li>
  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/ExposureAnalyticsLibrary.md">Exposure Analytics</a></li>
  109.  *      <li><b>Project</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/exposure/README.md">Exposure Group Level Collateralized/Uncollateralized Exposure</a></li>
  110.  *      <li><b>Package</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/exposure/evolver/README.md">Securities and Exposure States Evolvers</a></li>
  111.  *  </ul>
  112.  *
  113.  * @author Lakshmi Krishnamurthy
  114.  */

  115. public class DynamicsContainer
  116. {
  117.     private org.drip.exposure.evolver.LatentStateDynamicsContainer _latentStateDynamicsContainer = null;
  118.     private java.util.Map<java.lang.String, org.drip.exposure.evolver.PrimarySecurity> _mapPrimarySecurityDynamics
  119.         = null;
  120.     private java.util.Map<java.lang.String, org.drip.exposure.evolver.ScalingNumeraire>
  121.         _mapScalingNumeraireDynamics = null;

  122.     /**
  123.      * Empty DynamicsContainer Constructor
  124.      */

  125.     public DynamicsContainer()
  126.     {
  127.         _mapScalingNumeraireDynamics = new
  128.             org.drip.analytics.support.CaseInsensitiveHashMap<org.drip.exposure.evolver.ScalingNumeraire>();

  129.         _mapPrimarySecurityDynamics = new
  130.             org.drip.analytics.support.CaseInsensitiveHashMap<org.drip.exposure.evolver.PrimarySecurity>();

  131.         _latentStateDynamicsContainer = new org.drip.exposure.evolver.LatentStateDynamicsContainer();
  132.     }

  133.     /**
  134.      * Retrieve the Scaling Numeraire Evolver Dynamics Settings Map
  135.      *
  136.      * @return The Scaling Numeraire Evolver Dynamics Settings Map
  137.      */

  138.     public java.util.Map<java.lang.String, org.drip.exposure.evolver.ScalingNumeraire> scalingNumeraireMap()
  139.     {
  140.         return _mapScalingNumeraireDynamics;
  141.     }

  142.     /**
  143.      * Add the Named Scaling Numeraire
  144.      *
  145.      * @param numeraireName Name of the Scaling Numeraire
  146.      * @param numeraire Scaling Numeraire Instance
  147.      *
  148.      * @return TRUE - The Scaling Numeraire Successfully added
  149.      */

  150.     public boolean addScalingNumeraire (
  151.         final java.lang.String numeraireName,
  152.         final org.drip.exposure.evolver.ScalingNumeraire numeraire)
  153.     {
  154.         if (null == numeraireName || numeraireName.isEmpty() ||
  155.             null == numeraire)
  156.         {
  157.             return false;
  158.         }

  159.         _mapScalingNumeraireDynamics.put (
  160.             numeraireName,
  161.             numeraire
  162.         );

  163.         return true;
  164.     }

  165.     /**
  166.      * Indicate if the Scaling Numeraire Exists
  167.      *
  168.      * @param numeraireName The Scaling Numeraire Name
  169.      *
  170.      * @return TRUE - The Scaling Numeraire Exists
  171.      */

  172.     public boolean scalingNumeraireExists (
  173.         final java.lang.String numeraireName)
  174.     {
  175.         return null != numeraireName && !numeraireName.isEmpty() && _mapScalingNumeraireDynamics.containsKey
  176.             (numeraireName);
  177.     }

  178.     /**
  179.      * Retrieve the Scaling Numeraire
  180.      *
  181.      * @param numeraireName The Scaling Numeraire Name
  182.      *
  183.      * @return The Scaling Numeraire
  184.      */

  185.     public org.drip.exposure.evolver.ScalingNumeraire scalingNumeraire (
  186.         final java.lang.String numeraireName)
  187.     {
  188.         return !scalingNumeraireExists (numeraireName) ? null : _mapScalingNumeraireDynamics.get
  189.             (numeraireName);
  190.     }

  191.     /**
  192.      * Retrieve the Terminal Latent State Evolver Dynamics Settings Map
  193.      *
  194.      * @return The Terminal Latent State Evolver Dynamics Settings Map
  195.      */

  196.     public org.drip.exposure.evolver.LatentStateDynamicsContainer terminalLatentStateContainer()
  197.     {
  198.         return _latentStateDynamicsContainer;
  199.     }

  200.     /**
  201.      * Add the Terminal Latent State
  202.      *
  203.      * @param terminalLatentState The Terminal Latent State
  204.      *
  205.      * @return TRUE - The Terminal Latent State successfully added
  206.      */

  207.     public boolean addTerminalLatentState (
  208.         final org.drip.exposure.evolver.TerminalLatentState terminalLatentState)
  209.     {
  210.         return _latentStateDynamicsContainer.addTerminalLatentState (terminalLatentState) &&
  211.             addScalingNumeraire (
  212.                 terminalLatentState.label().fullyQualifiedName(),
  213.                 terminalLatentState
  214.             );
  215.     }

  216.     /**
  217.      * Indicate if the Terminal Latent State Exists
  218.      *
  219.      * @param label The Terminal Latent State Label
  220.      *
  221.      * @return TRUE - The Terminal Latent State Exists
  222.      */

  223.     public boolean terminalLatentStateExists (
  224.         final org.drip.state.identifier.LatentStateLabel label)
  225.     {
  226.         return _latentStateDynamicsContainer.labelExists (label);
  227.     }

  228.     /**
  229.      * Retrieve the Primary Security Evolver Dynamics Settings Map
  230.      *
  231.      * @return The Primary Security Evolver Dynamics Settings Map
  232.      */

  233.     public java.util.Map<java.lang.String, org.drip.exposure.evolver.PrimarySecurity> primarySecurityMap()
  234.     {
  235.         return _mapPrimarySecurityDynamics;
  236.     }

  237.     /**
  238.      * Add the Specified Primary Security Instance
  239.      *
  240.      * @param primarySecurity The Primary Security
  241.      *
  242.      * @return TRUE - The Primary Security Successfully Added
  243.      */

  244.     public boolean addPrimarySecurity (
  245.         final org.drip.exposure.evolver.PrimarySecurity primarySecurity)
  246.     {
  247.         if (null == primarySecurity)
  248.         {
  249.             return false;
  250.         }

  251.         _mapPrimarySecurityDynamics.put (
  252.             primarySecurity.id(),
  253.             primarySecurity
  254.         );

  255.         return addTerminalLatentState (primarySecurity) && addScalingNumeraire (
  256.             primarySecurity.label().fullyQualifiedName(),
  257.             primarySecurity
  258.         );
  259.     }

  260.     /**
  261.      * Indicate if the Primary Security Evolver exists in the Container
  262.      *
  263.      * @param id The Primary Security ID
  264.      *
  265.      * @return TRUE - The Primary Security Evolver exists in the Container
  266.      */

  267.     public boolean primarySecurityExists (
  268.         final java.lang.String id)
  269.     {
  270.         return null == id || id.isEmpty() ? false : _mapPrimarySecurityDynamics.containsKey (id);
  271.     }

  272.     /**
  273.      * Retrieve the Primary Security Evolver given the Label
  274.      *
  275.      * @param id The Primary Security ID
  276.      *
  277.      * @return The Primary Security Evolver
  278.      */

  279.     public org.drip.exposure.evolver.PrimarySecurity primarySecurity (
  280.         final java.lang.String id)
  281.     {
  282.         return primarySecurityExists (id) ? _mapPrimarySecurityDynamics.get (id) : null;
  283.     }
  284. }