ReferenceForwardState.java

  1. package org.drip.template.state;

  2. import org.drip.analytics.date.*;
  3. import org.drip.numerical.common.FormatUtil;
  4. import org.drip.service.env.EnvManager;
  5. import org.drip.service.template.LatentMarketStateBuilder;
  6. import org.drip.state.discount.*;
  7. import org.drip.state.forward.ForwardCurve;
  8. import org.drip.state.identifier.ForwardLabel;

  9. /*
  10.  * -*- mode: java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  11.  */

  12. /*!
  13.  * Copyright (C) 2020 Lakshmi Krishnamurthy
  14.  * Copyright (C) 2019 Lakshmi Krishnamurthy
  15.  * Copyright (C) 2018 Lakshmi Krishnamurthy
  16.  * Copyright (C) 2017 Lakshmi Krishnamurthy
  17.  * Copyright (C) 2016 Lakshmi Krishnamurthy
  18.  * Copyright (C) 2015 Lakshmi Krishnamurthy
  19.  *
  20.  *  This file is part of DROP, an open-source library targeting analytics/risk, transaction cost analytics,
  21.  *      asset liability management analytics, capital, exposure, and margin analytics, valuation adjustment
  22.  *      analytics, and portfolio construction analytics within and across fixed income, credit, commodity,
  23.  *      equity, FX, and structured products. It also includes auxiliary libraries for algorithm support,
  24.  *      numerical analysis, numerical optimization, spline builder, model validation, statistical learning,
  25.  *      and computational support.
  26.  *  
  27.  *      https://lakshmidrip.github.io/DROP/
  28.  *  
  29.  *  DROP is composed of three modules:
  30.  *  
  31.  *  - DROP Product Core - https://lakshmidrip.github.io/DROP-Product-Core/
  32.  *  - DROP Portfolio Core - https://lakshmidrip.github.io/DROP-Portfolio-Core/
  33.  *  - DROP Computational Core - https://lakshmidrip.github.io/DROP-Computational-Core/
  34.  *
  35.  *  DROP Product Core implements libraries for the following:
  36.  *  - Fixed Income Analytics
  37.  *  - Loan Analytics
  38.  *  - Transaction Cost Analytics
  39.  *
  40.  *  DROP Portfolio Core implements libraries for the following:
  41.  *  - Asset Allocation Analytics
  42.  *  - Asset Liability Management Analytics
  43.  *  - Capital Estimation Analytics
  44.  *  - Exposure Analytics
  45.  *  - Margin Analytics
  46.  *  - XVA Analytics
  47.  *
  48.  *  DROP Computational Core implements libraries for the following:
  49.  *  - Algorithm Support
  50.  *  - Computation Support
  51.  *  - Function Analysis
  52.  *  - Model Validation
  53.  *  - Numerical Analysis
  54.  *  - Numerical Optimizer
  55.  *  - Spline Builder
  56.  *  - Statistical Learning
  57.  *
  58.  *  Documentation for DROP is Spread Over:
  59.  *
  60.  *  - Main                     => https://lakshmidrip.github.io/DROP/
  61.  *  - Wiki                     => https://github.com/lakshmiDRIP/DROP/wiki
  62.  *  - GitHub                   => https://github.com/lakshmiDRIP/DROP
  63.  *  - Repo Layout Taxonomy     => https://github.com/lakshmiDRIP/DROP/blob/master/Taxonomy.md
  64.  *  - Javadoc                  => https://lakshmidrip.github.io/DROP/Javadoc/index.html
  65.  *  - Technical Specifications => https://github.com/lakshmiDRIP/DROP/tree/master/Docs/Internal
  66.  *  - Release Versions         => https://lakshmidrip.github.io/DROP/version.html
  67.  *  - Community Credits        => https://lakshmidrip.github.io/DROP/credits.html
  68.  *  - Issues Catalog           => https://github.com/lakshmiDRIP/DROP/issues
  69.  *  - JUnit                    => https://lakshmidrip.github.io/DROP/junit/index.html
  70.  *  - Jacoco                   => https://lakshmidrip.github.io/DROP/jacoco/index.html
  71.  *
  72.  *  Licensed under the Apache License, Version 2.0 (the "License");
  73.  *      you may not use this file except in compliance with the License.
  74.  *  
  75.  *  You may obtain a copy of the License at
  76.  *      http://www.apache.org/licenses/LICENSE-2.0
  77.  *  
  78.  *  Unless required by applicable law or agreed to in writing, software
  79.  *      distributed under the License is distributed on an "AS IS" BASIS,
  80.  *      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  81.  *  
  82.  *  See the License for the specific language governing permissions and
  83.  *      limitations under the License.
  84.  */

  85. /**
  86.  * <i>ReferenceForwardState</i> sets up the Calibration of the Reference Forward Latent State and examine the
  87.  * Emitted Metrics.
  88.  *
  89.  *  <br><br>
  90.  *  <ul>
  91.  *      <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/ProductCore.md">Product Core Module</a></li>
  92.  *      <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/FixedIncomeAnalyticsLibrary.md">Fixed Income Analytics</a></li>
  93.  *      <li><b>Project</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/template/README.md">Pricing/Risk Templates for Fixed Income Component Products</a></li>
  94.  *      <li><b>Package</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/template/state/README.md">Standard Latent State Construction Template</a></li>
  95.  *  </ul>
  96.  * <br><br>
  97.  *
  98.  * @author Lakshmi Krishnamurthy
  99.  */

  100. public class ReferenceForwardState {

  101.     private static final MergedDiscountForwardCurve OvernightCurve (
  102.         final JulianDate dtSpot,
  103.         final String strCurrency)
  104.         throws Exception
  105.     {
  106.         EnvManager.InitEnv ("");

  107.         String[] astrDepositMaturityTenor = new String[] {
  108.             "1D",
  109.             // "2D",
  110.             "3D"
  111.         };

  112.         double[] adblDepositQuote = new double[] {
  113.             0.0004,     // 1D
  114.             // 0.0004,      // 2D
  115.             0.0004      // 3D
  116.         };

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

  123.         double[] adblShortEndOISQuote = new double[] {
  124.             0.00070,    //   1W
  125.             0.00069,    //   2W
  126.             0.00078,    //   3W
  127.             0.00074     //   1M
  128.         };

  129.         String[] astrOISFuturesEffectiveTenor = new String[] {
  130.             "1M",
  131.             "2M",
  132.             "3M",
  133.             "4M",
  134.             "5M"
  135.         };

  136.         String[] astrOISFuturesMaturityTenor = new String[] {
  137.             "1M",
  138.             "1M",
  139.             "1M",
  140.             "1M",
  141.             "1M"
  142.         };

  143.         double[] adblOISFuturesQuote = new double[] {
  144.              0.00046,    //   1M x 1M
  145.              0.00016,    //   2M x 1M
  146.             -0.00007,    //   3M x 1M
  147.             -0.00013,    //   4M x 1M
  148.             -0.00014     //   5M x 1M
  149.         };

  150.         String[] astrLongEndOISMaturityTenor = new String[] {
  151.             "15M",
  152.             "18M",
  153.             "21M",
  154.             "02Y",
  155.             "03Y",
  156.             "04Y",
  157.             "05Y",
  158.             "06Y",
  159.             "07Y",
  160.             "08Y",
  161.             "09Y",
  162.             "10Y",
  163.             "11Y",
  164.             "12Y",
  165.             "15Y",
  166.             "20Y",
  167.             "25Y",
  168.             "30Y"
  169.         };

  170.         double[] adblLongEndOISQuote = new double[] {
  171.             0.00002,    //  15M
  172.             0.00008,    //  18M
  173.             0.00021,    //  21M
  174.             0.00036,    //   2Y
  175.             0.00127,    //   3Y
  176.             0.00274,    //   4Y
  177.             0.00456,    //   5Y
  178.             0.00647,    //   6Y
  179.             0.00827,    //   7Y
  180.             0.00996,    //   8Y
  181.             0.01147,    //   9Y
  182.             0.01280,    //  10Y
  183.             0.01404,    //  11Y
  184.             0.01516,    //  12Y
  185.             0.01764,    //  15Y
  186.             0.01939,    //  20Y
  187.             0.02003,    //  25Y
  188.             0.02038     //  30Y
  189.         };

  190.         return LatentMarketStateBuilder.SmoothOvernightCurve (
  191.             dtSpot,
  192.             strCurrency,
  193.             astrDepositMaturityTenor,
  194.             adblDepositQuote,
  195.             "Rate",
  196.             astrShortEndOISMaturityTenor,
  197.             adblShortEndOISQuote,
  198.             "SwapRate",
  199.             astrOISFuturesEffectiveTenor,
  200.             astrOISFuturesMaturityTenor,
  201.             adblOISFuturesQuote,
  202.             "SwapRate",
  203.             astrLongEndOISMaturityTenor,
  204.             adblLongEndOISQuote,
  205.             "SwapRate"
  206.         );
  207.     }

  208.     public static final void main (
  209.         final String[] astrArgs)
  210.         throws Exception
  211.     {
  212.         /*
  213.          * Initialize the Credit Analytics Library
  214.          */

  215.         EnvManager.InitEnv ("");

  216.         String strCurrency = "GBP";
  217.         String strForwardTenor = "6M";

  218.         JulianDate dtSpot = DateUtil.CreateFromYMD (
  219.             2017,
  220.             DateUtil.DECEMBER,
  221.             21
  222.         );

  223.         MergedDiscountForwardCurve dcOvernight = OvernightCurve (
  224.             dtSpot,
  225.             strCurrency
  226.         );

  227.         ForwardLabel forwardLabel = ForwardLabel.Create (
  228.             strCurrency,
  229.             strForwardTenor
  230.         );

  231.         String[] astrDepositMaturityTenor = new String[] {
  232.             "1D",
  233.             "1W",
  234.             "2W",
  235.             "3W",
  236.             "1M",
  237.             "2M",
  238.             "3M",
  239.             "4M",
  240.             "5M"
  241.         };

  242.         double[] adblDepositQuote = new double[] {
  243.             0.003565,   // 1D
  244.             0.003858,   // 1W
  245.             0.003840,   // 2W
  246.             0.003922,   // 3W
  247.             0.003869,   // 1M
  248.             0.003698,   // 2M
  249.             0.003527,   // 3M
  250.             0.003342,   // 4M
  251.             0.003225    // 5M
  252.         };

  253.         String[] astrFRAExerciseTenor = new String[] {
  254.             "00D",
  255.             "01M",
  256.             "02M",
  257.             "03M",
  258.             "04M",
  259.             "05M",
  260.             "06M",
  261.             "07M",
  262.             "08M",
  263.             "09M",
  264.             "10M",
  265.             "11M",
  266.             "12M",
  267.             "13M",
  268.             "14M",
  269.             "15M",
  270.             "16M",
  271.             "17M",
  272.             "18M"
  273.         };

  274.         double[] adblFRAQuote = new double[] {
  275.             0.003120,   //  0D
  276.             0.002930,   //  1M
  277.             0.002720,   //  2M
  278.             0.002600,   //  3M
  279.             0.002560,   //  4M
  280.             0.002520,   //  5M
  281.             0.002480,   //  6M
  282.             0.002540,   //  7M
  283.             0.002610,   //  8M
  284.             0.002670,   //  9M
  285.             0.002790,   // 10M
  286.             0.002910,   // 11M
  287.             0.003030,   // 12M
  288.             0.003180,   // 13M
  289.             0.003350,   // 14M
  290.             0.003520,   // 15M
  291.             0.003710,   // 16M
  292.             0.003890,   // 17M
  293.             0.004090    // 18M
  294.         };

  295.         String[] astrFixFloatMaturityTenor = new String[] {
  296.             "03Y",
  297.             "04Y",
  298.             "05Y",
  299.             "06Y",
  300.             "07Y",
  301.             "08Y",
  302.             "09Y",
  303.             "10Y",
  304.             "12Y",
  305.             "15Y",
  306.             "20Y",
  307.             "25Y",
  308.             "30Y",
  309.             "35Y",
  310.             "40Y",
  311.             "50Y",
  312.             "60Y"
  313.         };

  314.         double[] adblFixFloatQuote = new double[] {
  315.             0.004240,   //  3Y
  316.             0.005760,   //  4Y          
  317.             0.007620,   //  5Y
  318.             0.009540,   //  6Y
  319.             0.011350,   //  7Y
  320.             0.013030,   //  8Y
  321.             0.014520,   //  9Y
  322.             0.015840,   // 10Y
  323.             0.018090,   // 12Y
  324.             0.020370,   // 15Y
  325.             0.021870,   // 20Y
  326.             0.022340,   // 25Y
  327.             0.022560,   // 30Y
  328.             0.022950,   // 35Y
  329.             0.023480,   // 40Y
  330.             0.024210,   // 50Y
  331.             0.024630    // 60Y
  332.         };

  333.         ForwardCurve fcReference = LatentMarketStateBuilder.SmoothForwardCurve (
  334.             dtSpot,
  335.             forwardLabel,
  336.             astrDepositMaturityTenor,
  337.             adblDepositQuote,
  338.             "ForwardRate",
  339.             astrFRAExerciseTenor,
  340.             adblFRAQuote,
  341.             "ParForwardRate",
  342.             astrFixFloatMaturityTenor,
  343.             adblFixFloatQuote,
  344.             "SwapRate",
  345.             null,
  346.             null,
  347.             "DerivedParBasisSpread",
  348.             null,
  349.             null,
  350.             "DerivedParBasisSpread",
  351.             dcOvernight,
  352.             null
  353.         );

  354.         String strLatentStateLabel = fcReference.label().fullyQualifiedName();

  355.         System.out.println ("\n\n\t||-------------------------------------------------------------------------||");

  356.         for (int i = 0; i < adblDepositQuote.length; ++i)
  357.             System.out.println (
  358.                 "\t||  " + strLatentStateLabel +
  359.                 " |  DEPOSIT  | " + astrDepositMaturityTenor[i] + "  | " +
  360.                 FormatUtil.FormatDouble (adblDepositQuote[i], 1, 4, 100.) +
  361.                 "% | Forward Rate | " +
  362.                 FormatUtil.FormatDouble (fcReference.forward (astrDepositMaturityTenor[i]), 1, 4, 100.) +
  363.                 "%  ||"
  364.             );

  365.         System.out.println ("\t||-------------------------------------------------------------------------||");

  366.         System.out.println ("\n\n\t||--------------------------------------------------------------------------||");

  367.         for (int i = 0; i < adblFRAQuote.length; ++i)
  368.             System.out.println (
  369.                 "\t||  " + strLatentStateLabel +
  370.                 " |  FRA  | " + astrFRAExerciseTenor[i] + "  | " +
  371.                 FormatUtil.FormatDouble (adblFRAQuote[i], 1, 4, 100.) +
  372.                 "% | Par Forward Rate | " +
  373.                 FormatUtil.FormatDouble (fcReference.forward (dtSpot.addTenor (astrFRAExerciseTenor[i]).addTenor (strForwardTenor)), 1, 4, 100.) +
  374.                 "%  ||"
  375.             );

  376.         System.out.println ("\t||--------------------------------------------------------------------------||");

  377.         System.out.println ("\n\n\t||-------------------------------------------------------------------------||");

  378.         for (int i = 0; i < adblFixFloatQuote.length; ++i)
  379.             System.out.println (
  380.                 "\t||  " + strLatentStateLabel +
  381.                 " |  FIX FLOAT  | " + astrFixFloatMaturityTenor[i] + "  | " +
  382.                 FormatUtil.FormatDouble (adblFixFloatQuote[i], 1, 4, 100.) +
  383.                 "% | Swap Rate | " +
  384.                 FormatUtil.FormatDouble (fcReference.forward (astrFixFloatMaturityTenor[i]), 1, 4, 100.) +
  385.                 "%  ||"
  386.             );

  387.         System.out.println ("\t||-------------------------------------------------------------------------||");
  388.     }
  389. }