PathExerciseIndicator.java

  1. package org.drip.sample.govviemc;

  2. import org.drip.analytics.date.*;
  3. import org.drip.param.creator.MarketParamsBuilder;
  4. import org.drip.param.market.CurveSurfaceQuoteContainer;
  5. import org.drip.param.valuation.ValuationParams;
  6. import org.drip.product.creator.BondBuilder;
  7. import org.drip.product.credit.BondComponent;
  8. import org.drip.product.params.EmbeddedOptionSchedule;
  9. import org.drip.service.env.EnvManager;
  10. import org.drip.service.template.LatentMarketStateBuilder;
  11. import org.drip.state.discount.MergedDiscountForwardCurve;
  12. import org.drip.state.govvie.GovvieCurve;
  13. import org.drip.state.sequence.*;

  14. /*
  15.  * -*- mode: java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  16.  */

  17. /*!
  18.  * Copyright (C) 2019 Lakshmi Krishnamurthy
  19.  * Copyright (C) 2018 Lakshmi Krishnamurthy
  20.  * Copyright (C) 2017 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>PathExerciseIndicator</i> demonstrates the Simulations of the Per-Path Callable Bond OAS Based Exercise
  79.  * Indicator.
  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/govviemc/README.md">Govvie Curve Monte Carlo Runs</a></li>
  87.  *  </ul>
  88.  * <br><br>
  89.  *
  90.  * @author Lakshmi Krishnamurthy
  91.  */

  92. public class PathExerciseIndicator {

  93.     private static final MergedDiscountForwardCurve FundingCurve (
  94.         final JulianDate dtSpot,
  95.         final String strCurrency,
  96.         final double dblBump)
  97.         throws Exception
  98.     {
  99.         String[] astrDepositMaturityTenor = new String[] {
  100.             "2D"
  101.         };

  102.         double[] adblDepositQuote = new double[] {
  103.             0.0111956 + dblBump // 2D
  104.         };

  105.         double[] adblFuturesQuote = new double[] {
  106.             0.011375 + dblBump, // 98.8625
  107.             0.013350 + dblBump, // 98.6650
  108.             0.014800 + dblBump, // 98.5200
  109.             0.016450 + dblBump, // 98.3550
  110.             0.017850 + dblBump, // 98.2150
  111.             0.019300 + dblBump  // 98.0700
  112.         };

  113.         String[] astrFixFloatMaturityTenor = new String[] {
  114.             "02Y",
  115.             "03Y",
  116.             "04Y",
  117.             "05Y",
  118.             "06Y",
  119.             "07Y",
  120.             "08Y",
  121.             "09Y",
  122.             "10Y",
  123.             "11Y",
  124.             "12Y",
  125.             "15Y",
  126.             "20Y",
  127.             "25Y",
  128.             "30Y",
  129.             "40Y",
  130.             "50Y"
  131.         };

  132.         double[] adblFixFloatQuote = new double[] {
  133.             0.017029 + dblBump, //  2Y
  134.             0.019354 + dblBump, //  3Y
  135.             0.021044 + dblBump, //  4Y
  136.             0.022291 + dblBump, //  5Y
  137.             0.023240 + dblBump, //  6Y
  138.             0.024025 + dblBump, //  7Y
  139.             0.024683 + dblBump, //  8Y
  140.             0.025243 + dblBump, //  9Y
  141.             0.025720 + dblBump, // 10Y
  142.             0.026130 + dblBump, // 11Y
  143.             0.026495 + dblBump, // 12Y
  144.             0.027230 + dblBump, // 15Y
  145.             0.027855 + dblBump, // 20Y
  146.             0.028025 + dblBump, // 25Y
  147.             0.028028 + dblBump, // 30Y
  148.             0.027902 + dblBump, // 40Y
  149.             0.027655 + dblBump  // 50Y
  150.         };

  151.         return LatentMarketStateBuilder.SmoothFundingCurve (
  152.             dtSpot,
  153.             strCurrency,
  154.             astrDepositMaturityTenor,
  155.             adblDepositQuote,
  156.             "ForwardRate",
  157.             adblFuturesQuote,
  158.             "ForwardRate",
  159.             astrFixFloatMaturityTenor,
  160.             adblFixFloatQuote,
  161.             "SwapRate"
  162.         );
  163.     }

  164.     private static final PathGovvie PathGovvieCurves (
  165.         final JulianDate dtSpot,
  166.         final int iNumPath)
  167.         throws Exception
  168.     {
  169.         double dblVolatility = 0.10;
  170.         String strTreasuryCode = "UST";

  171.         String[] astrTenor = new String[] {
  172.             "01Y",
  173.             "02Y",
  174.             "03Y",
  175.             "05Y",
  176.             "07Y",
  177.             "10Y",
  178.             "20Y",
  179.             "30Y"
  180.         };

  181.         double[] adblTreasuryCoupon = new double[] {
  182.             0.0100,
  183.             0.0100,
  184.             0.0125,
  185.             0.0150,
  186.             0.0200,
  187.             0.0225,
  188.             0.0250,
  189.             0.0300
  190.         };

  191.         double[] adblTreasuryYield = new double[] {
  192.             0.0083, //  1Y
  193.             0.0122, //  2Y
  194.             0.0149, //  3Y
  195.             0.0193, //  5Y
  196.             0.0227, //  7Y
  197.             0.0248, // 10Y
  198.             0.0280, // 20Y
  199.             0.0308  // 30Y
  200.         };

  201.         return new PathGovvie (
  202.             new GovvieBuilderSettings (
  203.                 dtSpot,
  204.                 strTreasuryCode,
  205.                 astrTenor,
  206.                 adblTreasuryCoupon,
  207.                 adblTreasuryYield
  208.             ),
  209.             dblVolatility,
  210.             true
  211.         );
  212.     }

  213.     private static final BondComponent Callable (
  214.         final EmbeddedOptionSchedule eos)
  215.         throws Exception
  216.     {
  217.         JulianDate dtEffective = DateUtil.CreateFromYMD (
  218.             2009,
  219.             12,
  220.             3
  221.         );

  222.         JulianDate dtMaturity  = DateUtil.CreateFromYMD (
  223.             2039,
  224.             12,
  225.             1
  226.         );

  227.         double dblCoupon = 0.06558;
  228.         int iFreq = 2;
  229.         String strCUSIP = "033177XV3";
  230.         String strDayCount = "30/360";

  231.         BondComponent bond = BondBuilder.CreateSimpleFixed (
  232.             strCUSIP,
  233.             "USD",
  234.             "",
  235.             dblCoupon,
  236.             iFreq,
  237.             strDayCount,
  238.             dtEffective,
  239.             dtMaturity,
  240.             null,
  241.             null
  242.         );

  243.         bond.setEmbeddedCallSchedule (eos);

  244.         return bond;
  245.     }

  246.     public static final void main (
  247.         final String[] astrArgs)
  248.         throws Exception
  249.     {
  250.         EnvManager.InitEnv ("");

  251.         JulianDate dtSpot = DateUtil.CreateFromYMD (
  252.             2017,
  253.             DateUtil.MARCH,
  254.             24
  255.         );

  256.         int iNumPath = 50;
  257.         double dblCleanPrice = 1.08641;
  258.         int[] aiExerciseDate = new int[] {
  259.             DateUtil.CreateFromYMD (2019, 12,  1).julian(),
  260.             DateUtil.CreateFromYMD (2020, 12,  1).julian(),
  261.             DateUtil.CreateFromYMD (2021, 12,  1).julian(),
  262.             DateUtil.CreateFromYMD (2022, 12,  1).julian(),
  263.             DateUtil.CreateFromYMD (2023, 12,  1).julian(),
  264.             DateUtil.CreateFromYMD (2024, 12,  1).julian(),
  265.             DateUtil.CreateFromYMD (2025, 12,  1).julian(),
  266.             DateUtil.CreateFromYMD (2026, 12,  1).julian(),
  267.             DateUtil.CreateFromYMD (2027, 12,  1).julian(),
  268.             DateUtil.CreateFromYMD (2028, 12,  1).julian(),
  269.             DateUtil.CreateFromYMD (2029, 12,  1).julian(),
  270.             DateUtil.CreateFromYMD (2030, 12,  1).julian(),
  271.             DateUtil.CreateFromYMD (2031, 12,  1).julian(),
  272.             DateUtil.CreateFromYMD (2032, 12,  1).julian(),
  273.             DateUtil.CreateFromYMD (2033, 12,  1).julian(),
  274.             DateUtil.CreateFromYMD (2034, 12,  1).julian(),
  275.             DateUtil.CreateFromYMD (2035, 12,  1).julian(),
  276.             DateUtil.CreateFromYMD (2036, 12,  1).julian(),
  277.             DateUtil.CreateFromYMD (2037, 12,  1).julian(),
  278.             DateUtil.CreateFromYMD (2038, 12,  1).julian(),
  279.         };
  280.         double[] adblExercisePrice = new double[] {
  281.             1.,
  282.             1.,
  283.             1.,
  284.             1.,
  285.             1.,
  286.             1.,
  287.             1.,
  288.             1.,
  289.             1.,
  290.             1.,
  291.             1.,
  292.             1.,
  293.             1.,
  294.             1.,
  295.             1.,
  296.             1.,
  297.             1.,
  298.             1.,
  299.             1.,
  300.             1.,
  301.         };

  302.         int iNumVertex = aiExerciseDate.length;
  303.         double[][] aadblForwardPrice = new double[iNumPath][iNumVertex];
  304.         ValuationParams[] aValParamsEvent = new ValuationParams[iNumVertex];

  305.         BondComponent bond = Callable (
  306.             new EmbeddedOptionSchedule (
  307.                 aiExerciseDate,
  308.                 adblExercisePrice,
  309.                 false,
  310.                 30,
  311.                 false,
  312.                 Double.NaN,
  313.                 "",
  314.                 Double.NaN
  315.             )
  316.         );

  317.         PathGovvie pg = PathGovvieCurves (
  318.             dtSpot,
  319.             iNumPath
  320.         );

  321.         GovvieCurve[] aGCPath = pg.curveSequence (iNumPath);

  322.         MergedDiscountForwardCurve mdfc = FundingCurve (
  323.             dtSpot,
  324.             "USD",
  325.             0.
  326.         );

  327.         CurveSurfaceQuoteContainer csqcBase = MarketParamsBuilder.Create (
  328.             mdfc,
  329.             pg.govvieBuilderSettings().groundState(),
  330.             null,
  331.             null,
  332.             null,
  333.             null,
  334.             null
  335.         );

  336.         ValuationParams valParamsSpot = ValuationParams.Spot (dtSpot.julian());

  337.         double dblOASSpot = bond.oasFromPrice (
  338.             valParamsSpot,
  339.             csqcBase,
  340.             null,
  341.             dblCleanPrice
  342.         );

  343.         for (int iVertex = 0; iVertex < iNumVertex; ++iVertex)
  344.             aValParamsEvent[iVertex] = ValuationParams.Spot (aiExerciseDate[iVertex]);

  345.         for (int iPath = 0; iPath < iNumPath; ++iPath) {
  346.             CurveSurfaceQuoteContainer csqcPath = MarketParamsBuilder.Create (
  347.                 mdfc,
  348.                 aGCPath[iPath],
  349.                 null,
  350.                 null,
  351.                 null,
  352.                 null,
  353.                 null
  354.             );

  355.             for (int iVertex = 0; iVertex < iNumVertex; ++iVertex)
  356.                 aadblForwardPrice[iPath][iVertex] = bond.priceFromOAS (
  357.                     aValParamsEvent[iVertex],
  358.                     csqcPath,
  359.                     null,
  360.                     dblOASSpot
  361.                 );
  362.         }

  363.         System.out.println();

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

  365.         System.out.println ("\t||                          FORWARD EXERCISE INDICATOR                           ||");

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

  367.         for (int iPath = 0; iPath < iNumPath; ++iPath) {
  368.             String strDump = "\t||";

  369.             for (int iVertex = 0; iVertex < iNumVertex; ++iVertex)
  370.                 strDump = strDump + (aadblForwardPrice[iPath][iVertex] > adblExercisePrice[iVertex] ? " Y" : " N") + " |";

  371.             System.out.println (strDump + "|");
  372.         }

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

  374.         System.out.println();

  375.         EnvManager.TerminateEnv();
  376.     }
  377. }