FloatFloatSwapConvention.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>FloatFloatSwapConvention</i> contains the Details of the IBOR Float-Float Component of an OTC contact.
  80.  *
  81.  *  <br><br>
  82.  *  <ul>
  83.  *      <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/ProductCore.md">Product Core Module</a></li>
  84.  *      <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/FixedIncomeAnalyticsLibrary.md">Fixed Income Analytics Library</a></li>
  85.  *      <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>
  86.  *      <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>
  87.  *  </ul>
  88.  *
  89.  * @author Lakshmi Krishnamurthy
  90.  */

  91. public class FloatFloatSwapConvention {
  92.     private int _iSpotLag = -1;
  93.     private boolean _bIsComponentPair = false;
  94.     private java.lang.String _strCurrency = "";
  95.     private boolean _bBasisOnDerivedStream = true;
  96.     private boolean _bBasisOnDerivedComponent = true;
  97.     private java.lang.String _strReferenceTenor = "";
  98.     private boolean _bIsDerivedCompoundedToReference = true;

  99.     private org.drip.product.rates.FixFloatComponent fixFloatComponent (
  100.         final org.drip.analytics.date.JulianDate dtEffective,
  101.         final java.lang.String strFloaterTenor,
  102.         final java.lang.String strMaturityTenor,
  103.         final double dblFixedCoupon,
  104.         final double dblBasis,
  105.         final double dblNotional)
  106.     {
  107.         org.drip.market.otc.FixedFloatSwapConvention ffConv =
  108.             org.drip.market.otc.IBORFixedFloatContainer.ConventionFromJurisdiction (_strCurrency);

  109.         if (null == ffConv) return null;

  110.         org.drip.market.otc.FixedStreamConvention fixedConv = ffConv.fixedStreamConvention();

  111.         org.drip.product.rates.Stream streamFixed = fixedConv.createStream (dtEffective, strMaturityTenor,
  112.             dblFixedCoupon + (_bBasisOnDerivedStream ? 0. : dblBasis), dblNotional);

  113.         org.drip.state.identifier.ForwardLabel forwardLabel = org.drip.state.identifier.ForwardLabel.Create
  114.             (org.drip.market.definition.IBORIndexContainer.IndexFromJurisdiction (_strCurrency),
  115.                 strFloaterTenor);

  116.         java.lang.String strFloaterTenorComposite = _bIsDerivedCompoundedToReference ?
  117.             fixedConv.compositePeriodTenor() : strFloaterTenor;

  118.         try {
  119.             org.drip.param.period.ComposableFloatingUnitSetting cfus = new
  120.                 org.drip.param.period.ComposableFloatingUnitSetting (strFloaterTenor,
  121.                     org.drip.analytics.support.CompositePeriodBuilder.EDGE_DATE_SEQUENCE_REGULAR, null,
  122.                         forwardLabel,
  123.                             org.drip.analytics.support.CompositePeriodBuilder.REFERENCE_PERIOD_IN_ADVANCE,
  124.                                 _bBasisOnDerivedStream ? dblBasis : 0.);

  125.             org.drip.param.period.CompositePeriodSetting cps = new
  126.                 org.drip.param.period.CompositePeriodSetting
  127.                     (org.drip.analytics.support.Helper.TenorToFreq (strFloaterTenorComposite),
  128.                         strFloaterTenorComposite, _strCurrency, null, -1. * dblNotional, null, null, null,
  129.                             null);

  130.             java.util.List<java.lang.Integer> lsEdgeDate =
  131.                 org.drip.analytics.support.CompositePeriodBuilder.RegularEdgeDates (dtEffective,
  132.                     strFloaterTenorComposite, strMaturityTenor, null);

  133.             org.drip.product.rates.Stream streamFloater = new org.drip.product.rates.Stream
  134.                 (org.drip.analytics.support.CompositePeriodBuilder.FloatingCompositeUnit (lsEdgeDate, cps,
  135.                     cfus));

  136.             org.drip.product.rates.FixFloatComponent ffc = new org.drip.product.rates.FixFloatComponent
  137.                 (streamFixed, streamFloater, null);

  138.             ffc.setPrimaryCode ("IRS::" + ffc.forwardLabel().get ("DERIVED").fullyQualifiedName() + "." +
  139.                 strMaturityTenor);

  140.             return ffc;
  141.         } catch (java.lang.Exception e) {
  142.             e.printStackTrace();
  143.         }

  144.         return null;
  145.     }

  146.     /**
  147.      * FloatFloatSwapConvention Constructor
  148.      *
  149.      * @param strCurrency The Currency
  150.      * @param strReferenceTenor The Reference Tenor
  151.      * @param bBasisOnDerivedStream TRUE - Apply the Basis to the Derived Stream
  152.      * @param bBasisOnDerivedComponent TRUE - Apply the Basis to the Derived Component
  153.      * @param bIsDerivedCompoundedToReference TRUE - The Derived Periods are Compounded onto the Reference
  154.      * @param bIsComponentPair TRUE - The Float-Float Swap is a Component Pair of 2 Fix-Float Swaps
  155.      * @param iSpotLag Spot Lag
  156.      *
  157.      * @throws java.lang.Exception Thrown if the Inputs are Invalid
  158.      */

  159.     public FloatFloatSwapConvention (
  160.         final java.lang.String strCurrency,
  161.         final java.lang.String strReferenceTenor,
  162.         final boolean bBasisOnDerivedStream,
  163.         final boolean bBasisOnDerivedComponent,
  164.         final boolean bIsDerivedCompoundedToReference,
  165.         final boolean bIsComponentPair,
  166.         final int iSpotLag)
  167.         throws java.lang.Exception
  168.     {
  169.         if (null == (_strCurrency = strCurrency) || _strCurrency.isEmpty() || null == (_strReferenceTenor =
  170.             strReferenceTenor) || _strReferenceTenor.isEmpty() || 0 > (_iSpotLag = iSpotLag))
  171.             throw new java.lang.Exception ("FloatFloatSwapConvention ctr: Invalid Inputs");

  172.         _bIsComponentPair = bIsComponentPair;
  173.         _bBasisOnDerivedStream = bBasisOnDerivedStream;
  174.         _bBasisOnDerivedComponent = bBasisOnDerivedComponent;
  175.         _bIsDerivedCompoundedToReference = bIsDerivedCompoundedToReference;
  176.     }

  177.     /**
  178.      * Retrieve the Currency
  179.      *
  180.      * @return The Currency
  181.      */

  182.     public java.lang.String currency()
  183.     {
  184.         return _strCurrency;
  185.     }

  186.     /**
  187.      * Retrieve the Reference Tenor
  188.      *
  189.      * @return The Reference Tenor
  190.      */

  191.     public java.lang.String referenceTenor()
  192.     {
  193.         return _strReferenceTenor;
  194.     }

  195.     /**
  196.      * Retrieve the Flag indicating whether the Basis is to be applied to the Derived or the Reference Stream
  197.      *
  198.      * @return TRUE - The Basis is applied to the Derived Stream
  199.      */

  200.     public boolean basisOnDerivedStream()
  201.     {
  202.         return _bBasisOnDerivedStream;
  203.     }

  204.     /**
  205.      * Retrieve the Flag indicating whether the Basis is to be applied to the Derived or the Reference
  206.      *  Component
  207.      *
  208.      * @return TRUE - The Basis is applied to the Derived Component
  209.      */

  210.     public boolean basisOnDerivedComponent()
  211.     {
  212.         return _bBasisOnDerivedComponent;
  213.     }

  214.     /**
  215.      * Retrieve the Flag indicating whether the Derived Periods are to be compounded onto the Reference
  216.      *  Period
  217.      *
  218.      * @return TRUE - The Derived Periods are Compounded onto the Reference
  219.      */

  220.     public boolean derivedCompoundedToReference()
  221.     {
  222.         return _bIsDerivedCompoundedToReference;
  223.     }

  224.     /**
  225.      * Retrieve the Flag indicating whether the Float-Float Swap is a Component Pair of 2 Fix-Float Swaps
  226.      *
  227.      * @return TRUE - The Float-Float Swap is a Component Pair of 2 Fix-Float Swaps
  228.      */

  229.     public boolean componentPair()
  230.     {
  231.         return _bIsComponentPair;
  232.     }

  233.     /**
  234.      * Retrieve the Spot Lag
  235.      *
  236.      * @return The Spot Lag
  237.      */

  238.     public int spotLag()
  239.     {
  240.         return _iSpotLag;
  241.     }

  242.     /**
  243.      * Create an Instance of the Float-Float Component
  244.      *
  245.      * @param dtSpot Spot Date
  246.      * @param strDerivedTenor The Derived Tenor
  247.      * @param strMaturityTenor The Maturity Tenor
  248.      * @param dblBasis Basis
  249.      * @param dblNotional Notional
  250.      *
  251.      * @return Instance of the Float-Float Component
  252.      */

  253.     public org.drip.product.rates.FloatFloatComponent createFloatFloatComponent (
  254.         final org.drip.analytics.date.JulianDate dtSpot,
  255.         final java.lang.String strDerivedTenor,
  256.         final java.lang.String strMaturityTenor,
  257.         final double dblBasis,
  258.         final double dblNotional)
  259.     {
  260.         if (_bIsComponentPair || null == dtSpot) return null;

  261.         org.drip.state.identifier.ForwardLabel forwardLabelReference =
  262.             org.drip.state.identifier.ForwardLabel.Create
  263.                 (org.drip.market.definition.IBORIndexContainer.IndexFromJurisdiction (_strCurrency),
  264.                     _strReferenceTenor);

  265.         if (null == forwardLabelReference) return null;

  266.         org.drip.analytics.date.JulianDate dtEffective = dtSpot.addBusDays (_iSpotLag,
  267.             forwardLabelReference.floaterIndex().calendar());

  268.         org.drip.state.identifier.ForwardLabel forwardLabelDerived =
  269.             org.drip.state.identifier.ForwardLabel.Create
  270.                 (org.drip.market.definition.IBORIndexContainer.IndexFromJurisdiction (_strCurrency),
  271.                     strDerivedTenor);

  272.         if (null == forwardLabelDerived) return null;

  273.         java.lang.String strDerivedTenorComposite = _bIsDerivedCompoundedToReference ? _strReferenceTenor :
  274.             strDerivedTenor;

  275.         try {
  276.             org.drip.param.period.ComposableFloatingUnitSetting cfusReference = new
  277.                 org.drip.param.period.ComposableFloatingUnitSetting (_strReferenceTenor,
  278.                     org.drip.analytics.support.CompositePeriodBuilder.EDGE_DATE_SEQUENCE_REGULAR, null,
  279.                         forwardLabelReference,
  280.                             org.drip.analytics.support.CompositePeriodBuilder.REFERENCE_PERIOD_IN_ADVANCE,
  281.                                 !_bBasisOnDerivedStream ? dblBasis : 0.);

  282.             org.drip.param.period.CompositePeriodSetting cpsReference = new
  283.                 org.drip.param.period.CompositePeriodSetting
  284.                     (org.drip.analytics.support.Helper.TenorToFreq (_strReferenceTenor),
  285.                         _strReferenceTenor, _strCurrency, null, dblNotional, null, null, null, null);

  286.             java.util.List<java.lang.Integer> lsReferenceEdgeDate =
  287.                 org.drip.analytics.support.CompositePeriodBuilder.RegularEdgeDates (dtEffective,
  288.                     _strReferenceTenor, strMaturityTenor, null);

  289.             org.drip.product.rates.Stream streamReference = new org.drip.product.rates.Stream
  290.                 (org.drip.analytics.support.CompositePeriodBuilder.FloatingCompositeUnit
  291.                     (lsReferenceEdgeDate, cpsReference, cfusReference));

  292.             org.drip.param.period.ComposableFloatingUnitSetting cfusDerived = new
  293.                 org.drip.param.period.ComposableFloatingUnitSetting (strDerivedTenor,
  294.                     org.drip.analytics.support.CompositePeriodBuilder.EDGE_DATE_SEQUENCE_REGULAR, null,
  295.                         forwardLabelDerived,
  296.                             org.drip.analytics.support.CompositePeriodBuilder.REFERENCE_PERIOD_IN_ADVANCE,
  297.                                 _bBasisOnDerivedStream ? dblBasis : 0.);

  298.             org.drip.param.period.CompositePeriodSetting cpsDerived = new
  299.                 org.drip.param.period.CompositePeriodSetting
  300.                     (org.drip.analytics.support.Helper.TenorToFreq (strDerivedTenorComposite),
  301.                         strDerivedTenorComposite, _strCurrency, null, -1. * dblNotional, null, null, null,
  302.                             null);

  303.             java.util.List<java.lang.Integer> lsDerivedEdgeDate =
  304.                 org.drip.analytics.support.CompositePeriodBuilder.RegularEdgeDates (dtEffective,
  305.                     strDerivedTenor, strMaturityTenor, null);

  306.             org.drip.product.rates.Stream streamDerived = new org.drip.product.rates.Stream
  307.                 (org.drip.analytics.support.CompositePeriodBuilder.FloatingCompositeUnit (lsDerivedEdgeDate,
  308.                     cpsDerived, cfusDerived));

  309.             return new org.drip.product.rates.FloatFloatComponent (streamReference, streamDerived, null);
  310.         } catch (java.lang.Exception e) {
  311.             e.printStackTrace();
  312.         }

  313.         return null;
  314.     }

  315.     /**
  316.      * Create an Instance of the Fix-Float Component Pair
  317.      *
  318.      * @param dtSpot Spot Date
  319.      * @param strDerivedTenor The Derived Tenor
  320.      * @param strMaturityTenor The Maturity Tenor
  321.      * @param dblReferenceFixedCoupon Fixed Coupon Rate for the Reference Component
  322.      * @param dblDerivedFixedCoupon Fixed Coupon Rate for the Derived Component
  323.      * @param dblBasis Basis
  324.      * @param dblNotional Notional
  325.      *
  326.      * @return Instance of the Fix-Float Component Pair
  327.      */

  328.     public org.drip.product.fx.ComponentPair createFixFloatComponentPair (
  329.         final org.drip.analytics.date.JulianDate dtSpot,
  330.         final java.lang.String strDerivedTenor,
  331.         final java.lang.String strMaturityTenor,
  332.         final double dblReferenceFixedCoupon,
  333.         final double dblDerivedFixedCoupon,
  334.         final double dblBasis,
  335.         final double dblNotional)
  336.     {
  337.         if (!_bIsComponentPair || null == dtSpot) return null;

  338.         org.drip.market.definition.IBORIndex floaterIndex =
  339.             org.drip.market.definition.IBORIndexContainer.IndexFromJurisdiction (_strCurrency);

  340.         if (null == floaterIndex) return null;

  341.         org.drip.analytics.date.JulianDate dtEffective = dtSpot.addBusDays (_iSpotLag,
  342.             floaterIndex.calendar());

  343.         org.drip.product.rates.FixFloatComponent ffcReference = fixFloatComponent (dtEffective,
  344.             _strReferenceTenor, strMaturityTenor, dblReferenceFixedCoupon, !_bBasisOnDerivedComponent ?
  345.                 dblBasis : 0., dblNotional);

  346.         org.drip.product.rates.FixFloatComponent ffcDerived = fixFloatComponent (dtEffective,
  347.             strDerivedTenor, strMaturityTenor, dblDerivedFixedCoupon, _bBasisOnDerivedComponent ? dblBasis :
  348.                 0., -1. * dblNotional);

  349.         try {
  350.             return new org.drip.product.fx.ComponentPair (_strCurrency + "::" + _strReferenceTenor + "/" +
  351.                 strDerivedTenor + "_" + strMaturityTenor, ffcReference, ffcDerived, null);
  352.         } catch (java.lang.Exception e) {
  353.             e.printStackTrace();
  354.         }

  355.         return null;
  356.     }
  357. }