IBOR6MQuarticPolyVanilla.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>IBOR6MQuarticPolyVanilla</i> illustrates the Construction and Usage of the IBOR 6M Forward Curve Using
  79.  * Vanilla Quartic Polynomial Spline.
  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 IBOR6MQuarticPolyVanilla {
  93.     public static final ForwardCurve Make6MForward (
  94.         final JulianDate dtValue,
  95.         final String strCurrency,
  96.         final String strTenor)
  97.         throws Exception
  98.     {
  99.         ForwardLabel fri = ForwardLabel.Create (strCurrency, strTenor);

  100.         MergedDiscountForwardCurve dcEONIA = OvernightIndexCurve.MakeDC (
  101.             dtValue,
  102.             strCurrency
  103.         );

  104.         SegmentCustomBuilderControl scbcQuartic = new SegmentCustomBuilderControl (
  105.             MultiSegmentSequenceBuilder.BASIS_SPLINE_POLYNOMIAL,
  106.             new PolynomialFunctionSetParams (5),
  107.             SegmentInelasticDesignControl.Create (
  108.                 2,
  109.                 2
  110.             ),
  111.             new ResponseScalingShapeControl (
  112.                 true,
  113.                 new QuadraticRationalShapeControl (0.)
  114.             ),
  115.             null
  116.         );

  117.         /*
  118.          * Construct the Array of Deposit Instruments and their Quotes from the given set of parameters
  119.          */

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

  131.         String[] astrDepositTenor = new String[] {
  132.             "1D",
  133.             "1W",
  134.             "2W",
  135.             "3W",
  136.             "1M",
  137.             "2M",
  138.             "3M",
  139.             "4M",
  140.             "5M"
  141.         };

  142.         /*
  143.          * Construct the Array of FRAs and their Quotes from the given set of parameters
  144.          */

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

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

  187.         /*
  188.          * Construct the Array of Fix-Float Component and their Quotes from the given set of parameters
  189.          */

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

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

  228.         ForwardCurve fc = IBORCurve.CustomIBORBuilderSample (
  229.             dcEONIA,
  230.             null,
  231.             fri,
  232.             scbcQuartic,
  233.             astrDepositTenor,
  234.             adblDepositQuote,
  235.             "ForwardRate",
  236.             astrFRATenor,
  237.             adblFRAQuote,
  238.             "ParForwardRate",
  239.             astrFixFloatTenor,
  240.             adblFixFloatQuote,
  241.             "SwapRate",
  242.             null,
  243.             null,
  244.             "DerivedParBasisSpread",
  245.             null,
  246.             null,
  247.             "DerivedParBasisSpread",
  248.             "---- EURIBOR 6M VANILLA QUARTIC POLYNOMIAL FORWARD CURVE ---",
  249.             true
  250.         );

  251.         IBORCurve.ForwardJack (
  252.             dtValue,
  253.             "---- EURIBOR 6M VANILLA QUARTIC POLYNOMIAL FORWARD CURVE SENSITIVITY ---",
  254.             fc,
  255.             "DerivedParBasisSpread"
  256.         );

  257.         return fc;
  258.     }

  259.     public static final void main (
  260.         final String[] astrArgs)
  261.         throws Exception
  262.     {
  263.         /*
  264.          * Initialize the Credit Analytics Library
  265.          */

  266.         EnvManager.InitEnv ("");

  267.         Make6MForward (
  268.             DateUtil.CreateFromYMD (
  269.                 2012,
  270.                 DateUtil.DECEMBER,
  271.                 11
  272.             ),
  273.             "EUR",
  274.             "6M"
  275.         );

  276.         EnvManager.TerminateEnv();
  277.     }
  278. }