BrokenDateLIBORSpot.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>BrokenDateLIBORSpot</i> generates the LIBOR's at the Broken Date Tenors in the Currency specified.
  77.  *  
  78.  * <br><br>
  79.  *  <ul>
  80.  *      <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/AnalyticsCore.md">Analytics Core Module</a></li>
  81.  *      <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/FixedIncomeAnalyticsLibrary.md">Fixed Income Analytics Library</a></li>
  82.  *      <li><b>Project</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/sample/README.md">Sample</a></li>
  83.  *      <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>
  84.  *  </ul>
  85.  * <br><br>
  86.  *
  87.  * @author Lakshmi Krishnamurthy
  88.  */

  89. public class BrokenDateLIBORSpot {

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

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

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

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

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

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

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

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

  170.         int iNumMonth = 720;
  171.         String strCurrency = "USD";

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

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

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

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

  176.         MergedDiscountForwardCurve mdfc = FundingCurve (
  177.             dtSpot,
  178.             strCurrency
  179.         );

  180.         System.out.println ("SpotDate,ForwardTenor,ForwardDate,ZeroPrice,LIBOR,ZeroRate");

  181.         for (int i = 1; i <= iNumMonth; ++i) {
  182.             String strTenor = i + "M";

  183.             JulianDate dtForward = dtSpot.addMonths (i);

  184.             double dblDFForward = mdfc.df (strTenor);

  185.             double dblLIBOR = Helper.DF2Yield (
  186.                 iLIBORFreq,
  187.                 dblDFForward,
  188.                 Convention.YearFraction (
  189.                     dtSpot.julian(),
  190.                     dtForward.julian(),
  191.                     strLIBORDayCount,
  192.                     false,
  193.                     null,
  194.                     strCurrency
  195.                 )
  196.             );

  197.             double dblZero = Helper.DF2Yield (
  198.                 4,
  199.                 dblDFForward,
  200.                 Convention.YearFraction (
  201.                     dtSpot.julian(),
  202.                     dtForward.julian(),
  203.                     "30/360",
  204.                     false,
  205.                     null,
  206.                     strCurrency
  207.                 )
  208.             );

  209.             System.out.println (
  210.                 dtSpot + "," +
  211.                 strTenor + "," +
  212.                 dtForward + "," +
  213.                 FormatUtil.FormatDouble (dblDFForward, 1, 6, 1.) + "," +
  214.                 FormatUtil.FormatDouble (dblLIBOR, 1, 6, 100.) + "%," +
  215.                 FormatUtil.FormatDouble (dblZero, 1, 6, 100.) + "%"
  216.             );
  217.         }

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