TreasuryFuturesConvention.java

  1. package org.drip.market.exchange;

  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>TreasuryFuturesConvention</i> contains the Details for the Futures Basket of the Exchange-Traded
  81.  * Treasury Futures Contracts.
  82.  *
  83.  *  <br><br>
  84.  *  <ul>
  85.  *      <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/ProductCore.md">Product Core Module</a></li>
  86.  *      <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/FixedIncomeAnalyticsLibrary.md">Fixed Income Analytics Library</a></li>
  87.  *      <li><b>Project</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/market">Static Market Fields - the Definitions, the OTC/Exchange Traded Products, and Treasury Settings</a></li>
  88.  *      <li><b>Package</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/market/exchange">Deliverable Swap, STIR, Treasury Futures</a></li>
  89.  *  </ul>
  90.  *
  91.  * @author Lakshmi Krishnamurthy
  92.  */

  93. public class TreasuryFuturesConvention {
  94.     private java.lang.String _strName = "";
  95.     private java.lang.String _strCalendar = "";
  96.     private java.lang.String _strCurrency = "";
  97.     private java.lang.String[] _astrCode = null;
  98.     private java.lang.String[] _astrExchange = null;
  99.     private java.lang.String _strMaturityTenor = "";
  100.     private java.lang.String _strUnderlierType = "";
  101.     private java.lang.String _strUnderlierSubtype = "";
  102.     private double _dblBasketNotional = java.lang.Double.NaN;
  103.     private double _dblMinimumPriceMovement = java.lang.Double.NaN;
  104.     private org.drip.market.exchange.TreasuryFuturesSettle _bfs = null;
  105.     private org.drip.analytics.eventday.DateInMonth _dimExpiry = null;
  106.     private double _dblComponentNotionalMinimum = java.lang.Double.NaN;
  107.     private org.drip.market.exchange.TreasuryFuturesEligibility _bfe = null;

  108.     /**
  109.      * TreasuryFuturesConvention Constructor
  110.      *
  111.      * @param strName The Futures Name
  112.      * @param astrCode The Array of the Futures Codes
  113.      * @param strCurrency The Futures Currency
  114.      * @param strCalendar The Futures Settle Calendar
  115.      * @param strMaturityTenor The Maturity Tenor
  116.      * @param dblBasketNotional Basket Notional
  117.      * @param dblMinimumPriceMovement The Minimum Price Movement
  118.      * @param dblComponentNotionalMinimum The Minimum Component Notional
  119.      * @param astrExchange Exchange Array
  120.      * @param strUnderlierType Underlier Type
  121.      * @param strUnderlierSubtype Underlier Sub-Type
  122.      * @param dimExpiry The Expiry Date-In-Month Setting
  123.      * @param bfe Eligibility Settings
  124.      * @param bfs Settlement Settings
  125.      *
  126.      * @throws java.lang.Exception Thrown if the Inputs are Invalid
  127.      */

  128.     public TreasuryFuturesConvention (
  129.         final java.lang.String strName,
  130.         final java.lang.String[] astrCode,
  131.         final java.lang.String strCurrency,
  132.         final java.lang.String strCalendar,
  133.         final java.lang.String strMaturityTenor,
  134.         final double dblBasketNotional,
  135.         final double dblMinimumPriceMovement,
  136.         final double dblComponentNotionalMinimum,
  137.         final java.lang.String[] astrExchange,
  138.         final java.lang.String strUnderlierType,
  139.         final java.lang.String strUnderlierSubtype,
  140.         final org.drip.analytics.eventday.DateInMonth dimExpiry,
  141.         final org.drip.market.exchange.TreasuryFuturesEligibility bfe,
  142.         final org.drip.market.exchange.TreasuryFuturesSettle bfs)
  143.         throws java.lang.Exception
  144.     {
  145.         if (null == (_strName = strName) || _strName.isEmpty() || null == (_astrCode = astrCode) || 0 ==
  146.             _astrCode.length || null == (_strCurrency = strCurrency) || _strCurrency.isEmpty() || null ==
  147.                 (_strMaturityTenor = strMaturityTenor) || _strMaturityTenor.isEmpty() ||
  148.                     !org.drip.numerical.common.NumberUtil.IsValid (_dblBasketNotional = dblBasketNotional) ||
  149.                         !org.drip.numerical.common.NumberUtil.IsValid (_dblMinimumPriceMovement =
  150.                             dblMinimumPriceMovement) || !org.drip.numerical.common.NumberUtil.IsValid
  151.                                 (_dblComponentNotionalMinimum = dblComponentNotionalMinimum) || null ==
  152.                                     (_astrExchange = astrExchange) || 0 == _astrExchange.length || null ==
  153.                                         (_strUnderlierType = strUnderlierType) || _strUnderlierType.isEmpty()
  154.                                             || null == (_strUnderlierSubtype = strUnderlierSubtype) ||
  155.                                                 _strUnderlierSubtype.isEmpty() || null == (_dimExpiry =
  156.                                                     dimExpiry) || null == (_bfe = bfe) || null == (_bfs =
  157.                                                         bfs))
  158.             throw new java.lang.Exception ("TreasuryFuturesConvention ctr: Invalid Inputs");

  159.         _strCalendar = strCalendar;
  160.     }

  161.     /**
  162.      * Retrieve the Treasury Futures Name
  163.      *
  164.      * @return The Treasury Futures Name
  165.      */

  166.     public java.lang.String name()
  167.     {
  168.         return _strName;
  169.     }

  170.     /**
  171.      * Retrieve the Treasury Futures Settle Calendar
  172.      *
  173.      * @return The Treasury Futures Settle Calendar
  174.      */

  175.     public java.lang.String calendar()
  176.     {
  177.         return _strCalendar;
  178.     }

  179.     /**
  180.      * Retrieve the Treasury Futures Code Array
  181.      *
  182.      * @return The Treasury Futures Code Array
  183.      */

  184.     public java.lang.String[] codes()
  185.     {
  186.         return _astrCode;
  187.     }

  188.     /**
  189.      * Retrieve the Treasury Futures Currency
  190.      *
  191.      * @return The Treasury Futures Currency
  192.      */

  193.     public java.lang.String currency()
  194.     {
  195.         return _strCurrency;
  196.     }

  197.     /**
  198.      * Retrieve the Treasury Futures Maturity Tenor
  199.      *
  200.      * @return The Treasury Futures Maturity Tenor
  201.      */

  202.     public java.lang.String maturityTenor()
  203.     {
  204.         return _strMaturityTenor;
  205.     }

  206.     /**
  207.      * Retrieve the Treasury Futures Basket Notional
  208.      *
  209.      * @return The Treasury Futures Basket Notional
  210.      */

  211.     public double basketNotional()
  212.     {
  213.         return _dblBasketNotional;
  214.     }

  215.     /**
  216.      * Retrieve the Minimimum Price Movement - a.k.a Tick
  217.      *
  218.      * @return The Minimum Price Movement
  219.      */

  220.     public double minimumPriceMovement()
  221.     {
  222.         return _dblMinimumPriceMovement;
  223.     }

  224.     /**
  225.      * Retrieve the Minimum Treasury Futures Component Notional
  226.      *
  227.      * @return The Minimum Treasury Futures Component Notional
  228.      */

  229.     public double minimumComponentNotional()
  230.     {
  231.         return _dblComponentNotionalMinimum;
  232.     }

  233.     /**
  234.      * Retrieve the Bond Futures Exchanges Array
  235.      *
  236.      * @return The Bond Futures Exchanges Array
  237.      */

  238.     public java.lang.String[] exchanges()
  239.     {
  240.         return _astrExchange;
  241.     }

  242.     /**
  243.      * Retrieve the Treasury Futures Underlier Type
  244.      *
  245.      * @return The Treasury Futures Underlier Type
  246.      */

  247.     public java.lang.String underlierType()
  248.     {
  249.         return _strUnderlierType;
  250.     }

  251.     /**
  252.      * Retrieve the Treasury Futures Underlier Sub-type
  253.      *
  254.      * @return The Treasury Futures Underlier Sub-type
  255.      */

  256.     public java.lang.String underlierSubtype()
  257.     {
  258.         return _strUnderlierSubtype;
  259.     }

  260.     /**
  261.      * Retrieve the Date In Month Expiry Settings
  262.      *
  263.      * @return The Date In Month Expiry Settings
  264.      */

  265.     public org.drip.analytics.eventday.DateInMonth dimExpiry()
  266.     {
  267.         return _dimExpiry;
  268.     }

  269.     /**
  270.      * Retrieve the Treasury Futures Eligibility Settings
  271.      *
  272.      * @return The Treasury Futures Eligibility Settings
  273.      */

  274.     public org.drip.market.exchange.TreasuryFuturesEligibility eligibility()
  275.     {
  276.         return _bfe;
  277.     }

  278.     /**
  279.      * Retrieve the Treasury Futures Settle Settings
  280.      *
  281.      * @return The Treasury Futures Settle Settings
  282.      */

  283.     public org.drip.market.exchange.TreasuryFuturesSettle settle()
  284.     {
  285.         return _bfs;
  286.     }

  287.     /**
  288.      * Retrieve the TreasuryFuturesEventDates Instance corresponding to the Futures Expiry Year/Month
  289.      *
  290.      * @param iYear Futures Year
  291.      * @param iMonth Futures Month
  292.      *
  293.      * @return The TreasuryFuturesEventDates Instance
  294.      */

  295.     public org.drip.market.exchange.TreasuryFuturesEventDates eventDates (
  296.         final int iYear,
  297.         final int iMonth)
  298.     {
  299.         org.drip.analytics.date.JulianDate dtExpiry = _dimExpiry.instanceDay (iYear, iMonth, _strCalendar);

  300.         if (null == dtExpiry) return null;

  301.         try {
  302.             return new org.drip.market.exchange.TreasuryFuturesEventDates (dtExpiry, dtExpiry.addBusDays
  303.                 (_bfs.expiryFirstDeliveryLag(), _strCalendar), dtExpiry.addBusDays
  304.                     (_bfs.expiryFinalDeliveryLag(), _strCalendar), dtExpiry.addBusDays
  305.                         (_bfs.expiryDeliveryNoticeLag(), _strCalendar), dtExpiry.addBusDays
  306.                             (_bfs.expiryFirstDeliveryLag(), _strCalendar));
  307.         } catch (java.lang.Exception e) {
  308.             e.printStackTrace();
  309.         }

  310.         return null;
  311.     }

  312.     /**
  313.      * Compute the Reference Bond Price from the Quoted Futures Index Level
  314.      *
  315.      * @param dblFuturesQuotedIndex The Quoted Futures Index Level
  316.      *
  317.      * @return The Reference Price
  318.      *
  319.      * @throws java.lang.Exception Thrown if the Inputs are invalid
  320.      */

  321.     public double referencePrice (
  322.         final double dblFuturesQuotedIndex)
  323.         throws java.lang.Exception
  324.     {
  325.         if (!org.drip.numerical.common.NumberUtil.IsValid (dblFuturesQuotedIndex))
  326.             throw new java.lang.Exception ("TreasuryFuturesConvention::referencePrice => Invalid Inputs!");

  327.         double dblPeriodReferenceYield = 0.5 * (1. - dblFuturesQuotedIndex);

  328.         double dblCompoundedDF = java.lang.Math.pow (1. / (1. + dblPeriodReferenceYield),
  329.             org.drip.analytics.support.Helper.TenorToMonths (_strMaturityTenor) / 6);

  330.         return dblCompoundedDF + 0.5 * _bfs.currentReferenceYield() * (1. - dblCompoundedDF) /
  331.             dblPeriodReferenceYield;
  332.     }

  333.     /**
  334.      * Compute the Reference Bond Price from the Quoted Futures Index Level
  335.      *
  336.      * @param dtValue The Valuation Date
  337.      * @param bond The Bond Instance
  338.      * @param dblFuturesQuotedIndex The Quoted Futures Index Level
  339.      *
  340.      * @return The Reference Price
  341.      *
  342.      * @throws java.lang.Exception Thrown if the Treasury Futures Price Generic cannot be computed
  343.      */

  344.     public double referencePrice (
  345.         final org.drip.analytics.date.JulianDate dtValue,
  346.         final org.drip.product.definition.Bond bond,
  347.         final double dblFuturesQuotedIndex)
  348.         throws java.lang.Exception
  349.     {
  350.         if (null == dtValue || null == bond) return referencePrice (dblFuturesQuotedIndex);

  351.         if (!org.drip.numerical.common.NumberUtil.IsValid (dblFuturesQuotedIndex))
  352.             throw new java.lang.Exception ("AnalyticsHelper::referencePrice => Invalid Inputs");

  353.         return bond.priceFromYield (new org.drip.param.valuation.ValuationParams (dtValue, dtValue, null),
  354.             null, null, 1. - dblFuturesQuotedIndex);
  355.     }

  356.     /**
  357.      * Indicate whether the given bond is eligible to be delivered
  358.      *
  359.      * @param dtValue The Value Date
  360.      * @param bond The Bond whose Eligibility is to be evaluated
  361.      * @param dblOutstandingNotional The Outstanding Notional
  362.      * @param strIssuer The Issuer
  363.      *
  364.      * @return TRUE - The given bond is eligible to be delivered
  365.      */

  366.     public boolean isEligible (
  367.         final org.drip.analytics.date.JulianDate dtValue,
  368.         final org.drip.product.definition.Bond bond,
  369.         final double dblOutstandingNotional,
  370.         final java.lang.String strIssuer)
  371.     {
  372.         return _bfe.isEligible (dtValue, bond, dblOutstandingNotional, strIssuer);
  373.     }

  374.     @Override public java.lang.String toString()
  375.     {
  376.         java.lang.String strDump = "Name: " + _strName + " | Currency: " + _strCurrency + " | Calendar: " +
  377.             _strCalendar + " | Underlier Type: " + _strUnderlierType + " | Underlier Sub-type: " +
  378.                 _strUnderlierSubtype + " | Maturity Tenor: " + _strMaturityTenor + " | Basket Notional: " +
  379.                     _dblBasketNotional + " | Minimum Price Movement: " + _dblMinimumPriceMovement +
  380.                         " | Component Notional Minimum: " + _dblComponentNotionalMinimum;

  381.         for (int i = 0; i < _astrCode.length; ++i) {
  382.             if (0 == i)
  383.                 strDump += " | CODES => {";
  384.             else
  385.                 strDump += ", ";

  386.             strDump += _astrCode[i];

  387.             if (_astrExchange.length - 1 == i) strDump += "}";
  388.         }

  389.         for (int i = 0; i < _astrExchange.length; ++i) {
  390.             if (0 == i)
  391.                 strDump += " | EXCHANGES => (";
  392.             else
  393.                 strDump += ", ";

  394.             strDump += _astrExchange[i];

  395.             if (_astrExchange.length - 1 == i) strDump += ") ";
  396.         }

  397.         return strDump + "\n\t\t" + _dimExpiry + "\n\t\t" + _bfe + "\n\t\t" + _bfs;
  398.     }
  399. }