IBOR1MCubicKLKHyperbolic.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>IBOR1MCubicKLKHyperbolic</i> illustrates the Construction and Usage of the IBOR 1M Forward Curve Using
  79.  * Vanilla Cubic KLK Hyperbolic Tension B-Splines.
  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 IBOR1MCubicKLKHyperbolic {
  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 = "1M";
  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 scbcCubicKLKHyperbolic = 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.000661,
  134.             0.000980,
  135.             0.000993
  136.         };

  137.         String[] astrDepositTenor = new String[] {
  138.             "1D",
  139.             "7D",
  140.             "14D"
  141.         };

  142.         /*
  143.          * Construct the Array of Fix-Float Component and their Quotes from the given set of parameters
  144.          */

  145.         double[] adblFixFloatQuote = new double[] {
  146.             0.001100,
  147.             0.001060,
  148.             0.000960,
  149.             0.000850,
  150.             0.000790,
  151.             0.000750,
  152.             0.000710,
  153.             0.000690,
  154.             0.000660,
  155.             0.000650,
  156.             0.000640,
  157.             0.000630
  158.         };

  159.         String[] astrFixFloatTenor = new String[] {
  160.              "1M",
  161.              "2M",
  162.              "3M",
  163.              "4M",
  164.              "5M",
  165.              "6M",
  166.              "7M",
  167.              "8M",
  168.              "9M",
  169.             "10M",
  170.             "11M",
  171.             "12M"
  172.         };

  173.         /*
  174.          * Construct the Array of Float-Float Component and their Quotes from the given set of parameters
  175.          */

  176.         double[] adblFloatFloatQuote = new double[] {
  177.             0.002260,   //  2Y
  178.             0.002380,   //  3Y
  179.             0.002460,   //  4Y
  180.             0.002500,   //  5Y
  181.             0.002500,   //  6Y
  182.             0.002480,   //  7Y
  183.             0.002450,   //  8Y
  184.             0.002410,   //  9Y
  185.             0.002370,   // 10Y
  186.             0.002330,   // 11Y
  187.             0.002280,   // 12Y
  188.             0.002110,   // 15Y
  189.             0.001890,   // 20Y
  190.             0.001750,   // 25Y
  191.             0.001630    // 30Y
  192.         };

  193.         String[] astrFloatFloatTenor = new String[] {
  194.               "2Y",
  195.               "3Y",
  196.               "4Y",
  197.               "5Y",
  198.               "6Y",
  199.               "7Y",
  200.               "8Y",
  201.               "9Y",
  202.              "10Y",
  203.              "11Y",
  204.              "12Y",
  205.              "15Y",
  206.              "20Y",
  207.              "25Y",
  208.              "30Y"
  209.         };

  210.         /*
  211.          * Construct the Array of Terminal Synthetic Float-Float Components and their Quotes from the given set of parameters
  212.          */

  213.         String[] astrSyntheticFloatFloatTenor = new String[] {
  214.             "35Y",
  215.             "40Y",
  216.             "50Y",
  217.             "60Y"
  218.         };

  219.         double[] adblSyntheticFloatFloatQuote = new double[] {
  220.             0.001630,
  221.             0.001630,
  222.             0.001630,
  223.             0.001630
  224.         };

  225.         ForwardCurve fc6M = IBOR6MCubicPolyVanilla.Make6MForward (
  226.             dtValue,
  227.             strCurrency,
  228.             "6M",
  229.             true
  230.         );

  231.         ForwardCurve fc = IBORCurve.CustomIBORBuilderSample (
  232.             dcEONIA,
  233.             fc6M,
  234.             fri,
  235.             scbcCubicKLKHyperbolic,
  236.             astrDepositTenor,
  237.             adblDepositQuote,
  238.             "ForwardRate",
  239.             null,
  240.             null,
  241.             "ParForwardRate",
  242.             astrFixFloatTenor,
  243.             adblFixFloatQuote,
  244.             "SwapRate",
  245.             astrFloatFloatTenor,
  246.             adblFloatFloatQuote,
  247.             "DerivedParBasisSpread",
  248.             astrSyntheticFloatFloatTenor,
  249.             adblSyntheticFloatFloatQuote,
  250.             "DerivedParBasisSpread",
  251.             "---- VANILLA CUBIC KLK HYPERBOLIC TENSION B-SPLINE FORWARD CURVE ---",
  252.             true
  253.         );

  254.         IBORCurve.ForwardJack (
  255.             dtValue,
  256.             "---- VANILLA CUBIC KLK HYPERBOLIC TENSION B-SPLINE FORWARD CURVE SENSITIVITY ---",
  257.             fc,
  258.             "DerivedParBasisSpread"
  259.         );

  260.         EnvManager.TerminateEnv();
  261.     }
  262. }