PositionGroupSpecification.java

  1. package org.drip.xva.proto;

  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>PositionGroupSpecification</i> contains the Specification of a Named Position Group. The References
  77.  * are:
  78.  *
  79.  *  <br><br>
  80.  *  <ul>
  81.  *      <li>
  82.  *          Burgard, C., and M. Kjaer (2014): PDE Representations of Derivatives with Bilateral Counter-party
  83.  *              Risk and Funding Costs <i>Journal of Credit Risk</i> <b>7 (3)</b> 1-19
  84.  *      </li>
  85.  *      <li>
  86.  *          Burgard, C., and M. Kjaer (2014): In the Balance <i>Risk</i> <b>24 (11)</b> 72-75
  87.  *      </li>
  88.  *      <li>
  89.  *          Gregory, J. (2009): Being Two-faced over Counter-party Credit Risk <i>Risk</i> <b>20 (2)</b>
  90.  *              86-90
  91.  *      </li>
  92.  *      <li>
  93.  *          Li, B., and Y. Tang (2007): <i>Quantitative Analysis, Derivatives Modeling, and Trading
  94.  *              Strategies in the Presence of Counter-party Credit Risk for the Fixed Income Market</i>
  95.  *              <b>World Scientific Publishing</b> Singapore
  96.  *      </li>
  97.  *      <li>
  98.  *          Piterbarg, V. (2010): Funding Beyond Discounting: Collateral Agreements and Derivatives Pricing
  99.  *              <i>Risk</i> <b>21 (2)</b> 97-102
  100.  *      </li>
  101.  *  </ul>
  102.  *
  103.  *  <br><br>
  104.  *  <ul>
  105.  *      <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/PortfolioCore.md">Portfolio Core Module</a></li>
  106.  *      <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/XVAAnalyticsLibrary.md">XVA Analytics Library</a></li>
  107.  *      <li><b>Project</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/xva/README.md">Valuation Adjustments that account for Collateral, CC Credit/Debt and Funding Overhead</a></li>
  108.  *      <li><b>Package</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/xva/proto/README.md">Collateral, Counter Party, Netting Groups</a></li>
  109.  *  </ul>
  110.  * <br><br>
  111.  *
  112.  * @author Lakshmi Krishnamurthy
  113.  */

  114. public class PositionGroupSpecification extends org.drip.xva.proto.ObjectSpecification
  115. {
  116.     private int _closeOutScheme = -1;
  117.     private int _brokenDateScheme = -1;
  118.     private int _clientDefaultWindow = -1;
  119.     private int _dealerDefaultWindow = -1;
  120.     private int _positionReplicationScheme = -1;
  121.     private double _hedgeError = java.lang.Double.NaN;
  122.     private double _independentAmount = java.lang.Double.NaN;
  123.     private double _minimumTransferAmount = java.lang.Double.NaN;
  124.     private org.drip.function.definition.R1ToR1 _dealerThresholdFunction = null;
  125.     private org.drip.function.definition.R1ToR1[] _clientThresholdFunctionArray = null;

  126.     /**
  127.      * Generate a Zero-Threshold Instance of the Named Position Group
  128.      *
  129.      * @param name The Collateral Group Name
  130.      * @param positionReplicationScheme Position Replication Scheme
  131.      * @param brokenDateScheme Broken Date Interpolation Scheme
  132.      * @param hedgeError Hedge Error
  133.      * @param closeOutScheme Close Out Scheme
  134.      *
  135.      * @return The Zero-Threshold Instance of the Named Position Group
  136.      */

  137.     public static final PositionGroupSpecification ZeroThreshold (
  138.         final java.lang.String name,
  139.         final int positionReplicationScheme,
  140.         final int brokenDateScheme,
  141.         final double hedgeError,
  142.         final int closeOutScheme)
  143.     {
  144.         try
  145.         {
  146.             return new PositionGroupSpecification (
  147.                 org.drip.numerical.common.StringUtil.GUID(),
  148.                 name,
  149.                 14,
  150.                 14,
  151.                 null,
  152.                 null,
  153.                 0.,
  154.                 0.,
  155.                 positionReplicationScheme,
  156.                 brokenDateScheme,
  157.                 hedgeError,
  158.                 closeOutScheme
  159.             );
  160.         }
  161.         catch (java.lang.Exception e)
  162.         {
  163.             e.printStackTrace();
  164.         }

  165.         return null;
  166.     }

  167.     /**
  168.      * Generate a Fixed-Threshold Instance of the Named Position Group
  169.      *
  170.      * @param name The Collateral Group Name
  171.      * @param clientThreshold The Fixed Client Threshold
  172.      * @param dealerThreshold The Fixed Dealer Threshold
  173.      * @param positionReplicationScheme Position Replication Scheme
  174.      * @param brokenDateScheme Broken Date Interpolation Scheme
  175.      * @param hedgeError Hedge Error
  176.      * @param closeOutScheme Close Out Scheme
  177.      *
  178.      * @return The Fixed-Threshold Instance of the Named Position Group
  179.      */

  180.     public static final PositionGroupSpecification FixedThreshold (
  181.         final java.lang.String name,
  182.         final double clientThreshold,
  183.         final double dealerThreshold,
  184.         final int positionReplicationScheme,
  185.         final int brokenDateScheme,
  186.         final double hedgeError,
  187.         final int closeOutScheme)
  188.     {
  189.         if (!org.drip.numerical.common.NumberUtil.IsValid (clientThreshold) || 0. > clientThreshold ||
  190.             !org.drip.numerical.common.NumberUtil.IsValid (dealerThreshold) || 0. < dealerThreshold)
  191.         {
  192.             return null;
  193.         }

  194.         try
  195.         {
  196.             return new PositionGroupSpecification (
  197.                 org.drip.numerical.common.StringUtil.GUID(),
  198.                 name,
  199.                 14,
  200.                 14,
  201.                 new org.drip.function.r1tor1.FlatUnivariate[]
  202.                 {
  203.                     new org.drip.function.r1tor1.FlatUnivariate (clientThreshold)
  204.                 },
  205.                 new org.drip.function.r1tor1.FlatUnivariate (dealerThreshold),
  206.                 0.,
  207.                 0.,
  208.                 positionReplicationScheme,
  209.                 brokenDateScheme,
  210.                 hedgeError,
  211.                 closeOutScheme
  212.             );
  213.         }
  214.         catch (java.lang.Exception e)
  215.         {
  216.             e.printStackTrace();
  217.         }

  218.         return null;
  219.     }

  220.     /**
  221.      * PositionGroupSpecification Constructor
  222.      *
  223.      * @param id The Exposure Roll Up Group ID
  224.      * @param name The Exposure Roll Up Group Name
  225.      * @param clientDefaultWindow The Client Default Window
  226.      * @param dealerDefaultWindow The Dealer Default Window
  227.      * @param clientThresholdFunctionArray The Array of Collateral Group Client Threshold R^1 - R^1 Functions
  228.      * @param dealerThresholdFunction The Collateral Group Dealer Threshold R^1 - R^1 Function
  229.      * @param minimumTransferAmount The Collateral Group Minimum Transfer Amount
  230.      * @param independentAmount The Collateral Group Independent Amount
  231.      * @param positionReplicationScheme Position Replication Scheme
  232.      * @param brokenDateScheme Broken Date Interpolation Scheme
  233.      * @param hedgeError Hedge Error
  234.      * @param closeOutScheme Close Out Scheme
  235.      *
  236.      * @throws java.lang.Exception Thrown if the Inputs are Invalid
  237.      */

  238.     public PositionGroupSpecification (
  239.         final java.lang.String id,
  240.         final java.lang.String name,
  241.         final int clientDefaultWindow,
  242.         final int dealerDefaultWindow,
  243.         final org.drip.function.definition.R1ToR1[] clientThresholdFunctionArray,
  244.         final org.drip.function.definition.R1ToR1 dealerThresholdFunction,
  245.         final double minimumTransferAmount,
  246.         final double independentAmount,
  247.         final int positionReplicationScheme,
  248.         final int brokenDateScheme,
  249.         final double hedgeError,
  250.         final int closeOutScheme)
  251.         throws java.lang.Exception
  252.     {
  253.         super (
  254.             id,
  255.             name
  256.         );

  257.         if (-1 >= (_clientDefaultWindow = clientDefaultWindow) ||
  258.             -1 >= (_dealerDefaultWindow = dealerDefaultWindow) ||
  259.             !org.drip.numerical.common.NumberUtil.IsValid (_minimumTransferAmount = minimumTransferAmount) ||
  260.             !org.drip.numerical.common.NumberUtil.IsValid (_independentAmount = independentAmount) ||
  261.             !org.drip.numerical.common.NumberUtil.IsValid (_hedgeError = hedgeError))
  262.         {
  263.             throw new java.lang.Exception ("PositionGroupSpecification Constructor => Invalid Inputs");
  264.         }

  265.         _closeOutScheme = closeOutScheme;
  266.         _brokenDateScheme = brokenDateScheme;
  267.         _dealerThresholdFunction = dealerThresholdFunction;
  268.         _positionReplicationScheme = positionReplicationScheme;
  269.         _clientThresholdFunctionArray = clientThresholdFunctionArray;
  270.     }

  271.     /**
  272.      * Retrieve the Client Default Window
  273.      *
  274.      * @return The Client Default Window
  275.      */

  276.     public int clientDefaultWindow()
  277.     {
  278.         return _clientDefaultWindow;
  279.     }

  280.     /**
  281.      * Retrieve the Dealer Default Window
  282.      *
  283.      * @return The Dealer Default Window
  284.      */

  285.     public int dealerDefaultWindow()
  286.     {
  287.         return _dealerDefaultWindow;
  288.     }

  289.     /**
  290.      * Retrieve the Array of the Collateral Group Client Threshold R^1 - R^1 Functions
  291.      *
  292.      * @return The Array of the Collateral Group Client Threshold R^1 - R^1 Functions
  293.      */

  294.     public org.drip.function.definition.R1ToR1[] clientThresholdFunctionArray()
  295.     {
  296.         return _clientThresholdFunctionArray;
  297.     }

  298.     /**
  299.      * Retrieve the Collateral Group Dealer Threshold R^1 - R^1 Function
  300.      *
  301.      * @return The Collateral Group Dealer Threshold R^1 - R^1 Function
  302.      */

  303.     public org.drip.function.definition.R1ToR1 dealerThresholdFunction()
  304.     {
  305.         return _dealerThresholdFunction;
  306.     }

  307.     /**
  308.      * Retrieve the Collateral Group Minimum Transfer Amount
  309.      *
  310.      * @return The Collateral Group Minimum Transfer Amount
  311.      */

  312.     public double minimumTransferAmount()
  313.     {
  314.         return _minimumTransferAmount;
  315.     }

  316.     /**
  317.      * Retrieve the Collateral Group Independent Amount
  318.      *
  319.      * @return The Collateral Group Independent Amount
  320.      */

  321.     public double independentAmount()
  322.     {
  323.         return _independentAmount;
  324.     }

  325.     /**
  326.      * Retrieve the Position Replication Scheme
  327.      *
  328.      * @return The Position Replication Scheme
  329.      */

  330.     public int positionReplicationScheme()
  331.     {
  332.         return _positionReplicationScheme;
  333.     }

  334.     /**
  335.      * Retrieve the Broken Date Interpolation Scheme
  336.      *
  337.      * @return The Broken Date Interpolation Scheme
  338.      */

  339.     public int brokenDateScheme()
  340.     {
  341.         return _brokenDateScheme;
  342.     }

  343.     /**
  344.      * Retrieve the Hedge Error
  345.      *
  346.      * @return The Hedge Error
  347.      */

  348.     public double hedgeError()
  349.     {
  350.         return _hedgeError;
  351.     }

  352.     /**
  353.      * Retrieve the Close Out Scheme
  354.      *
  355.      * @return The Close Out Scheme
  356.      */

  357.     public int closeOutScheme()
  358.     {
  359.         return _closeOutScheme;
  360.     }

  361.     /**
  362.      * Retrieve the Flag specifying whether the Collateral Group is Uncollateralized
  363.      *
  364.      * @return TRUE - The Collateral Group is Uncollateralized
  365.      */

  366.     public boolean isUncollateralized()
  367.     {
  368.         return null == _clientThresholdFunctionArray && null == _dealerThresholdFunction;
  369.     }
  370. }