BrokenDateLIBORUSD.java

  1. package org.drip.sample.intexfeed;

  2. import org.drip.analytics.date.*;
  3. import org.drip.analytics.daycount.Convention;
  4. import org.drip.analytics.support.Helper;
  5. import org.drip.market.otc.*;
  6. import org.drip.numerical.common.FormatUtil;
  7. import org.drip.service.env.EnvManager;
  8. import org.drip.service.template.LatentMarketStateBuilder;
  9. import org.drip.state.discount.MergedDiscountForwardCurve;
  10. import org.drip.state.identifier.ForwardLabel;

  11. /*
  12.  * -*- mode: java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  13.  */

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

  75. /**
  76.  * <i>BrokenDateLIBORUSD</i> generates the USD LIBOR Forward's over Monthly Increments with Maturity up to 60
  77.  * Years for different Forward Tenors.
  78.  *  
  79.  * <br><br>
  80.  *  <ul>
  81.  *      <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/AnalyticsCore.md">Analytics Core Module</a></li>
  82.  *      <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/FixedIncomeAnalyticsLibrary.md">Fixed Income Analytics Library</a></li>
  83.  *      <li><b>Project</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/sample/README.md">Sample</a></li>
  84.  *      <li><b>Package</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/sample/intexfeed/README.md">Intex Feed Inputs</a></li>
  85.  *  </ul>
  86.  * <br><br>
  87.  *
  88.  * @author Lakshmi Krishnamurthy
  89.  */

  90. public class BrokenDateLIBORUSD {

  91.     private static final MergedDiscountForwardCurve FundingCurve (
  92.         final JulianDate dtSpot,
  93.         final String strCurrency)
  94.         throws Exception
  95.     {
  96.         String[] astrDepositMaturityTenor = new String[] {
  97.             "2D"
  98.         };

  99.         double[] adblDepositQuote = new double[] {
  100.             0.0130411 // 2D
  101.         };

  102.         double[] adblFuturesQuote = new double[] {
  103.             0.01345,    // 98.655
  104.             0.01470,    // 98.530
  105.             0.01575,    // 98.425
  106.             0.01660,    // 98.340
  107.             0.01745,    // 98.255
  108.             0.01845     // 98.155
  109.         };

  110.         String[] astrFixFloatMaturityTenor = new String[] {
  111.             "02Y",
  112.             "03Y",
  113.             "04Y",
  114.             "05Y",
  115.             "06Y",
  116.             "07Y",
  117.             "08Y",
  118.             "09Y",
  119.             "10Y",
  120.             "11Y",
  121.             "12Y",
  122.             "15Y",
  123.             "20Y",
  124.             "25Y",
  125.             "30Y",
  126.             "40Y",
  127.             "50Y"
  128.         };

  129.         double[] adblFixFloatQuote = new double[] {
  130.             0.016410, //  2Y
  131.             0.017863, //  3Y
  132.             0.019030, //  4Y
  133.             0.020035, //  5Y
  134.             0.020902, //  6Y
  135.             0.021660, //  7Y
  136.             0.022307, //  8Y
  137.             0.022879, //  9Y
  138.             0.023363, // 10Y
  139.             0.023820, // 11Y
  140.             0.024172, // 12Y
  141.             0.024934, // 15Y
  142.             0.025581, // 20Y
  143.             0.025906, // 25Y
  144.             0.025973, // 30Y
  145.             0.025838, // 40Y
  146.             0.025560  // 50Y
  147.         };

  148.         return LatentMarketStateBuilder.SmoothFundingCurve (
  149.             dtSpot,
  150.             strCurrency,
  151.             astrDepositMaturityTenor,
  152.             adblDepositQuote,
  153.             "ForwardRate",
  154.             adblFuturesQuote,
  155.             "ForwardRate",
  156.             astrFixFloatMaturityTenor,
  157.             adblFixFloatQuote,
  158.             "SwapRate"
  159.         );
  160.     }

  161.     public static final void main (
  162.         final String[] astrArgs)
  163.         throws Exception
  164.     {
  165.         EnvManager.InitEnv ("");

  166.         JulianDate dtSpot = DateUtil.CreateFromYMD (
  167.             2017,
  168.             DateUtil.OCTOBER,
  169.             5
  170.         );

  171.         int iNumMonth = 720;
  172.         String strCurrency = "USD";
  173.         String[] astrForwardTenor = new String[] {
  174.              "1M",
  175.              "2M",
  176.              "3M",
  177.              "6M",
  178.             "12M"
  179.         };

  180.         FixedFloatSwapConvention ffsc = IBORFixedFloatContainer.ConventionFromJurisdiction (strCurrency);

  181.         ForwardLabel forwardLabel = ffsc.floatStreamConvention().floaterIndex();

  182.         String strLIBORDayCount = forwardLabel.floaterIndex().dayCount();

  183.         int iLIBORFreq = Helper.TenorToFreq (forwardLabel.tenor());

  184.         MergedDiscountForwardCurve mdfc = FundingCurve (
  185.             dtSpot,
  186.             strCurrency
  187.         );

  188.         System.out.println
  189.             ("SpotDate,ViewDate,ForwardTenor,ViewDiscountFactor,ViewForwardDiscountFactor, ForwardRate");

  190.         for (int i = 0; i < iNumMonth; ++i) {
  191.             JulianDate dtView = 0 == i ? dtSpot : dtSpot.addMonths (i);

  192.             double dblDFView = mdfc.df (dtView);

  193.             for (int j = 0; j < astrForwardTenor.length; ++j) {
  194.                 JulianDate dtForward = dtView.addTenor (astrForwardTenor[j]);

  195.                 double dblDFForward = mdfc.df (dtForward);

  196.                 double dblForwardRate = Helper.DF2Yield (
  197.                     iLIBORFreq,
  198.                     dblDFForward / dblDFView,
  199.                     Convention.YearFraction (
  200.                         dtView.julian(),
  201.                         dtForward.julian(),
  202.                         strLIBORDayCount,
  203.                         false,
  204.                         null,
  205.                         strCurrency
  206.                     )
  207.                 );

  208.                 System.out.println (
  209.                     dtSpot + "," +
  210.                     dtView + "," +
  211.                     astrForwardTenor[j] + "," +
  212.                     FormatUtil.FormatDouble (dblDFView, 1, 8, 1.) + "," +
  213.                     FormatUtil.FormatDouble (dblDFForward, 1, 8, 1.) + "," +
  214.                     FormatUtil.FormatDouble (dblForwardRate, 1, 8, 100.) + "%"
  215.                 );
  216.             }
  217.         }

  218.         EnvManager.TerminateEnv();
  219.     }
  220. }