MultiCallExerciseMetrics.java

  1. package org.drip.sample.bond;

  2. import org.drip.analytics.date.*;
  3. import org.drip.analytics.output.BondEOSMetrics;
  4. import org.drip.measure.dynamics.DiffusionEvaluatorLogarithmic;
  5. import org.drip.measure.process.DiffusionEvolver;
  6. import org.drip.measure.statistics.UnivariateDiscreteThin;
  7. import org.drip.numerical.common.FormatUtil;
  8. import org.drip.param.creator.MarketParamsBuilder;
  9. import org.drip.param.valuation.ValuationParams;
  10. import org.drip.product.creator.BondBuilder;
  11. import org.drip.product.credit.BondComponent;
  12. import org.drip.product.params.EmbeddedOptionSchedule;
  13. import org.drip.service.env.EnvManager;
  14. import org.drip.service.template.LatentMarketStateBuilder;
  15. import org.drip.state.discount.MergedDiscountForwardCurve;
  16. import org.drip.state.sequence.GovvieBuilderSettings;

  17. /*
  18.  * -*- mode: java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  19.  */

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

  91. /**
  92.  * <i>MultiCallExerciseMetrics</i> demonstrates the Simulations of the Per-Path Callable Bond OAS Based
  93.  * Exercise Metrics.
  94.  *  
  95.  * <br><br>
  96.  *  <ul>
  97.  *      <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/ProductCore.md">Product Core Module</a></li>
  98.  *      <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/FixedIncomeAnalyticsLibrary.md">Fixed Income Analytics</a></li>
  99.  *      <li><b>Project</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/sample/README.md">DROP API Construction and Usage</a></li>
  100.  *      <li><b>Package</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/sample/bond/README.md">Bullet, EOS Bond Metrics + Curve</a></li>
  101.  *  </ul>
  102.  * <br><br>
  103.  *
  104.  * @author Lakshmi Krishnamurthy
  105.  */

  106. public class MultiCallExerciseMetrics {

  107.     private static final MergedDiscountForwardCurve FundingCurve (
  108.         final JulianDate dtSpot,
  109.         final String strCurrency,
  110.         final double dblBump)
  111.         throws Exception
  112.     {
  113.         String[] astrDepositMaturityTenor = new String[] {
  114.             "2D"
  115.         };

  116.         double[] adblDepositQuote = new double[] {
  117.             0.0111956 + dblBump // 2D
  118.         };

  119.         double[] adblFuturesQuote = new double[] {
  120.             0.011375 + dblBump, // 98.8625
  121.             0.013350 + dblBump, // 98.6650
  122.             0.014800 + dblBump, // 98.5200
  123.             0.016450 + dblBump, // 98.3550
  124.             0.017850 + dblBump, // 98.2150
  125.             0.019300 + dblBump  // 98.0700
  126.         };

  127.         String[] astrFixFloatMaturityTenor = new String[] {
  128.             "02Y",
  129.             "03Y",
  130.             "04Y",
  131.             "05Y",
  132.             "06Y",
  133.             "07Y",
  134.             "08Y",
  135.             "09Y",
  136.             "10Y",
  137.             "11Y",
  138.             "12Y",
  139.             "15Y",
  140.             "20Y",
  141.             "25Y",
  142.             "30Y",
  143.             "40Y",
  144.             "50Y"
  145.         };

  146.         double[] adblFixFloatQuote = new double[] {
  147.             0.017029 + dblBump, //  2Y
  148.             0.019354 + dblBump, //  3Y
  149.             0.021044 + dblBump, //  4Y
  150.             0.022291 + dblBump, //  5Y
  151.             0.023240 + dblBump, //  6Y
  152.             0.024025 + dblBump, //  7Y
  153.             0.024683 + dblBump, //  8Y
  154.             0.025243 + dblBump, //  9Y
  155.             0.025720 + dblBump, // 10Y
  156.             0.026130 + dblBump, // 11Y
  157.             0.026495 + dblBump, // 12Y
  158.             0.027230 + dblBump, // 15Y
  159.             0.027855 + dblBump, // 20Y
  160.             0.028025 + dblBump, // 25Y
  161.             0.028028 + dblBump, // 30Y
  162.             0.027902 + dblBump, // 40Y
  163.             0.027655 + dblBump  // 50Y
  164.         };

  165.         return LatentMarketStateBuilder.SmoothFundingCurve (
  166.             dtSpot,
  167.             strCurrency,
  168.             astrDepositMaturityTenor,
  169.             adblDepositQuote,
  170.             "ForwardRate",
  171.             adblFuturesQuote,
  172.             "ForwardRate",
  173.             astrFixFloatMaturityTenor,
  174.             adblFixFloatQuote,
  175.             "SwapRate"
  176.         );
  177.     }

  178.     public static final void main (
  179.         final String[] astrArgs)
  180.         throws Exception
  181.     {
  182.         EnvManager.InitEnv (
  183.             "",
  184.             true
  185.         );

  186.         JulianDate dtSpot = DateUtil.CreateFromYMD (
  187.             2017,
  188.             DateUtil.MARCH,
  189.             24
  190.         );

  191.         int iNumPath = 500;
  192.         double dblCleanPrice = 1.08641;
  193.         int[] aiExerciseDate = new int[] {
  194.             DateUtil.CreateFromYMD (2019, 12,  1).julian(),
  195.             DateUtil.CreateFromYMD (2020, 12,  1).julian(),
  196.             DateUtil.CreateFromYMD (2021, 12,  1).julian(),
  197.             DateUtil.CreateFromYMD (2022, 12,  1).julian(),
  198.             DateUtil.CreateFromYMD (2023, 12,  1).julian(),
  199.             DateUtil.CreateFromYMD (2024, 12,  1).julian(),
  200.             DateUtil.CreateFromYMD (2025, 12,  1).julian(),
  201.             DateUtil.CreateFromYMD (2026, 12,  1).julian(),
  202.             DateUtil.CreateFromYMD (2027, 12,  1).julian(),
  203.             DateUtil.CreateFromYMD (2028, 12,  1).julian(),
  204.             DateUtil.CreateFromYMD (2029, 12,  1).julian(),
  205.             DateUtil.CreateFromYMD (2030, 12,  1).julian(),
  206.             DateUtil.CreateFromYMD (2031, 12,  1).julian(),
  207.             DateUtil.CreateFromYMD (2032, 12,  1).julian(),
  208.             DateUtil.CreateFromYMD (2033, 12,  1).julian(),
  209.             DateUtil.CreateFromYMD (2034, 12,  1).julian(),
  210.             DateUtil.CreateFromYMD (2035, 12,  1).julian(),
  211.             DateUtil.CreateFromYMD (2036, 12,  1).julian(),
  212.             DateUtil.CreateFromYMD (2037, 12,  1).julian(),
  213.             DateUtil.CreateFromYMD (2038, 12,  1).julian(),
  214.         };
  215.         double[] adblExercisePrice = new double[] {
  216.             1.,
  217.             1.,
  218.             1.,
  219.             1.,
  220.             1.,
  221.             1.,
  222.             1.,
  223.             1.,
  224.             1.,
  225.             1.,
  226.             1.,
  227.             1.,
  228.             1.,
  229.             1.,
  230.             1.,
  231.             1.,
  232.             1.,
  233.             1.,
  234.             1.,
  235.             1.,
  236.         };
  237.         JulianDate dtEffective = DateUtil.CreateFromYMD (
  238.             2009,
  239.             12,
  240.             3
  241.         );

  242.         JulianDate dtMaturity  = DateUtil.CreateFromYMD (
  243.             2039,
  244.             12,
  245.             1
  246.         );

  247.         double dblCoupon = 0.06558;
  248.         int iFreq = 2;
  249.         String strCUSIP = "033177XV3";
  250.         String strDayCount = "30/360";
  251.         double dblVolatility = 0.10;
  252.         String strTreasuryCode = "UST";

  253.         String[] astrTenor = new String[] {
  254.             "01Y",
  255.             "02Y",
  256.             "03Y",
  257.             "05Y",
  258.             "07Y",
  259.             "10Y",
  260.             "20Y",
  261.             "30Y"
  262.         };

  263.         double[] adblTreasuryCoupon = new double[] {
  264.             0.0100,
  265.             0.0100,
  266.             0.0125,
  267.             0.0150,
  268.             0.0200,
  269.             0.0225,
  270.             0.0250,
  271.             0.0300
  272.         };

  273.         double[] adblTreasuryYield = new double[] {
  274.             0.0083, //  1Y
  275.             0.0122, //  2Y
  276.             0.0149, //  3Y
  277.             0.0193, //  5Y
  278.             0.0227, //  7Y
  279.             0.0248, // 10Y
  280.             0.0280, // 20Y
  281.             0.0308  // 30Y
  282.         };

  283.         BondComponent bond = BondBuilder.CreateSimpleFixed (
  284.             strCUSIP,
  285.             "USD",
  286.             "",
  287.             dblCoupon,
  288.             iFreq,
  289.             strDayCount,
  290.             dtEffective,
  291.             dtMaturity,
  292.             null,
  293.             null
  294.         );

  295.         bond.setEmbeddedCallSchedule (
  296.             new EmbeddedOptionSchedule (
  297.                 aiExerciseDate,
  298.                 adblExercisePrice,
  299.                 false,
  300.                 30,
  301.                 false,
  302.                 Double.NaN,
  303.                 "",
  304.                 Double.NaN
  305.             )
  306.         );

  307.         GovvieBuilderSettings gbs = new GovvieBuilderSettings (
  308.             dtSpot,
  309.             strTreasuryCode,
  310.             astrTenor,
  311.             adblTreasuryCoupon,
  312.             adblTreasuryYield
  313.         );

  314.         BondEOSMetrics bem = bond.callMetrics (
  315.             ValuationParams.Spot (dtSpot.julian()),
  316.             MarketParamsBuilder.Create (
  317.                 FundingCurve (
  318.                     dtSpot,
  319.                     "USD",
  320.                     0.
  321.                 ),
  322.                 gbs.groundState(),
  323.                 null,
  324.                 null,
  325.                 null,
  326.                 null,
  327.                 null
  328.             ),
  329.             null,
  330.             dblCleanPrice,
  331.             gbs,
  332.             new DiffusionEvolver (
  333.                 DiffusionEvaluatorLogarithmic.Standard (
  334.                     0.,
  335.                     dblVolatility
  336.                 )
  337.             ),
  338.             iNumPath
  339.         );

  340.         UnivariateDiscreteThin udtOptimalExercisePrice = bem.optimalExercisePrice();

  341.         UnivariateDiscreteThin udtOptimalExercisePV = bem.optimalExerciseValue();

  342.         UnivariateDiscreteThin udtOptimalExerciseOAS = bem.optimalExerciseOAS();

  343.         UnivariateDiscreteThin udtOptimalExerciseOASGap = bem.optimalExerciseOASGap();

  344.         UnivariateDiscreteThin udtOptimalExerciseDuration = bem.optimalExerciseDuration();

  345.         UnivariateDiscreteThin udtOptimalExerciseConvexity = bem.optimalExerciseConvexity();

  346.         System.out.println();

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

  348.         System.out.println (
  349.             "\t||  OAS             => " +
  350.                 FormatUtil.FormatDouble (
  351.                     bem.oas(), 3, 1, 10000.
  352.                 )
  353.             + "                                  ||"
  354.         );

  355.         System.out.println (
  356.             "\t||  OAS Duration    =>   " +
  357.                 FormatUtil.FormatDouble (
  358.                     bem.oasDuration(), 1, 1, 10000.
  359.                 )
  360.             + "                                  ||"
  361.         );

  362.         System.out.println (
  363.             "\t||  OAS Convexity   =>   " +
  364.                 FormatUtil.FormatDouble (
  365.                     bem.oasConvexity(), 1, 1, 1000000.
  366.                 )
  367.             + "                                  ||"
  368.         );

  369.         System.out.println (
  370.             "\t||  OAS To Maturity => " +
  371.                 FormatUtil.FormatDouble (
  372.                     bem.oasTM(), 3, 1, 10000.
  373.                 )
  374.             + "                                  ||"
  375.         );

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

  377.         System.out.println();

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

  379.         System.out.println ("\t||        Optimal Exercise Price                               ||");

  380.         System.out.println ("\t||        Optimal Exercise Value                               ||");

  381.         System.out.println ("\t||        Optimal Exercise OAS                                 ||");

  382.         System.out.println ("\t||        Optimal Exercise OAS Gap                             ||");

  383.         System.out.println ("\t||        Optimal Exercise Duration                            ||");

  384.         System.out.println ("\t||        Optimal Exercise Convexity                           ||");

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

  386.         System.out.println ("\t|| AVERAGE => " +
  387.             FormatUtil.FormatDouble (udtOptimalExercisePrice.average(), 3, 2, 100.) + " | " +
  388.             FormatUtil.FormatDouble (udtOptimalExercisePV.average(), 2, 1, 100.) + " | " +
  389.             FormatUtil.FormatDouble (udtOptimalExerciseOAS.average(), 3, 1, 10000.) + " | " +
  390.             FormatUtil.FormatDouble (udtOptimalExerciseOASGap.average(), 3, 0, 10000.) + " | " +
  391.             FormatUtil.FormatDouble (udtOptimalExerciseDuration.average(), 2, 2, 10000.) + " | " +
  392.             FormatUtil.FormatDouble (udtOptimalExerciseConvexity.average(), 1, 2, 1000000.) + " ||"
  393.         );

  394.         System.out.println ("\t||  ERROR  => " +
  395.             FormatUtil.FormatDouble (udtOptimalExercisePrice.error(), 3, 2, 100.) + " | " +
  396.             FormatUtil.FormatDouble (udtOptimalExercisePV.error(), 2, 1, 100.) + " | " +
  397.             FormatUtil.FormatDouble (udtOptimalExerciseOAS.error(), 3, 1, 10000.) + " | " +
  398.             FormatUtil.FormatDouble (udtOptimalExerciseOASGap.error(), 3, 0, 10000.) + " | " +
  399.             FormatUtil.FormatDouble (udtOptimalExerciseDuration.error(), 2, 2, 10000.) + " | " +
  400.             FormatUtil.FormatDouble (udtOptimalExerciseConvexity.error(), 1, 2, 1000000.) + " ||"
  401.         );

  402.         System.out.println ("\t|| MAXIMUM => " +
  403.             FormatUtil.FormatDouble (udtOptimalExercisePrice.maximum(), 3, 2, 100.) + " | " +
  404.             FormatUtil.FormatDouble (udtOptimalExercisePV.maximum(), 2, 1, 100.) + " | " +
  405.             FormatUtil.FormatDouble (udtOptimalExerciseOAS.maximum(), 3, 1, 10000.) + " | " +
  406.             FormatUtil.FormatDouble (udtOptimalExerciseOASGap.maximum(), 3, 0, 10000.) + " | " +
  407.             FormatUtil.FormatDouble (udtOptimalExerciseDuration.maximum(), 2, 2, 10000.) + " | " +
  408.             FormatUtil.FormatDouble (udtOptimalExerciseConvexity.maximum(), 1, 2, 1000000.) + " ||"
  409.         );

  410.         System.out.println ("\t|| MINIMUM => " +
  411.             FormatUtil.FormatDouble (udtOptimalExercisePrice.minimum(), 3, 2, 100.) + " | " +
  412.             FormatUtil.FormatDouble (udtOptimalExercisePV.minimum(), 2, 1, 100.) + " | " +
  413.             FormatUtil.FormatDouble (udtOptimalExerciseOAS.minimum(), 3, 1, 10000.) + " | " +
  414.             FormatUtil.FormatDouble (udtOptimalExerciseOASGap.minimum(), 3, 0, 10000.) + " | " +
  415.             FormatUtil.FormatDouble (udtOptimalExerciseDuration.minimum(), 2, 2, 10000.) + " | " +
  416.             FormatUtil.FormatDouble (udtOptimalExerciseConvexity.minimum(), 1, 2, 1000000.) + " ||"
  417.         );

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

  419.         System.out.println();

  420.         EnvManager.TerminateEnv();
  421.     }
  422. }