BrokenDateLIBOREUR.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.product.definition.CalibratableComponent;
  8. import org.drip.product.rates.*;
  9. import org.drip.service.env.EnvManager;
  10. // import org.drip.service.template.LatentMarketStateBuilder;
  11. import org.drip.service.template.OTCInstrumentBuilder;
  12. import org.drip.state.creator.ScenarioDiscountCurveBuilder;
  13. import org.drip.state.discount.MergedDiscountForwardCurve;
  14. import org.drip.state.identifier.ForwardLabel;

  15. /*
  16.  * -*- mode: java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  17.  */

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

  79. /**
  80.  * <i>BrokenDateLIBOREUR</i> generates the EUR LIBOR Forward's over Monthly Increments with Maturity up to 60
  81.  * Years for different Forward Tenors.
  82.  *  
  83.  * <br><br>
  84.  *  <ul>
  85.  *      <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/AnalyticsCore.md">Analytics Core Module</a></li>
  86.  *      <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/FixedIncomeAnalyticsLibrary.md">Fixed Income Analytics Library</a></li>
  87.  *      <li><b>Project</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/sample/README.md">Sample</a></li>
  88.  *      <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>
  89.  *  </ul>
  90.  * <br><br>
  91.  *
  92.  * @author Lakshmi Krishnamurthy
  93.  */

  94. public class BrokenDateLIBOREUR {

  95.     private static final MergedDiscountForwardCurve FundingCurve (
  96.         final JulianDate dtSpot,
  97.         final String strCurrency)
  98.         throws Exception
  99.     {
  100.         String[] depositTenorArray = new String[] {
  101.             "1W",
  102.             "2W",
  103.             "1M",
  104.             "2M",
  105.             "3M",
  106.             "6M",
  107.             "9M"
  108.         };

  109.         double[] depositQuoteArray = new double[] {
  110.             -0.00379, // 1W
  111.             -0.00372, // 2W
  112.             -0.00370, // 1M
  113.             -0.00341, // 2M
  114.             -0.00329, // 3M
  115.             -0.00271, // 6M
  116.             -0.00221  // 9M
  117.         };

  118.         String[] fixFloatMaturityTenorArray = new String[] {
  119.             "18M",
  120.             "02Y",
  121.             "03Y",
  122.             "04Y",
  123.             "05Y",
  124.             "06Y",
  125.             "07Y",
  126.             "08Y",
  127.             "09Y",
  128.             "10Y",
  129.             "11Y",
  130.             "12Y",
  131.             "15Y",
  132.             "20Y",
  133.             "25Y",
  134.             "30Y",
  135.             "35Y",
  136.             "40Y",
  137.             "45Y",
  138.             "50Y"
  139.         };

  140.         double[] fixFloatQuoteArray = new double[] {
  141.             -0.002040, // 18M
  142.             -0.001190, // 02Y
  143.              0.000855, // 03Y
  144.              0.002960, // 04Y
  145.              0.004990, // 05Y
  146.              0.006630, // 06Y
  147.              0.008090, // 07Y
  148.              0.009360, // 08Y
  149.              0.010490, // 09Y
  150.              0.011300, // 10Y
  151.              0.012360, // 11Y
  152.              0.013150, // 12Y
  153.              0.014890, // 15Y
  154.              0.016300, // 20Y
  155.              0.016690, // 25Y
  156.              0.016740, // 30Y
  157.              0.016680, // 35Y
  158.              0.016530, // 40Y
  159.              0.015944, // 45Y
  160.              0.016090, // 50Y
  161.         };

  162.         int depositCount = depositTenorArray.length;
  163.         int calibComponentCount = depositCount + fixFloatMaturityTenorArray.length;
  164.         CalibratableComponent[] calibComponentArray = new CalibratableComponent[calibComponentCount];
  165.         String[] calibMeasureArray = new String[calibComponentCount];
  166.         double[] calibQuoteArray = new double[calibComponentCount];

  167.         SingleStreamComponent[] depositArray = OTCInstrumentBuilder.FundingDeposit (
  168.             dtSpot,
  169.             strCurrency,
  170.             depositTenorArray
  171.         );

  172.         FixFloatComponent[] fixFloatArray = OTCInstrumentBuilder.FixFloatStandard (
  173.             dtSpot,
  174.             strCurrency,
  175.             "ALL",
  176.             fixFloatMaturityTenorArray,
  177.             "MAIN",
  178.             0.
  179.         );

  180.         for (int i = 0; i < depositCount; ++i)
  181.         {
  182.             calibMeasureArray[i] = "Rate";
  183.             calibQuoteArray[i] = depositQuoteArray[i];
  184.             calibComponentArray[i] = depositArray[i];
  185.         }

  186.         for (int i = depositCount; i < calibComponentCount; ++i)
  187.         {
  188.             calibMeasureArray[i] = "SwapRate";
  189.             calibComponentArray[i] = fixFloatArray[i - depositCount];
  190.             calibQuoteArray[i] = fixFloatQuoteArray[i - depositCount];
  191.         }

  192.         return ScenarioDiscountCurveBuilder.NonlinearBuild (
  193.             dtSpot,
  194.             "USD",
  195.             calibComponentArray,
  196.             calibQuoteArray,
  197.             calibMeasureArray,
  198.             null
  199.         );

  200.         /* return LatentMarketStateBuilder.SingleStretchShapePreservingFundingCurve (
  201.             dtSpot,
  202.             strCurrency,
  203.             depositTenorArray,
  204.             depositQuoteArray,
  205.             "ForwardRate",
  206.             null, // adblFuturesQuote,
  207.             null, // "ForwardRate",
  208.             astrFixFloatMaturityTenor,
  209.             adblFixFloatQuote,
  210.             "SwapRate"
  211.         ); */
  212.     }

  213.     public static final void main (
  214.         final String[] astrArgs)
  215.         throws Exception
  216.     {
  217.         EnvManager.InitEnv ("");

  218.         JulianDate dtSpot = DateUtil.CreateFromYMD (
  219.             2017,
  220.             DateUtil.OCTOBER,
  221.             5
  222.         );

  223.         int iNumMonth = 720;
  224.         String strCurrency = "USD";
  225.         String[] astrForwardTenor = new String[] {
  226.              "1M",
  227.              "2M",
  228.              "3M",
  229.              "6M",
  230.             "12M"
  231.         };

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

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

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

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

  236.         MergedDiscountForwardCurve mdfc = FundingCurve (
  237.             dtSpot,
  238.             strCurrency
  239.         );

  240.         System.out.println
  241.             ("SpotDate,ViewDate,ForwardTenor,ViewDiscountFactor,ViewForwardDiscountFactor, ForwardRate");

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

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

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

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

  248.                 double dblForwardRate = Helper.DF2Yield (
  249.                     iLIBORFreq,
  250.                     dblDFForward / dblDFView,
  251.                     Convention.YearFraction (
  252.                         dtView.julian(),
  253.                         dtForward.julian(),
  254.                         strLIBORDayCount,
  255.                         false,
  256.                         null,
  257.                         strCurrency
  258.                     )
  259.                 );

  260.                 System.out.println (
  261.                     dtSpot + "," +
  262.                     dtView + "," +
  263.                     astrForwardTenor[j] + "," +
  264.                     FormatUtil.FormatDouble (dblDFView, 1, 8, 1.) + "," +
  265.                     FormatUtil.FormatDouble (dblDFForward, 1, 8, 1.) + "," +
  266.                     FormatUtil.FormatDouble (dblForwardRate, 1, 8, 100.) + "%"
  267.                 );
  268.             }
  269.         }

  270.         EnvManager.TerminateEnv();
  271.     }
  272. }