FloatStreamConvention.java

  1. package org.drip.market.otc;

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

  78. /**
  79.  * <i>FloatStreamConvention</i> contains the details of the Floating Stream of an OTC IBOR/Overnight Fix-
  80.  * Float Swap Contract.
  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 Library</a></li>
  86.  *      <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>
  87.  *      <li><b>Package</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/market/otc">OTC Dual Stream Option Container</a></li>
  88.  *  </ul>
  89.  *
  90.  * @author Lakshmi Krishnamurthy
  91.  */

  92. public class FloatStreamConvention {
  93.     private java.lang.String _strCompositePeriodTenor = "";
  94.     private org.drip.state.identifier.ForwardLabel _forwardLabel = null;

  95.     /**
  96.      * FloatStreamConvention Constructor
  97.      *
  98.      * @param forwardLabel The Forward Label
  99.      * @param strCompositePeriodTenor Composite Period Tenor
  100.      *
  101.      * @throws java.lang.Exception Thrown if Inputs are invalid
  102.      */

  103.     public FloatStreamConvention (
  104.         final org.drip.state.identifier.ForwardLabel forwardLabel,
  105.         final java.lang.String strCompositePeriodTenor)
  106.         throws java.lang.Exception
  107.     {
  108.         if (null == (_forwardLabel = forwardLabel) || null == (_strCompositePeriodTenor =
  109.             strCompositePeriodTenor) || _strCompositePeriodTenor.isEmpty())
  110.             throw new java.lang.Exception ("FloatStreamConvention ctr: Invalid Inputs");
  111.     }

  112.     /**
  113.      * Retrieve the Forward Label
  114.      *
  115.      * @return The Forward Label
  116.      */

  117.     public org.drip.state.identifier.ForwardLabel floaterIndex()
  118.     {
  119.         return _forwardLabel;
  120.     }

  121.     /**
  122.      * Retrieve the Composite Period Tenor
  123.      *
  124.      * @return The Composite Period Tenor
  125.      */

  126.     public java.lang.String compositePeriodTenor()
  127.     {
  128.         return _strCompositePeriodTenor;
  129.     }

  130.     /**
  131.      * Create a Floating Stream Instance
  132.      *
  133.      * @param dtEffective Effective Date
  134.      * @param strMaturityTenor Maturity Tenor
  135.      * @param dblBasis Basis
  136.      * @param dblNotional Notional
  137.      *
  138.      * @return The Fixed Stream Instance
  139.      */

  140.     public org.drip.product.rates.Stream createStream (
  141.         final org.drip.analytics.date.JulianDate dtEffective,
  142.         final java.lang.String strMaturityTenor,
  143.         final double dblBasis,
  144.         final double dblNotional)
  145.     {
  146.         boolean bOvernight = _forwardLabel.overnight();

  147.         try {
  148.             org.drip.param.period.ComposableFloatingUnitSetting cfus = new
  149.                 org.drip.param.period.ComposableFloatingUnitSetting (bOvernight ? "ON" :
  150.                     _forwardLabel.tenor(), bOvernight ?
  151.                         org.drip.analytics.support.CompositePeriodBuilder.EDGE_DATE_SEQUENCE_OVERNIGHT :
  152.                             org.drip.analytics.support.CompositePeriodBuilder.EDGE_DATE_SEQUENCE_REGULAR,
  153.                                 null, _forwardLabel,
  154.                                     org.drip.analytics.support.CompositePeriodBuilder.REFERENCE_PERIOD_IN_ADVANCE,
  155.                 dblBasis);

  156.             org.drip.param.period.CompositePeriodSetting cps = new
  157.                 org.drip.param.period.CompositePeriodSetting (bOvernight ? 360 :
  158.                     org.drip.analytics.support.Helper.TenorToFreq (_strCompositePeriodTenor),
  159.                         _strCompositePeriodTenor, _forwardLabel.currency(), null, dblNotional, null, null,
  160.                             null, null);

  161.             java.util.List<java.lang.Integer> lsEdgeDate = bOvernight ?
  162.                 org.drip.analytics.support.CompositePeriodBuilder.OvernightEdgeDates (dtEffective,
  163.                     dtEffective.addTenor (strMaturityTenor), null):
  164.                         org.drip.analytics.support.CompositePeriodBuilder.RegularEdgeDates (dtEffective,
  165.                             _strCompositePeriodTenor, strMaturityTenor, null);

  166.             return new org.drip.product.rates.Stream
  167.                 (org.drip.analytics.support.CompositePeriodBuilder.FloatingCompositeUnit (lsEdgeDate, cps,
  168.                     cfus));
  169.         } catch (java.lang.Exception e) {
  170.             e.printStackTrace();
  171.         }

  172.         return null;
  173.     }

  174.     @Override public java.lang.String toString()
  175.     {
  176.         return "[FLOAT: " + _forwardLabel.fullyQualifiedName() + " | " + _strCompositePeriodTenor + "]";
  177.     }
  178. }