IBOR6MCubicPolyVanilla.java

  1. package org.drip.sample.forward;

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

  77. /**
  78.  * <i>IBOR6MCubicPolyVanilla</i> illustrates the Construction and Usage of the IBOR 6M Forward Curve Using
  79.  * Vanilla Cubic Polynomial.
  80.  *  
  81.  * <br><br>
  82.  *  <ul>
  83.  *      <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/AnalyticsCore.md">Analytics 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/sample/README.md">Sample</a></li>
  86.  *      <li><b>Package</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/sample/forward/README.md">Forward Rate Curve Construction</a></li>
  87.  *  </ul>
  88.  * <br><br>
  89.  *
  90.  * @author Lakshmi Krishnamurthy
  91.  */

  92. public class IBOR6MCubicPolyVanilla {
  93.     public static final ForwardCurve Make6MForward (
  94.         final JulianDate dtValue,
  95.         final String strCurrency,
  96.         final String strTenor,
  97.         final boolean bPrintMetric)
  98.         throws Exception
  99.     {
  100.         ForwardLabel fri = ForwardLabel.Create (
  101.             strCurrency,
  102.             strTenor
  103.         );

  104.         MergedDiscountForwardCurve dcEONIA = OvernightIndexCurve.MakeDC (
  105.             dtValue,
  106.             strCurrency
  107.         );

  108.         SegmentCustomBuilderControl scbcCubic = new SegmentCustomBuilderControl (
  109.             MultiSegmentSequenceBuilder.BASIS_SPLINE_POLYNOMIAL,
  110.             new PolynomialFunctionSetParams (4),
  111.             SegmentInelasticDesignControl.Create (
  112.                 2,
  113.                 2
  114.             ),
  115.             new ResponseScalingShapeControl (
  116.                 true,
  117.                 new QuadraticRationalShapeControl (0.)
  118.             ),
  119.             null
  120.         );

  121.         /*
  122.          * Construct the Array of Deposit Instruments and their Quotes from the given set of parameters
  123.          */

  124.         double[] adblDepositQuote = new double[] {
  125.             0.003565,   // 1D
  126.             0.003858,   // 1W
  127.             0.003840,   // 2W
  128.             0.003922,   // 3W
  129.             0.003869,   // 1M
  130.             0.003698,   // 2M
  131.             0.003527,   // 3M
  132.             0.003342,   // 4M
  133.             0.003225    // 5M
  134.         };

  135.         String[] astrDepositTenor = new String[] {
  136.             "1D",
  137.             "1W",
  138.             "2W",
  139.             "3W",
  140.             "1M",
  141.             "2M",
  142.             "3M",
  143.             "4M",
  144.             "5M"
  145.         };

  146.         /*
  147.          * Construct the Array of FRAs and their Quotes from the given set of parameters
  148.          */

  149.         double[] adblFRAQuote = new double[] {
  150.             0.003120,   //  0D
  151.             0.002930,   //  1M
  152.             0.002720,   //  2M
  153.             0.002600,   //  3M
  154.             0.002560,   //  4M
  155.             0.002520,   //  5M
  156.             0.002480,   //  6M
  157.             0.002540,   //  7M
  158.             0.002610,   //  8M
  159.             0.002670,   //  9M
  160.             0.002790,   // 10M
  161.             0.002910,   // 11M
  162.             0.003030,   // 12M
  163.             0.003180,   // 13M
  164.             0.003350,   // 14M
  165.             0.003520,   // 15M
  166.             0.003710,   // 16M
  167.             0.003890,   // 17M
  168.             0.004090    // 18M
  169.         };

  170.         String[] astrFRATenor = new String[] {
  171.              "0D",
  172.              "1M",
  173.              "2M",
  174.              "3M",
  175.              "4M",
  176.              "5M",
  177.              "6M",
  178.              "7M",
  179.              "8M",
  180.              "9M",
  181.             "10M",
  182.             "11M",
  183.             "12M",
  184.             "13M",
  185.             "14M",
  186.             "15M",
  187.             "16M",
  188.             "17M",
  189.             "18M"
  190.         };

  191.         /*
  192.          * Construct the Array of Fix-Float Component and their Quotes from the given set of parameters
  193.          */

  194.         double[] adblFixFloatQuote = new double[] {
  195.             0.004240,   //  3Y
  196.             0.005760,   //  4Y          
  197.             0.007620,   //  5Y
  198.             0.009540,   //  6Y
  199.             0.011350,   //  7Y
  200.             0.013030,   //  8Y
  201.             0.014520,   //  9Y
  202.             0.015840,   // 10Y
  203.             0.018090,   // 12Y
  204.             0.020370,   // 15Y
  205.             0.021870,   // 20Y
  206.             0.022340,   // 25Y
  207.             0.022560,   // 30Y
  208.             0.022950,   // 35Y
  209.             0.023480,   // 40Y
  210.             0.024210,   // 50Y
  211.             0.024630    // 60Y
  212.         };

  213.         String[] astrFixFloatTenor = new String[] {
  214.              "3Y",
  215.              "4Y",
  216.              "5Y",
  217.              "6Y",
  218.              "7Y",
  219.              "8Y",
  220.              "9Y",
  221.             "10Y",
  222.             "12Y",
  223.             "15Y",
  224.             "20Y",
  225.             "25Y",
  226.             "30Y",
  227.             "35Y",
  228.             "40Y",
  229.             "50Y",
  230.             "60Y"
  231.         };

  232.         ForwardCurve fc = IBORCurve.CustomIBORBuilderSample (
  233.             dcEONIA,
  234.             null,
  235.             fri,
  236.             scbcCubic,
  237.             astrDepositTenor,
  238.             adblDepositQuote,
  239.             "ForwardRate",
  240.             astrFRATenor,
  241.             adblFRAQuote,
  242.             "ParForwardRate",
  243.             astrFixFloatTenor,
  244.             adblFixFloatQuote,
  245.             "SwapRate",
  246.             null,
  247.             null,
  248.             "DerivedParBasisSpread",
  249.             null,
  250.             null,
  251.             "DerivedParBasisSpread",
  252.             "---- EURIBOR 6M VANILLA CUBIC POLYNOMIAL FORWARD CURVE ---",
  253.             bPrintMetric
  254.         );

  255.         /* if (bPrintMetric)
  256.             IBORCurve.ForwardJack (
  257.                 dtValue,
  258.                 "---- EURIBOR 6M VANILLA CUBIC POLYNOMIAL FORWARD CURVE SENSITIVITY ---",
  259.                 fc,
  260.                 "DerivedParBasisSpread"
  261.             ); */

  262.         return fc;
  263.     }

  264.     public static final void main (
  265.         final String[] astrArgs)
  266.         throws Exception
  267.     {
  268.         /*
  269.          * Initialize the Credit Analytics Library
  270.          */

  271.         EnvManager.InitEnv ("");

  272.         Make6MForward (
  273.             DateUtil.CreateFromYMD (
  274.                 2012,
  275.                 DateUtil.DECEMBER,
  276.                 11
  277.             ),
  278.             "GBP",
  279.             "6M",
  280.             true
  281.         );

  282.         EnvManager.TerminateEnv();
  283.     }
  284. }