LimitChargeTermIssuer.java

  1. package org.drip.portfolioconstruction.constraint;

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

  76. /**
  77.  * <i>LimitChargeTermIssuer</i> constrains the Limit Issuer Transaction Charge Term.
  78.  *
  79.  *  <br><br>
  80.  *  <ul>
  81.  *      <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/PortfolioCore.md">Portfolio Core Module</a></li>
  82.  *      <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/AssetAllocationAnalyticsLibrary.md">Asset Allocation Analytics</a></li>
  83.  *      <li><b>Project</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/portfolioconstruction/README.md">Portfolio Construction under Allocation Constraints</a></li>
  84.  *      <li><b>Package</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/portfolioconstruction/constraint/README.md"> Portfolio Construction Constraint Term Suite</a></li>
  85.  *  </ul>
  86.  * <br><br>
  87.  *
  88.  * @author Lakshmi Krishnamurthy
  89.  */

  90. public class LimitChargeTermIssuer
  91.     extends org.drip.portfolioconstruction.optimizer.ConstraintTerm
  92. {
  93.     private double[] _initialHoldingsArray = null;
  94.     private org.drip.portfolioconstruction.cost.TransactionCharge[] _transactionChargeArray = null;


  95.     /**
  96.      * Construct a Static Instance of LimitChargeTermIssuer
  97.      *
  98.      * @param name Name of the LimitChargeTermIssuer Constraint
  99.      * @param scope Scope of the LimitChargeTermIssuer Constraint
  100.      * @param unit Unit of the LimitChargeTermIssuer Constraint
  101.      * @param minimum Minimum Value for the LimitChargeTermIssuer Constraint
  102.      * @param maximum Maximum Value for the LimitChargeTermIssuer Constraint
  103.      * @param initialHoldingsArray Array of Initial Holdings
  104.      * @param transactionChargeArray Array of Transaction Charge
  105.      *
  106.      * @return Instance of LimitChargeTermIssuer
  107.      */

  108.     public static final LimitChargeTermIssuer Standard (
  109.         final java.lang.String name,
  110.         final org.drip.portfolioconstruction.optimizer.Scope scope,
  111.         final org.drip.portfolioconstruction.optimizer.Unit unit,
  112.         final double minimum,
  113.         final double maximum,
  114.         final double[] initialHoldingsArray,
  115.         final org.drip.portfolioconstruction.cost.TransactionCharge[] transactionChargeArray)
  116.     {
  117.         try
  118.         {
  119.             return new LimitChargeTermIssuer (
  120.                 name,
  121.                 "CT_LIMIT_TRANSACTION_CHARGE",
  122.                 "Constrains the Total Transaction Charge",
  123.                 scope,
  124.                 unit,
  125.                 minimum,
  126.                 maximum,
  127.                 initialHoldingsArray,
  128.                 transactionChargeArray
  129.             );
  130.         }
  131.         catch (java.lang.Exception e)
  132.         {
  133.             e.printStackTrace();
  134.         }

  135.         return null;
  136.     }

  137.     /**
  138.      * Construct a Static Instance of GoldmanSachsShortfall LimitChargeTermIssuer
  139.      *
  140.      * @param name Name of the LimitChargeTermIssuer Constraint
  141.      * @param scope Scope of the LimitChargeTermIssuer Constraint
  142.      * @param unit Unit of the LimitChargeTermIssuer Constraint
  143.      * @param minimum Minimum Value for the LimitChargeTermIssuer Constraint
  144.      * @param maximum Maximum Value for the LimitChargeTermIssuer Constraint
  145.      * @param initialHoldingsArray Array of Initial Holdings
  146.      * @param goldmanSachsShortfallTransactionChargeArray Array of GoldmanSachsShortfall Transaction Charge
  147.      *
  148.      * @return Instance of GoldmanSachsShortfall LimitChargeTermIssuer
  149.      */

  150.     public static final LimitChargeTermIssuer GoldmanSachsShortfall (
  151.         final java.lang.String name,
  152.         final org.drip.portfolioconstruction.optimizer.Scope scope,
  153.         final org.drip.portfolioconstruction.optimizer.Unit unit,
  154.         final double minimum,
  155.         final double maximum,
  156.         final double[] initialHoldingsArray,
  157.         final org.drip.portfolioconstruction.cost.TransactionChargeGoldmanSachsShortfall[]
  158.             goldmanSachsShortfallTransactionChargeArray)
  159.     {
  160.         try
  161.         {
  162.             return new LimitChargeTermIssuer (
  163.                 name,
  164.                 "CT_LIMIT_GOLDMAN_SACHS_SHORTFALL",
  165.                 "Constrains the Total Transaction Charge using the Goldman Sachs Shortfall Model",
  166.                 scope,
  167.                 unit,
  168.                 minimum,
  169.                 maximum,
  170.                 initialHoldingsArray,
  171.                 goldmanSachsShortfallTransactionChargeArray
  172.             );
  173.         }
  174.         catch (java.lang.Exception e)
  175.         {
  176.             e.printStackTrace();
  177.         }

  178.         return null;
  179.     }

  180.     /**
  181.      * LimitChargeTermIssuer Constructor
  182.      *
  183.      * @param name Name of the LimitChargeTermIssuer Constraint
  184.      * @param strID ID of the LimitChargeTermIssuer Constraint
  185.      * @param strDescription Description of the LimitChargeTermIssuer Constraint
  186.      * @param scope Scope of the LimitChargeTermIssuer Constraint
  187.      * @param unit Unit of the LimitChargeTermIssuer Constraint
  188.      * @param minimum Minimum Value for the LimitChargeTermIssuer Constraint
  189.      * @param maximum Maximum Value for the LimitChargeTermIssuer Constraint
  190.      * @param initialHoldingsArray Array of Initial Holdings
  191.      * @param transactionChargeArray Array of Transaction Charge
  192.      *
  193.      * @throws java.lang.Exception Thrown if the Inputs are Invalid
  194.      */

  195.     public LimitChargeTermIssuer (
  196.         final java.lang.String name,
  197.         final java.lang.String strID,
  198.         final java.lang.String strDescription,
  199.         final org.drip.portfolioconstruction.optimizer.Scope scope,
  200.         final org.drip.portfolioconstruction.optimizer.Unit unit,
  201.         final double minimum,
  202.         final double maximum,
  203.         final double[] initialHoldingsArray,
  204.         final org.drip.portfolioconstruction.cost.TransactionCharge[] transactionChargeArray)
  205.         throws java.lang.Exception
  206.     {
  207.         super (
  208.             name,
  209.             strID,
  210.             strDescription,
  211.             "LIMIT_TRANSACTION_CHARGE",
  212.             scope,
  213.             unit,
  214.             minimum,
  215.             maximum
  216.         );

  217.         if (null == (_initialHoldingsArray = initialHoldingsArray) ||
  218.             null == (_transactionChargeArray = transactionChargeArray))
  219.         {
  220.             throw new java.lang.Exception ("LimitChargeTermIssuer Constructor => Invalid Inputs");
  221.         }

  222.         int assetCount = _initialHoldingsArray.length;

  223.         if (0 == assetCount || assetCount != _transactionChargeArray.length)
  224.         {
  225.             throw new java.lang.Exception ("LimitChargeTermIssuer Constructor => Invalid Inputs");
  226.         }

  227.         for (int assetIndex = 0; assetIndex < assetCount; ++assetIndex)
  228.         {
  229.             if (!org.drip.numerical.common.NumberUtil.IsValid (_initialHoldingsArray[assetIndex]) ||
  230.                 null == _transactionChargeArray[assetIndex])
  231.             {
  232.                 throw new java.lang.Exception ("LimitChargeTermIssuer Constructor => Invalid Inputs");
  233.             }
  234.         }
  235.     }

  236.     /**
  237.      * Retrieve the Array of Initial Holdings
  238.      *
  239.      * @return The Initial Holdings Array
  240.      */

  241.     public double[] initialHoldingsArray()
  242.     {
  243.         return _initialHoldingsArray;
  244.     }

  245.     /**
  246.      * Retrieve the Array of Transaction Charges
  247.      *
  248.      * @return The Transaction Charge Array
  249.      */

  250.     public org.drip.portfolioconstruction.cost.TransactionCharge[] transactionChargeArray()
  251.     {
  252.         return _transactionChargeArray;
  253.     }

  254.     @Override public org.drip.function.definition.RdToR1 rdtoR1()
  255.     {
  256.         return new org.drip.function.definition.RdToR1 (null)
  257.         {
  258.             @Override public int dimension()
  259.             {
  260.                 return _initialHoldingsArray.length;
  261.             }

  262.             @Override public double evaluate (
  263.                 final double[] finalHoldingsArray)
  264.                 throws java.lang.Exception
  265.             {
  266.                 double limitChargeIssuer = 0.;
  267.                 int assetCount = _initialHoldingsArray.length;

  268.                 if (null == finalHoldingsArray ||
  269.                     !org.drip.numerical.common.NumberUtil.IsValid (finalHoldingsArray) ||
  270.                     finalHoldingsArray.length != assetCount)
  271.                 {
  272.                     throw new java.lang.Exception
  273.                         ("LimitChargeTermIssuer::rdToR1::evaluate => Invalid Variate Dimension");
  274.                 }

  275.                 for (int assetIndex = 0; assetIndex < assetCount; ++assetIndex)
  276.                 {
  277.                     limitChargeIssuer += _transactionChargeArray[assetIndex].estimate (
  278.                         _initialHoldingsArray[assetIndex],
  279.                         finalHoldingsArray[assetIndex]
  280.                     );
  281.                 }

  282.                 return limitChargeIssuer;
  283.             }
  284.         };
  285.     }
  286. }