IBOR3MCubicPolyVanilla.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>IBOR3MCubicPolyVanilla</i> illustrates the Construction and Usage of the IBOR 3M 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 IBOR3MCubicPolyVanilla {

  93.     public static final ForwardCurve Make3MForward (
  94.         final String strTenor,
  95.         final String strCurrency,
  96.         final JulianDate dtValue,
  97.         final MergedDiscountForwardCurve dcEONIA,
  98.         final ForwardCurve fc6M,
  99.         final SegmentCustomBuilderControl scbc,
  100.         final boolean bPrintMetric)
  101.         throws Exception
  102.     {
  103.         ForwardLabel fri = ForwardLabel.Create (
  104.             strCurrency,
  105.             strTenor
  106.         );

  107.         /*
  108.          * Construct the Array of Deposit Instruments and their Quotes from the given set of parameters
  109.          */

  110.         double[] adblDepositQuote = new double[] {
  111.             0.001865,
  112.             0.001969,
  113.             0.001951,
  114.             0.001874
  115.         };

  116.         String[] astrDepositTenor = new String[] {
  117.             "2W",
  118.             "3W",
  119.             "1M",
  120.             "2M"
  121.         };

  122.         /*
  123.          * Construct the Array of FRAs and their Quotes from the given set of parameters
  124.          */

  125.         double[] adblFRAQuote = new double[] {
  126.             0.001790,
  127.             0.001775,
  128.             0.001274,
  129.             0.001222,
  130.             0.001269,
  131.             0.001565,
  132.             0.001961,
  133.             0.002556,
  134.             0.003101
  135.         };

  136.         String[] astrFRATenor = new String[] {
  137.              "0D",
  138.              "1M",
  139.              "3M",
  140.              "6M",
  141.              "9M",
  142.             "12M",
  143.             "15M",
  144.             "18M",
  145.             "21M"
  146.         };

  147.         /*
  148.          * Construct the Array of Fix-Float Component and their Quotes from the given set of parameters
  149.          */

  150.         double[] adblFixFloatQuote = new double[] {
  151.             0.002850,   //  3Y
  152.             0.004370,   //  4Y
  153.             0.006230,   //  5Y
  154.             0.008170,   //  6Y
  155.             0.010000,   //  7Y
  156.             0.011710,   //  8Y
  157.             0.013240,   //  9Y
  158.             0.014590,   // 10Y
  159.             0.016920,   // 12Y
  160.             0.019330,   // 15Y
  161.             0.020990,   // 20Y
  162.             0.021560,   // 25Y
  163.             0.021860    // 30Y
  164.         };

  165.         String[] astrFixFloatTenor = new String[] {
  166.              "3Y",
  167.              "4Y",
  168.              "5Y",
  169.              "6Y",
  170.              "7Y",
  171.              "8Y",
  172.              "9Y",
  173.             "10Y",
  174.             "12Y",
  175.             "15Y",
  176.             "20Y",
  177.             "25Y",
  178.             "30Y"
  179.         };

  180.         /*
  181.          * Construct the Array of Terminal Synthetic Float-Float Components and their Quotes from the given set of parameters
  182.          */

  183.         String[] astrSyntheticFloatFloatTenor = new String[] {
  184.             "35Y",
  185.             "40Y",
  186.             "50Y",
  187.             "60Y"
  188.         };

  189.         double[] adblSyntheticFloatFloatQuote = new double[] {
  190.             0.00065,
  191.             0.00060,
  192.             0.00054,
  193.             0.00050
  194.         };

  195.         ForwardCurve fc =
  196.             IBORCurve.CustomIBORBuilderSample (
  197.             dcEONIA,
  198.             fc6M,
  199.             fri,
  200.             scbc,
  201.             astrDepositTenor,
  202.             adblDepositQuote,
  203.             "ForwardRate",
  204.             astrFRATenor,
  205.             adblFRAQuote,
  206.             "ParForwardRate",
  207.             astrFixFloatTenor,
  208.             adblFixFloatQuote,
  209.             "SwapRate",
  210.             null,
  211.             null,
  212.             "DerivedParBasisSpread",
  213.             astrSyntheticFloatFloatTenor,
  214.             adblSyntheticFloatFloatQuote,
  215.             "DerivedParBasisSpread",
  216.             "---- VANILLA CUBIC POLYNOMIAL FORWARD CURVE ---",
  217.             bPrintMetric
  218.         );

  219.         return fc;
  220.     }

  221.     public static final void main (
  222.         final String[] astrArgs)
  223.         throws Exception
  224.     {
  225.         /*
  226.          * Initialize the Credit Analytics Library
  227.          */

  228.         EnvManager.InitEnv ("");

  229.         JulianDate dtValue = DateUtil.CreateFromYMD (
  230.             2012,
  231.             DateUtil.DECEMBER,
  232.             11
  233.         );

  234.         String strTenor = "3M";
  235.         String strCurrency = "GBP";

  236.         MergedDiscountForwardCurve dcEONIA = OvernightIndexCurve.MakeDC (
  237.             dtValue,
  238.             strCurrency
  239.         );

  240.         ForwardCurve fc6M = IBOR6MCubicPolyVanilla.Make6MForward (
  241.             dtValue,
  242.             strCurrency,
  243.             "6M",
  244.             true
  245.         );

  246.         SegmentCustomBuilderControl scbcCubic = new SegmentCustomBuilderControl (
  247.             MultiSegmentSequenceBuilder.BASIS_SPLINE_POLYNOMIAL,
  248.             new PolynomialFunctionSetParams (4),
  249.             SegmentInelasticDesignControl.Create (
  250.                 2,
  251.                 2
  252.             ),
  253.             new ResponseScalingShapeControl (
  254.                 true,
  255.                 new QuadraticRationalShapeControl (0.)
  256.             ),
  257.             null
  258.         );

  259.         ForwardCurve fc = Make3MForward (
  260.             strTenor,
  261.             strCurrency,
  262.             dtValue,
  263.             dcEONIA,
  264.             fc6M,
  265.             scbcCubic,
  266.             true
  267.         );

  268.         IBORCurve.ForwardJack (
  269.             dtValue,
  270.             "---- VANILLA CUBIC POLYNOMIAL FORWARD CURVE SENSITIVITY ---",
  271.             fc,
  272.             "DerivedParBasisSpread"
  273.         );

  274.         EnvManager.TerminateEnv();
  275.     }
  276. }