EqualityConstraintSettings.java

  1. package org.drip.portfolioconstruction.allocator;

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

  77. /**
  78.  * <i>EqualityConstraintSettings</i> holds the Parameters required to generate the Mandatory Constraints for
  79.  * the Portfolio.
  80.  *
  81.  *  <br><br>
  82.  *  <ul>
  83.  *      <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/PortfolioCore.md">Portfolio Core Module</a></li>
  84.  *      <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/AssetAllocationAnalyticsLibrary.md">Asset Allocation Analytics</a></li>
  85.  *      <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>
  86.  *      <li><b>Package</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/portfolioconstruction/allocator/README.md">MVO Based Portfolio Allocation Construction</a></li>
  87.  *  </ul>
  88.  *
  89.  * @author Lakshmi Krishnamurthy
  90.  */

  91. public class EqualityConstraintSettings
  92. {

  93.     /**
  94.      * NO_CONSTRAINT - No Constraint of any Kind
  95.      */

  96.     public static final int NO_CONSTRAINT = 1;

  97.     /**
  98.      * FULLY_INVESTED_CONSTRAINT - The Mandatory Completely Invested Constraint
  99.      */

  100.     public static final int FULLY_INVESTED_CONSTRAINT = 2;

  101.     /**
  102.      * RETURNS_CONSTRAINT - The Mandatory Returns Constraint
  103.      */

  104.     public static final int RETURNS_CONSTRAINT = 4;

  105.     private int _constraintType = -1;
  106.     private double _returnsConstraint = java.lang.Double.NaN;

  107.     /**
  108.      * Construct an Unconstrained Instance of EqualityConstraintSettings
  109.      *
  110.      * @return Unconstrained EqualityConstraintSettings Instance
  111.      */

  112.     public static final EqualityConstraintSettings Unconstrained()
  113.     {
  114.         try
  115.         {
  116.             return new EqualityConstraintSettings (
  117.                 NO_CONSTRAINT,
  118.                 java.lang.Double.NaN
  119.             );
  120.         }
  121.         catch (java.lang.Exception e)
  122.         {
  123.             e.printStackTrace();
  124.         }

  125.         return null;
  126.     }

  127.     /**
  128.      * Construct a Fully Invested Instance of EqualityConstraintSettings
  129.      *
  130.      * @return Fully Invested EqualityConstraintSettings Instance
  131.      */

  132.     public static final EqualityConstraintSettings FullyInvested()
  133.     {
  134.         try
  135.         {
  136.             return new EqualityConstraintSettings (
  137.                 FULLY_INVESTED_CONSTRAINT,
  138.                 java.lang.Double.NaN
  139.             );
  140.         }
  141.         catch (java.lang.Exception e)
  142.         {
  143.             e.printStackTrace();
  144.         }

  145.         return null;
  146.     }

  147.     /**
  148.      * Construct a Returns Constrained Instance of EqualityConstraintSettings
  149.      *
  150.      * @param returnsConstraint The Returns Constraint
  151.      *
  152.      * @return Returns Constrained EqualityConstraintSettings Instance
  153.      */

  154.     public static final EqualityConstraintSettings ReturnsConstrained (
  155.         final double returnsConstraint)
  156.     {
  157.         try
  158.         {
  159.             return new EqualityConstraintSettings (
  160.                 FULLY_INVESTED_CONSTRAINT | RETURNS_CONSTRAINT,
  161.                 returnsConstraint
  162.             );
  163.         }
  164.         catch (java.lang.Exception e)
  165.         {
  166.             e.printStackTrace();
  167.         }

  168.         return null;
  169.     }

  170.     /**
  171.      * EqualityConstraintSettings Constructor
  172.      *
  173.      * @param constraintType The Constraint Type
  174.      * @param returnsConstraint The Returns Constraint
  175.      *
  176.      * @throws java.lang.Exception Thrown if the Inputs are Invalid
  177.      */

  178.     public EqualityConstraintSettings (
  179.         final int constraintType,
  180.         final double returnsConstraint)
  181.         throws java.lang.Exception
  182.     {
  183.         _constraintType = constraintType;
  184.         _returnsConstraint = returnsConstraint;

  185.         if (0 == (NO_CONSTRAINT & _constraintType) && 0 == (FULLY_INVESTED_CONSTRAINT & _constraintType) &&
  186.             0 == (RETURNS_CONSTRAINT & _constraintType))
  187.         {
  188.             throw new java.lang.Exception ("EqualityConstraintSettings Constructor => Invalid Inputs!");
  189.         }

  190.         if (0 != (RETURNS_CONSTRAINT & _constraintType) && !org.drip.numerical.common.NumberUtil.IsValid
  191.             (_returnsConstraint))
  192.         {
  193.             throw new java.lang.Exception ("EqualityConstraintSettings Constructor => Invalid Inputs!");
  194.         }
  195.     }

  196.     /**
  197.      * Retrieve the Constraint Type
  198.      *
  199.      * @return The Constraint Type
  200.      */

  201.     public int constraintType()
  202.     {
  203.         return _constraintType;
  204.     }

  205.     /**
  206.      * Retrieve the Returns Constraint
  207.      *
  208.      * @return The Returns Constraint
  209.      */

  210.     public double returnsConstraint()
  211.     {
  212.         return _returnsConstraint;
  213.     }
  214. }