IBOR3MCubicKLKHyperbolic.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.ExponentialTensionSetParams;
  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>IBOR3MCubicKLKHyperbolic</i> illustrates the Construction and Usage of the IBOR 3M Forward Curve Using
  79.  * Cubic KLK Hyperbolic Tension B-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 IBOR3MCubicKLKHyperbolic {
  93.     public static final void main (
  94.         final String[] astrArgs)
  95.         throws Exception
  96.     {
  97.         /*
  98.          * Initialize the Credit Analytics Library
  99.          */

  100.         EnvManager.InitEnv ("");

  101.         JulianDate dtValue = DateUtil.CreateFromYMD (
  102.             2012,
  103.             DateUtil.DECEMBER,
  104.             11
  105.         );

  106.         String strTenor = "3M";
  107.         String strCurrency = "USD";

  108.         ForwardLabel fri = ForwardLabel.Create (
  109.             strCurrency,
  110.             strTenor
  111.         );

  112.         MergedDiscountForwardCurve dcEONIA = OvernightIndexCurve.MakeDC (
  113.             dtValue,
  114.             strCurrency
  115.         );

  116.         SegmentCustomBuilderControl scbcKLKHyperbolic = new SegmentCustomBuilderControl (
  117.             MultiSegmentSequenceBuilder.BASIS_SPLINE_KLK_HYPERBOLIC_TENSION,
  118.             new ExponentialTensionSetParams (1.),
  119.             SegmentInelasticDesignControl.Create (
  120.                 2,
  121.                 2
  122.             ),
  123.             new ResponseScalingShapeControl (
  124.                 true,
  125.                 new QuadraticRationalShapeControl (0.)
  126.             ),
  127.             null
  128.         );

  129.         /*
  130.          * Construct the Array of Deposit Instruments and their Quotes from the given set of parameters
  131.          */

  132.         double[] adblDepositQuote = new double[] {
  133.             0.001865,
  134.             0.001969,
  135.             0.001951,
  136.             0.001874
  137.         };

  138.         String[] astrDepositTenor = new String[] {
  139.             "2W",
  140.             "3W",
  141.             "1M",
  142.             "2M"
  143.         };

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

  147.         double[] adblFRAQuote = new double[] {
  148.             0.001790,
  149.             0.001775,
  150.             0.001274,
  151.             0.001222,
  152.             0.001269,
  153.             0.001565,
  154.             0.001961,
  155.             0.002556,
  156.             0.003101
  157.         };

  158.         String[] astrFRATenor = new String[] {
  159.              "0D",
  160.              "1M",
  161.              "3M",
  162.              "6M",
  163.              "9M",
  164.             "12M",
  165.             "15M",
  166.             "18M",
  167.             "21M"
  168.         };

  169.         /*
  170.          * Construct the Array of Fix-Float Component and their Quotes from the given set of parameters
  171.          */

  172.         double[] adblFixFloatQuote = new double[] {
  173.             0.002850,   //  3Y
  174.             0.004370,   //  4Y
  175.             0.006230,   //  5Y
  176.             0.008170,   //  6Y
  177.             0.010000,   //  7Y
  178.             0.011710,   //  8Y
  179.             0.013240,   //  9Y
  180.             0.014590,   // 10Y
  181.             0.016920,   // 12Y
  182.             0.019330,   // 15Y
  183.             0.020990,   // 20Y
  184.             0.021560,   // 25Y
  185.             0.021860    // 30Y
  186.         };

  187.         String[] astrFixFloatTenor = new String[] {
  188.              "3Y",
  189.              "4Y",
  190.              "5Y",
  191.              "6Y",
  192.              "7Y",
  193.              "8Y",
  194.              "9Y",
  195.             "10Y",
  196.             "12Y",
  197.             "15Y",
  198.             "20Y",
  199.             "25Y",
  200.             "30Y"
  201.         };

  202.         /*
  203.          * Construct the Array of Terminal Synthetic Float-Float Components and their Quotes from the given set of parameters
  204.          */

  205.         String[] astrSyntheticFloatFloatTenor = new String[] {
  206.             "35Y",
  207.             "40Y",
  208.             "50Y",
  209.             "60Y"
  210.         };

  211.         double[] adblSyntheticFloatFloatQuote = new double[] {
  212.             0.00065,
  213.             0.00060,
  214.             0.00054,
  215.             0.00050
  216.         };

  217.         ForwardCurve fc6M = IBOR6MCubicPolyVanilla.Make6MForward (
  218.             dtValue,
  219.             strCurrency,
  220.             "6M",
  221.             true
  222.         );

  223.         ForwardCurve fc = IBORCurve.CustomIBORBuilderSample (
  224.             dcEONIA,
  225.             fc6M,
  226.             fri,
  227.             scbcKLKHyperbolic,
  228.             astrDepositTenor,
  229.             adblDepositQuote,
  230.             "ForwardRate",
  231.             astrFRATenor,
  232.             adblFRAQuote,
  233.             "ParForwardRate",
  234.             astrFixFloatTenor,
  235.             adblFixFloatQuote,
  236.             "SwapRate",
  237.             null,
  238.             null,
  239.             "DerivedParBasisSpread",
  240.             astrSyntheticFloatFloatTenor,
  241.             adblSyntheticFloatFloatQuote,
  242.             "DerivedParBasisSpread",
  243.             "---- VANILLA CUBIC KLK HYPERBOLIC TENSION B-SPLINE FORWARD CURVE ---",
  244.             true
  245.         );

  246.         IBORCurve.ForwardJack (
  247.             dtValue,
  248.             "---- VANILLA CUBIC KLK HYPERBOLIC TENSION B-SPLINE FORWARD CURVE SENSITIVITY ---",
  249.             fc,
  250.             "DerivedParBasisSpread"
  251.         );

  252.         EnvManager.TerminateEnv();
  253.     }
  254. }