CrossFloatSwapConvention.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>CrossFloatSwapConvention</i> contains the Details of the Cross-Currency Floating Swap of an OTC
  80.  * 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 CrossFloatSwapConvention {
  93.     private int _iSpotLag = -1;
  94.     private int _iFixingType = -1;
  95.     private boolean _bFXMTM = false;
  96.     private org.drip.market.otc.CrossFloatStreamConvention _crossStreamDerived = null;
  97.     private org.drip.market.otc.CrossFloatStreamConvention _crossStreamReference = null;

  98.     private org.drip.product.rates.Stream floatingStream (
  99.         final org.drip.analytics.date.JulianDate dtEffective,
  100.         final org.drip.market.otc.CrossFloatStreamConvention cfsc,
  101.         final org.drip.param.period.FixingSetting fxFixingSetting,
  102.         final java.lang.String strMaturityTenor,
  103.         final double dblBasis,
  104.         final double dblNotional)
  105.     {
  106.         java.lang.String strFloaterTenor = cfsc.tenor();

  107.         org.drip.state.identifier.ForwardLabel forwardLabel = org.drip.state.identifier.ForwardLabel.Create
  108.             (org.drip.market.definition.IBORIndexContainer.IndexFromJurisdiction (cfsc.currency()),
  109.                 strFloaterTenor);

  110.         if (null == forwardLabel) return null;

  111.         try {
  112.             org.drip.param.period.ComposableFloatingUnitSetting cfusReference = new
  113.                 org.drip.param.period.ComposableFloatingUnitSetting (strFloaterTenor,
  114.                     org.drip.analytics.support.CompositePeriodBuilder.EDGE_DATE_SEQUENCE_REGULAR, null,
  115.                         forwardLabel,
  116.                             org.drip.analytics.support.CompositePeriodBuilder.REFERENCE_PERIOD_IN_ADVANCE,
  117.                                 cfsc.applySpread() ? dblBasis : 0.);

  118.             org.drip.param.period.CompositePeriodSetting cpsReference = new
  119.                 org.drip.param.period.CompositePeriodSetting
  120.                     (org.drip.analytics.support.Helper.TenorToFreq (strFloaterTenor),
  121.                         strFloaterTenor, _crossStreamReference.currency(), null, dblNotional, null, null,
  122.                             fxFixingSetting, null);

  123.             java.util.List<java.lang.Integer> lsReferenceEdgeDate =
  124.                 org.drip.analytics.support.CompositePeriodBuilder.RegularEdgeDates (dtEffective,
  125.                     strFloaterTenor, strMaturityTenor, null);

  126.             return new org.drip.product.rates.Stream
  127.                 (org.drip.analytics.support.CompositePeriodBuilder.FloatingCompositeUnit
  128.                     (lsReferenceEdgeDate, cpsReference, cfusReference));
  129.         } catch (java.lang.Exception e) {
  130.             e.printStackTrace();
  131.         }

  132.         return null;
  133.     }

  134.     /**
  135.      * CrossFloatSwapConvention Constructor
  136.      *
  137.      * @param crossStreamReference Reference Cross Float Stream
  138.      * @param crossStreamDerived Derived Cross Float Stream
  139.      * @param iFixingType Fixing Type
  140.      * @param bFXMTM TRUE - The Cross Currency Swap is of the FX MTM type
  141.      * @param iSpotLag Spot Lag
  142.      *
  143.      * @throws java.lang.Exception Thrown if Inputs are Invalid
  144.      */

  145.     public CrossFloatSwapConvention (
  146.         final org.drip.market.otc.CrossFloatStreamConvention crossStreamReference,
  147.         final org.drip.market.otc.CrossFloatStreamConvention crossStreamDerived,
  148.         final int iFixingType,
  149.         final boolean bFXMTM,
  150.         final int iSpotLag)
  151.         throws java.lang.Exception
  152.     {
  153.         if (null == (_crossStreamReference = crossStreamReference) || null == (_crossStreamDerived =
  154.             crossStreamDerived) || !org.drip.param.period.FixingSetting.ValidateType (_iFixingType =
  155.                 iFixingType) || 0 > (_iSpotLag = iSpotLag))
  156.             throw new java.lang.Exception ("CrossFloatSwapConvention ctr: Invalid Inputs");

  157.         _bFXMTM = bFXMTM;
  158.     }

  159.     /**
  160.      * Retrieve the Reference Convention
  161.      *
  162.      * @return The Reference Convention
  163.      */

  164.     public org.drip.market.otc.CrossFloatStreamConvention referenceConvention()
  165.     {
  166.         return _crossStreamReference;
  167.     }

  168.     /**
  169.      * Retrieve the Derived Convention
  170.      *
  171.      * @return The Derived Convention
  172.      */

  173.     public org.drip.market.otc.CrossFloatStreamConvention derivedConvention()
  174.     {
  175.         return _crossStreamDerived;
  176.     }

  177.     /**
  178.      * Retrieve the Fixing Setting Type
  179.      *
  180.      * @return The Fixing Setting Type
  181.      */

  182.     public int fixingType()
  183.     {
  184.         return _iFixingType;
  185.     }

  186.     /**
  187.      * Retrieve the Spot Lag
  188.      *
  189.      * @return The Spot Lag
  190.      */

  191.     public int spotLag()
  192.     {
  193.         return _iSpotLag;
  194.     }

  195.     /**
  196.      * Retrieve the FX MTM Flag
  197.      *
  198.      * @return The FX MTM Flag
  199.      */

  200.     public boolean isFXMTM()
  201.     {
  202.         return _bFXMTM;
  203.     }

  204.     /**
  205.      * Create an Instance of the Float-Float Component
  206.      *
  207.      * @param dtSpot Spot Date
  208.      * @param strMaturityTenor The Maturity Tenor
  209.      * @param dblBasis Basis
  210.      * @param dblReferenceNotional Notional of the Reference Stream
  211.      * @param dblDerivedNotional Notional of the Derived Stream
  212.      *
  213.      * @return Instance of the Float-Float Component
  214.      */

  215.     public org.drip.product.rates.FloatFloatComponent createFloatFloatComponent (
  216.         final org.drip.analytics.date.JulianDate dtSpot,
  217.         final java.lang.String strMaturityTenor,
  218.         final double dblBasis,
  219.         final double dblReferenceNotional,
  220.         final double dblDerivedNotional)
  221.     {
  222.         if (null == dtSpot) return null;

  223.         org.drip.analytics.date.JulianDate dtEffective = dtSpot.addBusDays (_iSpotLag,
  224.             org.drip.market.definition.IBORIndexContainer.IndexFromJurisdiction
  225.                 (_crossStreamReference.currency()).calendar() + "," +
  226.                     org.drip.market.definition.IBORIndexContainer.IndexFromJurisdiction
  227.                         (_crossStreamDerived.currency()).calendar());

  228.         try {
  229.             org.drip.param.period.FixingSetting fxFixingSetting = _bFXMTM ? null : new
  230.                 org.drip.param.period.FixingSetting (_iFixingType, null, dtEffective.julian());

  231.             return new org.drip.product.rates.FloatFloatComponent (floatingStream (dtEffective,
  232.                 _crossStreamReference, fxFixingSetting, strMaturityTenor, dblBasis, dblReferenceNotional),
  233.                     floatingStream (dtEffective, _crossStreamDerived, fxFixingSetting, strMaturityTenor,
  234.                         dblBasis, dblDerivedNotional), null);
  235.         } catch (java.lang.Exception e) {
  236.             e.printStackTrace();
  237.         }

  238.         return null;
  239.     }

  240.     @Override public java.lang.String toString()
  241.     {
  242.         return _crossStreamReference + " " + _crossStreamDerived + " " + _iFixingType + " " + _iSpotLag + " "
  243.             + _bFXMTM;
  244.     }
  245. }