LastTradingDateSetting.java

  1. package org.drip.product.params;

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

  79. /**
  80.  * <i>LastTradingDateSetting</i> contains the Last Trading Date Generation Scheme for the given Option.
  81.  *
  82.  * <br><br>
  83.  *  <ul>
  84.  *      <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/ProductCore.md">Product Core Module</a></li>
  85.  *      <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/FixedIncomeAnalyticsLibrary.md">Fixed Income Analytics</a></li>
  86.  *      <li><b>Project</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/product/README.md">Product Components/Baskets for Credit, FRA, FX, Govvie, Rates, and Option AssetClasses</a></li>
  87.  *      <li><b>Package</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/product/params/README.md">Fixed Income Product Customization Parameters</a></li>
  88.  *  </ul>
  89.  * <br><br>
  90.  *
  91.  * @author Lakshmi Krishnamurthy
  92.  */

  93. public class LastTradingDateSetting {

  94.     /**
  95.      * Quarterly Mid-Curve Option
  96.      */

  97.     public static final int MID_CURVE_OPTION_QUARTERLY = 0;

  98.     /**
  99.      * Serial Mid-Curve Option
  100.      */

  101.     public static final int MID_CURVE_OPTION_SERIAL = 1;

  102.     /**
  103.      * Generic Mid-Curve Option
  104.      */

  105.     public static final int MID_CURVE_OPTION = 2;

  106.     private int _iMidCurveOptionType = -1;
  107.     private java.lang.String _strLastTradeExerciseLag = "";
  108.     private int _iLastTradingDate = java.lang.Integer.MIN_VALUE;

  109.     /**
  110.      * Retrieve the String Version of the Mid Curve Option Setting
  111.      *
  112.      * @param iMidCurveOptionType The Mid Curve Option Type
  113.      *
  114.      * @return String Version of the Mid Curve Option Setting
  115.      */

  116.     public static final java.lang.String MidCurveOptionString (
  117.         final int iMidCurveOptionType)
  118.     {
  119.         if (MID_CURVE_OPTION_QUARTERLY == iMidCurveOptionType) return "QUARTERLY";

  120.         if (MID_CURVE_OPTION_SERIAL == iMidCurveOptionType) return "SERIAL";

  121.         if (MID_CURVE_OPTION == iMidCurveOptionType) return "REGULAR";

  122.         return null;
  123.     }

  124.     /**
  125.      * LastTradingDateSetting Constructor
  126.      *
  127.      * @param iMidCurveOptionType Mid Curve Option Type
  128.      * @param strLastTradeExerciseLag Lag between the Exercise Date and the Last Option Trading Date
  129.      * @param iLastTradingDate The Last Trading Date
  130.      *
  131.      * @throws java.lang.Exception Thrown if the Inputs are invalid
  132.      */

  133.     public LastTradingDateSetting (
  134.         final int iMidCurveOptionType,
  135.         final java.lang.String strLastTradeExerciseLag,
  136.         final int iLastTradingDate)
  137.         throws java.lang.Exception
  138.     {
  139.         if (MID_CURVE_OPTION_QUARTERLY != (_iMidCurveOptionType = iMidCurveOptionType) &&
  140.             MID_CURVE_OPTION_SERIAL != _iMidCurveOptionType && MID_CURVE_OPTION != _iMidCurveOptionType)
  141.             throw new java.lang.Exception ("LastTradingDateSetting ctr => Invalid Inputs");

  142.         _iLastTradingDate = iLastTradingDate;
  143.         _strLastTradeExerciseLag = strLastTradeExerciseLag;

  144.         if ((MID_CURVE_OPTION == _iMidCurveOptionType && (null == _strLastTradeExerciseLag ||
  145.             _strLastTradeExerciseLag.isEmpty())) || (MID_CURVE_OPTION_SERIAL == _iMidCurveOptionType &&
  146.                 !org.drip.numerical.common.NumberUtil.IsValid (_iLastTradingDate)))
  147.             throw new java.lang.Exception ("LastTradingDateSetting ctr => Invalid Inputs");
  148.     }

  149.     /**
  150.      * Retrieve the Mid-Curve Option Type
  151.      *
  152.      * @return The Mid-Curve Option Type
  153.      */

  154.     public int midCurveOptionType()
  155.     {
  156.         return _iMidCurveOptionType;
  157.     }

  158.     /**
  159.      * Retrieve the Lag between the Last Trading and Exercise Date
  160.      *
  161.      * @return The Lag between the Last Trading and Exercise Date
  162.      */

  163.     public java.lang.String lastTradeExerciseLag()
  164.     {
  165.         return _strLastTradeExerciseLag;
  166.     }

  167.     /**
  168.      * Retrieve the Last Trading Date
  169.      *
  170.      * @return The Last Trading Date
  171.      */

  172.     public double lastTradingDate()
  173.     {
  174.         return _iLastTradingDate;
  175.     }

  176.     /**
  177.      * Compute the Last Trading Date
  178.      *
  179.      * @param iUnderlyingLastTradingDate The Last Trading Date for the Underlying
  180.      * @param strCalendar The Calendar
  181.      *
  182.      * @return The Last Trading Date
  183.      */

  184.     public int lastTradingDate (
  185.         final int iUnderlyingLastTradingDate,
  186.         final java.lang.String strCalendar)
  187.     {
  188.         if (MID_CURVE_OPTION_SERIAL == _iMidCurveOptionType) return _iLastTradingDate;

  189.         if (MID_CURVE_OPTION_QUARTERLY == _iMidCurveOptionType) return iUnderlyingLastTradingDate;

  190.         return new org.drip.analytics.date.JulianDate (iUnderlyingLastTradingDate).subtractTenorAndAdjust
  191.             (_strLastTradeExerciseLag, strCalendar).julian();
  192.     }

  193.     @Override public java.lang.String toString()
  194.     {
  195.         java.lang.String str = "MID CURVE OPTION::" + MidCurveOptionString (_iMidCurveOptionType);

  196.         if (MID_CURVE_OPTION_QUARTERLY == _iMidCurveOptionType) return str;

  197.         if (MID_CURVE_OPTION == _iMidCurveOptionType) return str + "@" + _strLastTradeExerciseLag;

  198.         if (MID_CURVE_OPTION_SERIAL == _iMidCurveOptionType) return str + "@" + _iLastTradingDate;

  199.         return null;
  200.     }
  201. }